diff --git a/ShadowsocksX-NG.xcodeproj/project.pbxproj b/ShadowsocksX-NG.xcodeproj/project.pbxproj index 37c8a71..d160b0b 100644 --- a/ShadowsocksX-NG.xcodeproj/project.pbxproj +++ b/ShadowsocksX-NG.xcodeproj/project.pbxproj @@ -52,6 +52,8 @@ 9BEEF0751D04EF3E00FC52B3 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BEEF0731D04EF3E00FC52B3 /* PreferencesWindowController.swift */; }; 9BEEF0781D04FE8A00FC52B3 /* LaunchAgentUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BEEF0771D04FE8A00FC52B3 /* LaunchAgentUtils.swift */; }; 9BEEF07B1D05631500FC52B3 /* AdvPreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BEEF0791D05631500FC52B3 /* AdvPreferencesWindowController.swift */; }; + C8E42A6C1D4F270A0074C7EA /* UserRulesController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8E42A6A1D4F270A0074C7EA /* UserRulesController.swift */; }; + C8E42A6E1D4F2CAF0074C7EA /* UserRulesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C8E42A701D4F2CAF0074C7EA /* UserRulesController.xib */; }; E0E57CCA7EB34B90F9D340F2 /* Pods_ShadowsocksX_NGTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 388120F062D7EB7DD0D8DDCA /* Pods_ShadowsocksX_NGTests.framework */; }; F0809FF1595BE2966343D3C7 /* libPods-proxy_conf_helper.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E7783AEDB4A3BDDC9FF16AC /* libPods-proxy_conf_helper.a */; }; /* End PBXBuildFile section */ @@ -159,6 +161,9 @@ 9BEEF0771D04FE8A00FC52B3 /* LaunchAgentUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LaunchAgentUtils.swift; sourceTree = ""; }; 9BEEF0791D05631500FC52B3 /* AdvPreferencesWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvPreferencesWindowController.swift; sourceTree = ""; }; B4E6A97CA843F3943524B686 /* Pods-proxy_conf_helper.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-proxy_conf_helper.debug.xcconfig"; path = "Pods/Target Support Files/Pods-proxy_conf_helper/Pods-proxy_conf_helper.debug.xcconfig"; sourceTree = ""; }; + C8E42A6A1D4F270A0074C7EA /* UserRulesController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserRulesController.swift; sourceTree = ""; }; + C8E42A6F1D4F2CAF0074C7EA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/UserRulesController.xib; sourceTree = ""; }; + C8E42A721D4F2CB10074C7EA /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/UserRulesController.strings"; sourceTree = ""; }; E9E9FB3855DA55D0710EE7BD /* Pods-ShadowsocksX-NG.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NG.release.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NG/Pods-ShadowsocksX-NG.release.xcconfig"; sourceTree = ""; }; FE3237E9FB24D9B924A0E630 /* Pods-ShadowsocksX-NG.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NG.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NG/Pods-ShadowsocksX-NG.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -307,6 +312,8 @@ 9B2491B91D0ACC3E003BBECC /* AdvPreferencesWindowController.xib */, 9BA04B241D24044D005AAD7F /* ProxyPreferencesController.swift */, 9B0D55481D2CC85400A4A8E2 /* ProxyPreferencesController.xib */, + C8E42A6A1D4F270A0074C7EA /* UserRulesController.swift */, + C8E42A701D4F2CAF0074C7EA /* UserRulesController.xib */, ); name = UI; sourceTree = ""; @@ -450,6 +457,7 @@ 9B0D55461D2CC85400A4A8E2 /* ProxyPreferencesController.xib in Resources */, 9B2491B41D0ACC3A003BBECC /* PreferencesWindowController.xib in Resources */, 9B3FFF291D08A1DF0019A709 /* user-rule.txt in Resources */, + C8E42A6E1D4F2CAF0074C7EA /* UserRulesController.xib in Resources */, 9BEEF06A1D04D4D500FC52B3 /* start_ss_local.sh in Resources */, 9B3FFF391D08CF110019A709 /* qrcode.min.js in Resources */, 9B3FFF3A1D08CF110019A709 /* qrcode.htm in Resources */, @@ -625,6 +633,7 @@ 9B0BFFE91D0460A70040E62B /* AppDelegate.swift in Sources */, 9BA04B231D23D5A5005AAD7F /* ProxyConfTool.m in Sources */, 9BEEF0781D04FE8A00FC52B3 /* LaunchAgentUtils.swift in Sources */, + C8E42A6C1D4F270A0074C7EA /* UserRulesController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -705,6 +714,15 @@ name = AdvPreferencesWindowController.xib; sourceTree = ""; }; + C8E42A701D4F2CAF0074C7EA /* UserRulesController.xib */ = { + isa = PBXVariantGroup; + children = ( + C8E42A6F1D4F2CAF0074C7EA /* Base */, + C8E42A721D4F2CB10074C7EA /* zh-Hans */, + ); + name = UserRulesController.xib; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index 42f0430..3fc0af2 100644 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -16,7 +16,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele var preferencesWinCtrl: PreferencesWindowController! var advPreferencesWinCtrl: AdvPreferencesWindowController! var proxyPreferencesWinCtrl: ProxyPreferencesController! - + var editUserRulesWinCtrl: UserRulesController! + var launchAtLoginController: LaunchAtLoginController = LaunchAtLoginController() @IBOutlet weak var window: NSWindow! @@ -181,23 +182,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele } @IBAction func editUserRulesForPAC(sender: NSMenuItem) { - let url = NSURL(fileURLWithPath: PACUserRuleFilePath) - NSWorkspace.sharedWorkspace().openURL(url) - } - - @IBAction func applyUserRulesForPAC(sender: NSMenuItem) { - if GeneratePACFile() { - // Popup a user notification - let notification = NSUserNotification() - notification.title = "PAC has been updated by User Rules.".localized - NSUserNotificationCenter.defaultUserNotificationCenter() - .deliverNotification(notification) - } else { - let notification = NSUserNotification() - notification.title = "It's failed to update PAC by User Rules.".localized - NSUserNotificationCenter.defaultUserNotificationCenter() - .deliverNotification(notification) + if editUserRulesWinCtrl != nil { + editUserRulesWinCtrl.close() } + let ctrl = UserRulesController(windowNibName: "UserRulesController") + editUserRulesWinCtrl = ctrl + + ctrl.showWindow(self) + NSApp.activateIgnoringOtherApps(true) + ctrl.window?.makeKeyAndOrderFront(self) } @IBAction func showQRCodeForCurrentServer(sender: NSMenuItem) { diff --git a/ShadowsocksX-NG/Base.lproj/MainMenu.xib b/ShadowsocksX-NG/Base.lproj/MainMenu.xib index 5f50952..603ad84 100644 --- a/ShadowsocksX-NG/Base.lproj/MainMenu.xib +++ b/ShadowsocksX-NG/Base.lproj/MainMenu.xib @@ -1,7 +1,7 @@ - + - + @@ -76,12 +76,6 @@ - - - - - - diff --git a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib index 07f4c19..9a4d115 100644 --- a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib +++ b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib @@ -1,7 +1,7 @@ - + - + @@ -25,7 +25,7 @@ - + diff --git a/ShadowsocksX-NG/Base.lproj/ProxyPreferencesController.xib b/ShadowsocksX-NG/Base.lproj/ProxyPreferencesController.xib index ef62b91..3b3dfcb 100644 --- a/ShadowsocksX-NG/Base.lproj/ProxyPreferencesController.xib +++ b/ShadowsocksX-NG/Base.lproj/ProxyPreferencesController.xib @@ -1,7 +1,7 @@ - + - + @@ -16,7 +16,7 @@ - + diff --git a/ShadowsocksX-NG/Base.lproj/UserRulesController.xib b/ShadowsocksX-NG/Base.lproj/UserRulesController.xib new file mode 100644 index 0000000..2f6c6ef --- /dev/null +++ b/ShadowsocksX-NG/Base.lproj/UserRulesController.xib @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ShadowsocksX-NG/UserRulesController.swift b/ShadowsocksX-NG/UserRulesController.swift new file mode 100644 index 0000000..3e020cc --- /dev/null +++ b/ShadowsocksX-NG/UserRulesController.swift @@ -0,0 +1,53 @@ +// +// UserRulesController.swift +// ShadowsocksX-NG +// +// Created by 周斌佳 on 16/8/1. +// Copyright © 2016年 qiuyuzhou. All rights reserved. +// + +import Cocoa + +class UserRulesController: NSWindowController { + + @IBOutlet var userRulesView: NSTextView! + + override func windowDidLoad() { + super.windowDidLoad() + + let fileMgr = NSFileManager.defaultManager() + if !fileMgr.fileExistsAtPath(PACUserRuleFilePath) { + let src = NSBundle.mainBundle().pathForResource("user-rule", ofType: "txt") + try! fileMgr.copyItemAtPath(src!, toPath: PACUserRuleFilePath) + } + + let str = try? String(contentsOfFile: PACUserRuleFilePath, encoding: NSUTF8StringEncoding) + userRulesView.string = str + } + + @IBAction func didCancel(sender: AnyObject) { + window?.performClose(self) + } + + @IBAction func didOK(sender: AnyObject) { + if let str = userRulesView.string { + do { + try str.dataUsingEncoding(NSUTF8StringEncoding)?.writeToFile(PACUserRuleFilePath, options: .DataWritingAtomic) + + if GeneratePACFile() { + // Popup a user notification + let notification = NSUserNotification() + notification.title = "PAC has been updated by User Rules.".localized + NSUserNotificationCenter.defaultUserNotificationCenter() + .deliverNotification(notification) + } else { + let notification = NSUserNotification() + notification.title = "It's failed to update PAC by User Rules.".localized + NSUserNotificationCenter.defaultUserNotificationCenter() + .deliverNotification(notification) + } + } catch {} + } + window?.performClose(self) + } +} diff --git a/ShadowsocksX-NG/zh-Hans.lproj/UserRulesController.strings b/ShadowsocksX-NG/zh-Hans.lproj/UserRulesController.strings new file mode 100644 index 0000000..c432a05 --- /dev/null +++ b/ShadowsocksX-NG/zh-Hans.lproj/UserRulesController.strings @@ -0,0 +1,9 @@ + +/* Class = "NSButtonCell"; title = "OK"; ObjectID = "0Sc-cm-Vyu"; */ +"0Sc-cm-Vyu.title" = "确定"; + +/* Class = "NSWindow"; title = "User Rules"; ObjectID = "F0z-JX-Cv5"; */ +"F0z-JX-Cv5.title" = "用户规则"; + +/* Class = "NSButtonCell"; title = "Cancel"; ObjectID = "QAR-9i-kmv"; */ +"QAR-9i-kmv.title" = "取消";