Fix "Copy shell command" display issue

This commit is contained in:
yicheng 2019-12-17 21:04:11 +08:00
parent 969124d9e7
commit 0e62dcf0f9
5 changed files with 21 additions and 30 deletions

View File

@ -50,7 +50,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var disposeBag = DisposeBag()
var statusItemView: StatusItemView!
var isSpeedTesting = false
var isMenuOptionEnter = false
func applicationDidFinishLaunching(_ notification: Notification) {
signal(SIGPIPE, SIG_IGN)
@ -418,14 +417,15 @@ extension AppDelegate {
}
}
@IBAction func actionCopyExportCommand(_ sender: Any) {
@IBAction func actionCopyExportCommand(_ sender: NSMenuItem) {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
let port = ConfigManager.shared.currentConfig?.port ?? 0
let socksport = ConfigManager.shared.currentConfig?.socketPort ?? 0
let localhost = "127.0.0.1"
let ip = isMenuOptionEnter ? NetworkChangeNotifier.getPrimaryIPAddress() ?? localhost : localhost
let isLocalhostCopy = sender == copyExportCommandMenuItem
let ip = isLocalhostCopy ? localhost :
NetworkChangeNotifier.getPrimaryIPAddress() ?? localhost
pasteboard.setString("export https_proxy=http://\(ip):\(port) http_proxy=http://\(ip):\(port) all_proxy=socks5://\(ip):\(socksport)", forType: .string)
}
@ -619,11 +619,6 @@ extension AppDelegate {
self?.syncConfig()
}
}
func updateCopyProxyItem() {
isMenuOptionEnter = NSEvent.modifierFlags == [.option]
copyExportCommandMenuItem.title = isMenuOptionEnter ? NSLocalizedString("Copy Shell Export Command with External IP", comment: "") : NSLocalizedString("Copy Shell Export Command", comment: "")
}
}
// MARK: NSMenuDelegate
@ -634,7 +629,6 @@ extension AppDelegate: NSMenuDelegate {
func menuNeedsUpdate(_ menu: NSMenu) {
syncConfig()
updateConfigFiles()
updateCopyProxyItem()
}
}

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15505"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15400"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@ -231,11 +231,17 @@
<action selector="actionSetSystemProxy:" target="Voe-Tx-rLC" id="jrp-iz-ljC"/>
</connections>
</menuItem>
<menuItem title="Copy export command" keyEquivalent="c" id="Jmb-PK-rMW">
<menuItem title="Copy shell command" keyEquivalent="c" id="Jmb-PK-rMW">
<connections>
<action selector="actionCopyExportCommand:" target="Voe-Tx-rLC" id="82r-sY-7xb"/>
</connections>
</menuItem>
<menuItem title="Copy shell command (External IP)" alternate="YES" keyEquivalent="c" id="7wl-vK-5JO">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="actionCopyExportCommand:" target="Voe-Tx-rLC" id="hsS-Db-cmT"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="nXl-3B-Q18"/>
<menuItem title="Start at login" id="B1J-XB-BiZ">
<modifierMask key="keyEquivalentModifierMask"/>
@ -613,7 +619,7 @@
</viewController>
<customObject id="oHh-a0-cAY" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-24.5" y="623"/>
<point key="canvasLocation" x="-32" y="744"/>
</scene>
<!--Remote Configs-->
<scene sceneID="lXv-k7-YEi">
@ -638,7 +644,7 @@
<tableColumns>
<tableColumn identifier="url" editable="NO" width="176" minWidth="40" maxWidth="1000" id="C79-J5-30z">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Url">
<font key="font" metaFont="message" size="11"/>
<font key="font" metaFont="controlContent" size="11"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
@ -678,7 +684,7 @@
</tableColumn>
<tableColumn identifier="configName" width="86" minWidth="40" maxWidth="1000" id="lRE-Xa-euB">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Config Name">
<font key="font" metaFont="message" size="11"/>
<font key="font" metaFont="controlContent" size="11"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
@ -718,7 +724,7 @@
</tableColumn>
<tableColumn identifier="updateTime" width="95" minWidth="40" maxWidth="1000" id="xoc-hs-9qa">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Update Time">
<font key="font" metaFont="message" size="11"/>
<font key="font" metaFont="controlContent" size="11"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>

View File

@ -38,12 +38,6 @@
/* No comment provided by engineer. */
"Config loading Fail!" = "Config loading Fail!";
/* No comment provided by engineer. */
"Copy Shell Export Command" = "Copy Shell Export Command";
/* No comment provided by engineer. */
"Copy Shell Export Command with External IP" = "Copy Shell Export Command with External IP";
/* No comment provided by engineer. */
"Direct" = "Direct";

View File

@ -38,12 +38,6 @@
/* No comment provided by engineer. */
"Config loading Fail!" = "配置文件加载失败";
/* No comment provided by engineer. */
"Copy Shell Export Command" = "复制终端代理命令";
/* No comment provided by engineer. */
"Copy Shell Export Command with External IP" = "复制终端代理命令(外部IP)";
/* No comment provided by engineer. */
"Direct" = "直连";

View File

@ -74,7 +74,7 @@
/* Class = "NSMenuItem"; title = "API Connect Error"; ObjectID = "jGT-1M-xJu"; */
"jGT-1M-xJu.title" = "API Connect Error";
/* Class = "NSMenuItem"; title = "Copy export command"; ObjectID = "Jmb-PK-rMW"; */
/* Class = "NSMenuItem"; title = "Copy shell command"; ObjectID = "Jmb-PK-rMW"; */
"Jmb-PK-rMW.title" = "复制终端代理命令";
/* Class = "NSMenuItem"; title = "Config"; ObjectID = "JMV-Dy-CI0"; */
@ -157,3 +157,6 @@
/* Class = "NSTextFieldCell"; title = "Core Version"; ObjectID = "zwo-q5-k5N"; */
"zwo-q5-k5N.title" = "内核版本";
/* Class = "NSMenuItem"; title = "Copy shell command (External IP)"; ObjectID = "7wl-vK-5JO"; */
"7wl-vK-5JO.title" = "复制终端代理命令(外部IP)";