Move "Copy HTTP Proxy Export" from preference panel to menu.

This commit is contained in:
Charlie Qiu
2017-03-02 14:26:32 +08:00
parent b981b93f5f
commit aabb67f2c5
4 changed files with 68 additions and 61 deletions

View File

@ -44,6 +44,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
@IBOutlet var exportAllServerProfileItem: NSMenuItem!
@IBOutlet var serversPreferencesMenuItem: NSMenuItem!
@IBOutlet weak var copyHttpProxyExportCmdLineMenuItem: NSMenuItem!
@IBOutlet weak var lanchAtLoginMenuItem: NSMenuItem!
@IBOutlet weak var hudWindow: NSPanel!
@ -140,6 +142,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
(note) in
SyncPrivoxy()
self.applyConfig()
self.updateCopyHttpProxyExportMenu()
}
)
notifyCenter.addObserver(forName: NSNotification.Name(rawValue: "NOTIFY_FOUND_SS_URL"), object: nil, queue: nil) {
@ -195,6 +198,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
, forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
updateMainMenu()
updateCopyHttpProxyExportMenu()
updateServersMenu()
updateRunningModeMenu()
updateLaunchAtLoginMenu()
@ -486,6 +490,26 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
updateRunningModeMenu()
}
@IBAction func copyExportCommand(_ sender: NSMenuItem) {
// Get the Http proxy config.
let defaults = UserDefaults.standard
let address = defaults.string(forKey: "LocalHTTP.ListenAddress")
let port = defaults.integer(forKey: "LocalHTTP.ListenPort")
// Format an export string.
let command = "export http_proxy=http://\(address):\(port);export https_proxy=http://\(address):\(port);"
// Copy to paste board.
NSPasteboard.general().clearContents()
NSPasteboard.general().setString(command, forType: NSStringPboardType)
// Give a system notification.
let notification = NSUserNotification()
notification.title = "Export Command Copied.".localized
NSUserNotificationCenter.default
.deliver(notification)
}
@IBAction func showLogs(_ sender: NSMenuItem) {
let ws = NSWorkspace.shared()
if let appUrl = ws.urlForApplication(withBundleIdentifier: "com.apple.Console") {
@ -595,6 +619,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
}
}
func updateCopyHttpProxyExportMenu() {
let defaults = UserDefaults.standard
let isOn = defaults.bool(forKey: "LocalHTTPOn")
copyHttpProxyExportCmdLineMenuItem.isHidden = !isOn
}
func updateServersMenu() {
let mgr = ServerProfileManager.instance
serversMenuItem.submenu?.removeAllItems()

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2657" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11542"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@ -15,15 +15,15 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="HTTP Proxy Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" frameAutosaveName="" animationBehavior="default" id="vS3-DL-Nq3">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<rect key="contentRect" x="109" y="131" width="253" height="219"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<rect key="contentRect" x="109" y="131" width="253" height="190"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<view key="contentView" id="Qef-Mj-9z1">
<rect key="frame" x="0.0" y="0.0" width="253" height="219"/>
<rect key="frame" x="0.0" y="0.0" width="253" height="190"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button translatesAutoresizingMaskIntoConstraints="NO" id="hgn-81-fsH">
<rect key="frame" x="18" y="183" width="138" height="18"/>
<rect key="frame" x="18" y="154" width="138" height="18"/>
<buttonCell key="cell" type="check" title="HTTP Proxy Enable" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="dqU-MG-Sum">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -33,7 +33,7 @@
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="P4f-0N-7JI">
<rect key="frame" x="18" y="133" width="141" height="18"/>
<rect key="frame" x="18" y="126" width="141" height="18"/>
<buttonCell key="cell" type="check" title="Follow Global Mode" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="ofk-Pc-c8f">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -43,7 +43,7 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="CKF-K9-m8X">
<rect key="frame" x="18" y="132" width="217" height="17"/>
<rect key="frame" x="18" y="103" width="217" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="HTTP Proxy Listen Address:" id="qd0-kc-ttB">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -51,7 +51,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ecd-cS-zUI">
<rect key="frame" x="18" y="79" width="217" height="17"/>
<rect key="frame" x="18" y="50" width="217" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="HTTP Proxy Listen Port:" id="2Sd-yn-gdY">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -59,7 +59,7 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vsw-6L-eh3">
<rect key="frame" x="20" y="102" width="213" height="22"/>
<rect key="frame" x="20" y="73" width="213" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="chf-Id-e5F">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
@ -74,7 +74,7 @@
</connections>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="lD1-xm-Qy3">
<rect key="frame" x="20" y="49" width="213" height="22"/>
<rect key="frame" x="20" y="20" width="213" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="KR0-Ey-wq8">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
@ -89,56 +89,35 @@
<outlet property="formatter" destination="ji3-e7-HNW" id="xWV-vJ-7eq"/>
</connections>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="PvN-Sl-Y1x">
<rect key="frame" x="14" y="13" width="225" height="32"/>
<buttonCell key="cell" type="push" title="Copy Shell Export Command" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ySG-BC-5r0">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="copyExportCommand:" target="-2" id="qzS-ny-TI2"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="lD1-xm-Qy3" firstAttribute="leading" secondItem="PvN-Sl-Y1x" secondAttribute="leading" id="0y9-Yy-bwC"/>
<constraint firstItem="hgn-81-fsH" firstAttribute="leading" secondItem="P4f-0N-7JI" secondAttribute="leading" id="1R6-Zi-ctk"/>
<constraint firstItem="lD1-xm-Qy3" firstAttribute="top" secondItem="Ecd-cS-zUI" secondAttribute="bottom" constant="8" id="1nm-UH-kh1"/>
<constraint firstItem="P4f-0N-7JI" firstAttribute="top" secondItem="hgn-81-fsH" secondAttribute="bottom" constant="14" id="45x-uF-HIp"/>
<constraint firstItem="lD1-xm-Qy3" firstAttribute="trailing" secondItem="PvN-Sl-Y1x" secondAttribute="trailing" id="7sa-J6-wkh"/>
<constraint firstItem="CKF-K9-m8X" firstAttribute="leading" secondItem="vsw-6L-eh3" secondAttribute="leading" id="AHk-aI-egi"/>
<constraint firstAttribute="bottom" secondItem="PvN-Sl-Y1x" secondAttribute="bottom" constant="20" id="DbT-3u-ZkF"/>
<constraint firstItem="PvN-Sl-Y1x" firstAttribute="leading" secondItem="Qef-Mj-9z1" secondAttribute="leading" constant="20" id="E9Q-5h-emd"/>
<constraint firstItem="hgn-81-fsH" firstAttribute="top" secondItem="Qef-Mj-9z1" secondAttribute="top" constant="20" symbolic="YES" id="Frc-hf-qrH"/>
<constraint firstItem="vsw-6L-eh3" firstAttribute="leading" secondItem="Ecd-cS-zUI" secondAttribute="leading" id="LrJ-ar-6wM"/>
<constraint firstItem="Ecd-cS-zUI" firstAttribute="leading" secondItem="lD1-xm-Qy3" secondAttribute="leading" id="OKR-LY-EGz"/>
<constraint firstItem="CKF-K9-m8X" firstAttribute="trailing" secondItem="vsw-6L-eh3" secondAttribute="trailing" id="Pd5-7w-ckb"/>
<constraint firstAttribute="trailing" secondItem="PvN-Sl-Y1x" secondAttribute="trailing" constant="20" id="PnS-gu-hdu"/>
<constraint firstItem="hgn-81-fsH" firstAttribute="leading" secondItem="Qef-Mj-9z1" secondAttribute="leading" constant="20" symbolic="YES" id="Ybz-LX-Dja"/>
<constraint firstItem="PvN-Sl-Y1x" firstAttribute="top" secondItem="lD1-xm-Qy3" secondAttribute="bottom" constant="8" id="f3P-0R-9gv"/>
<constraint firstItem="Ecd-cS-zUI" firstAttribute="trailing" secondItem="lD1-xm-Qy3" secondAttribute="trailing" id="fB5-qO-5nl"/>
<constraint firstItem="vsw-6L-eh3" firstAttribute="trailing" secondItem="Ecd-cS-zUI" secondAttribute="trailing" id="gjk-JO-7i3"/>
<constraint firstItem="Ecd-cS-zUI" firstAttribute="top" secondItem="vsw-6L-eh3" secondAttribute="bottom" constant="6" id="pcf-ni-T4y"/>
<constraint firstItem="vsw-6L-eh3" firstAttribute="top" secondItem="CKF-K9-m8X" secondAttribute="bottom" constant="8" id="sXF-aR-Xnj"/>
<constraint firstItem="CKF-K9-m8X" firstAttribute="top" secondItem="P4f-0N-7JI" secondAttribute="bottom" constant="8" symbolic="YES" id="3JQ-SJ-TSN"/>
<constraint firstItem="Ecd-cS-zUI" firstAttribute="trailing" secondItem="lD1-xm-Qy3" secondAttribute="trailing" id="7gU-3r-116"/>
<constraint firstItem="hgn-81-fsH" firstAttribute="leading" secondItem="P4f-0N-7JI" secondAttribute="leading" id="9a5-Oj-c36"/>
<constraint firstItem="P4f-0N-7JI" firstAttribute="leading" secondItem="CKF-K9-m8X" secondAttribute="leading" id="FNT-X2-Wjy"/>
<constraint firstItem="hgn-81-fsH" firstAttribute="top" secondItem="Qef-Mj-9z1" secondAttribute="top" constant="20" symbolic="YES" id="G6a-3j-ZVI"/>
<constraint firstItem="vsw-6L-eh3" firstAttribute="trailing" secondItem="Ecd-cS-zUI" secondAttribute="trailing" id="Imt-lq-XHl"/>
<constraint firstItem="CKF-K9-m8X" firstAttribute="trailing" secondItem="vsw-6L-eh3" secondAttribute="trailing" id="V0q-XV-Mui"/>
<constraint firstAttribute="trailing" secondItem="CKF-K9-m8X" secondAttribute="trailing" constant="20" symbolic="YES" id="WhC-Dm-ETJ"/>
<constraint firstItem="hgn-81-fsH" firstAttribute="leading" secondItem="Qef-Mj-9z1" secondAttribute="leading" constant="20" symbolic="YES" id="XKp-Ug-dvt"/>
<constraint firstItem="vsw-6L-eh3" firstAttribute="leading" secondItem="Ecd-cS-zUI" secondAttribute="leading" id="bep-WS-ThG"/>
<constraint firstItem="lD1-xm-Qy3" firstAttribute="top" secondItem="Ecd-cS-zUI" secondAttribute="bottom" constant="8" symbolic="YES" id="fap-29-XS4"/>
<constraint firstAttribute="bottom" secondItem="lD1-xm-Qy3" secondAttribute="bottom" constant="20" symbolic="YES" id="nDF-aL-c9J"/>
<constraint firstItem="CKF-K9-m8X" firstAttribute="leading" secondItem="vsw-6L-eh3" secondAttribute="leading" id="o6R-dQ-3gq"/>
<constraint firstItem="Ecd-cS-zUI" firstAttribute="leading" secondItem="lD1-xm-Qy3" secondAttribute="leading" id="oWo-gR-cua"/>
<constraint firstItem="vsw-6L-eh3" firstAttribute="top" secondItem="CKF-K9-m8X" secondAttribute="bottom" constant="8" symbolic="YES" id="q8d-OA-Ea2"/>
<constraint firstItem="Ecd-cS-zUI" firstAttribute="top" secondItem="vsw-6L-eh3" secondAttribute="bottom" constant="6" id="zdB-fb-Nth"/>
</constraints>
</view>
<connections>
<outlet property="delegate" destination="-2" id="mD3-X9-VEN"/>
</connections>
<point key="canvasLocation" x="2.5" y="120.5"/>
<point key="canvasLocation" x="2.5" y="106"/>
</window>
<userDefaultsController representsSharedInstance="YES" id="Adn-6l-wm4"/>
<numberFormatter formatterBehavior="default10_4" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="42" id="ji3-e7-HNW" userLabel="Port Number Formatter">
<real key="minimum" value="128"/>
<real key="maximum" value="65535"/>
</numberFormatter>
<button verticalHuggingPriority="750" id="XMF-lp-tgg">
<rect key="frame" x="0.0" y="0.0" width="82" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="iOs-ut-Dj4">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</objects>
</document>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
@ -16,6 +16,7 @@
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="ShadowsocksX_NG" customModuleProvider="target">
<connections>
<outlet property="autoModeMenuItem" destination="r07-Gu-aEz" id="9aH-pQ-Rgi"/>
<outlet property="copyHttpProxyExportCmdLineMenuItem" destination="lg6-To-GZA" id="VTb-he-dg4"/>
<outlet property="exportAllServerProfileItem" destination="6k0-gn-DQv" id="W2x-96-ISj"/>
<outlet property="globalModeMenuItem" destination="Mw3-Jm-eXA" id="ar5-Yx-3ze"/>
<outlet property="hudWindow" destination="QWV-F6-ac1" id="K6D-a4-oqE"/>
@ -103,6 +104,12 @@
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="vwY-hQ-ZIz"/>
<menuItem title="Copy HTTP Proxy Shell Export Line" id="lg6-To-GZA">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="copyExportCommand:" target="Voe-Tx-rLC" id="2U4-3M-sAK"/>
</connections>
</menuItem>
<menuItem title="Scan QR Code From Screen ..." id="Qe6-bF-paT">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
@ -212,7 +219,7 @@
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" oneShot="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="QWV-F6-ac1" customClass="NSPanel">
<windowStyleMask key="styleMask" closable="YES" miniaturizable="YES" resizable="YES" utility="YES"/>
<rect key="contentRect" x="139" y="81" width="200" height="100"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<value key="minSize" type="size" width="200" height="100"/>
<value key="maxSize" type="size" width="200" height="100"/>
<view key="contentView" id="rai-SH-9tZ" userLabel="Panel View">

View File

@ -27,13 +27,4 @@ class HTTPPreferencesWindowController: NSWindowController, NSWindowDelegate {
.post(name: Notification.Name(rawValue: NOTIFY_HTTP_CONF_CHANGED), object: nil)
}
@IBAction func copyExportCommand(_ sender: Any) {
let command = "export http_proxy=http://\(address.stringValue):\(port.stringValue);export https_proxy=http://\(address.stringValue):\(port.stringValue);"
NSPasteboard.general().clearContents()
NSPasteboard.general().setString(command, forType: NSStringPboardType)
let notification = NSUserNotification()
notification.title = "Export Command Copied.".localized
NSUserNotificationCenter.default
.deliver(notification)
}
}