diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index e550b1a..2d3015b 100755 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -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() diff --git a/ShadowsocksX-NG/Base.lproj/HTTPPreferencesWindowController.xib b/ShadowsocksX-NG/Base.lproj/HTTPPreferencesWindowController.xib index 6a4f3ba..8845c32 100644 --- a/ShadowsocksX-NG/Base.lproj/HTTPPreferencesWindowController.xib +++ b/ShadowsocksX-NG/Base.lproj/HTTPPreferencesWindowController.xib @@ -1,8 +1,8 @@ - + - + @@ -15,15 +15,15 @@ - - - + + + - + - + @@ -51,7 +51,7 @@ - + @@ -59,7 +59,7 @@ - + @@ -74,7 +74,7 @@ - + @@ -89,56 +89,35 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + - diff --git a/ShadowsocksX-NG/Base.lproj/MainMenu.xib b/ShadowsocksX-NG/Base.lproj/MainMenu.xib index 520d361..0223bdc 100755 --- a/ShadowsocksX-NG/Base.lproj/MainMenu.xib +++ b/ShadowsocksX-NG/Base.lproj/MainMenu.xib @@ -1,5 +1,5 @@ - + @@ -16,6 +16,7 @@ + @@ -103,6 +104,12 @@ + + + + + + @@ -212,7 +219,7 @@ - + diff --git a/ShadowsocksX-NG/HTTPPreferencesWindowController.swift b/ShadowsocksX-NG/HTTPPreferencesWindowController.swift index 29a8a75..6f2c64f 100644 --- a/ShadowsocksX-NG/HTTPPreferencesWindowController.swift +++ b/ShadowsocksX-NG/HTTPPreferencesWindowController.swift @@ -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) - } }