-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor in class AppDelegate.
- Loading branch information
Showing
6 changed files
with
282 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
1C82DBA81FA96C7500B32551 /* obfs-local in Resources */ = {isa = PBXBuildFile; fileRef = 1C82DBA51FA96C7400B32551 /* obfs-local */; }; | ||
1C82DBAA1FA96FB600B32551 /* install_simple_obfs.sh in Resources */ = {isa = PBXBuildFile; fileRef = 1C82DBA91FA96F0300B32551 /* install_simple_obfs.sh */; }; | ||
258E511BA910B0521B24DAB8 /* Pods_ShadowsocksX_NG.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 283ED1A8E9B711AC65670031 /* Pods_ShadowsocksX_NG.framework */; }; | ||
8EE2EDC2214F6D9F00FB4562 /* HTTPUserProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EE2EDBF214F6D9F00FB4562 /* HTTPUserProxy.swift */; }; | ||
8EE2EDC3214F6D9F00FB4562 /* AppleScriptUserProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EE2EDC1214F6D9F00FB4562 /* AppleScriptUserProxy.swift */; }; | ||
8EE2EDC5214F6DA600FB4562 /* AppleScriptDefinition.sdef in Resources */ = {isa = PBXBuildFile; fileRef = 8EE2EDC4214F6DA600FB4562 /* AppleScriptDefinition.sdef */; }; | ||
8EE2EDC7214F6F0C00FB4562 /* ShadowsocksX-NG in Resources */ = {isa = PBXBuildFile; fileRef = 8EE2EDC6214F6F0C00FB4562 /* ShadowsocksX-NG */; }; | ||
9B07EFA71D048BBB0052D9DF /* ss-local in Resources */ = {isa = PBXBuildFile; fileRef = 9B07EFA61D048BBB0052D9DF /* ss-local */; }; | ||
9B07EFAC1D048E880052D9DF /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 9B07EFA81D048E880052D9DF /* [email protected] */; }; | ||
9B07EFAD1D048E880052D9DF /* menu_icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 9B07EFA91D048E880052D9DF /* menu_icon.png */; }; | ||
|
@@ -145,6 +149,10 @@ | |
50D54926AA21B0D4D8DD9C4F /* Pods-ShadowsocksX-NGUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NGUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NGUITests/Pods-ShadowsocksX-NGUITests.release.xcconfig"; sourceTree = "<group>"; }; | ||
58907E7F50405104B42CB189 /* Pods-ShadowsocksX-NGUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NGUITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NGUITests/Pods-ShadowsocksX-NGUITests.debug.xcconfig"; sourceTree = "<group>"; }; | ||
5B6203C1228FCD3D365814AC /* Pods-ShadowsocksX-NGTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NGTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NGTests/Pods-ShadowsocksX-NGTests.debug.xcconfig"; sourceTree = "<group>"; }; | ||
8EE2EDBF214F6D9F00FB4562 /* HTTPUserProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPUserProxy.swift; sourceTree = "<group>"; }; | ||
8EE2EDC1214F6D9F00FB4562 /* AppleScriptUserProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppleScriptUserProxy.swift; sourceTree = "<group>"; }; | ||
8EE2EDC4214F6DA600FB4562 /* AppleScriptDefinition.sdef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = AppleScriptDefinition.sdef; sourceTree = "<group>"; }; | ||
8EE2EDC6214F6F0C00FB4562 /* ShadowsocksX-NG */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "ShadowsocksX-NG"; sourceTree = "<group>"; }; | ||
9B07EFA61D048BBB0052D9DF /* ss-local */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = "ss-local"; sourceTree = "<group>"; }; | ||
9B07EFA81D048E880052D9DF /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; }; | ||
9B07EFA91D048E880052D9DF /* menu_icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu_icon.png; sourceTree = "<group>"; }; | ||
|
@@ -358,10 +366,14 @@ | |
9B0BFFE71D0460A70040E62B /* ShadowsocksX-NG */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
8EE2EDC4214F6DA600FB4562 /* AppleScriptDefinition.sdef */, | ||
8EE2EDC6214F6F0C00FB4562 /* ShadowsocksX-NG */, | ||
9BB706A51D1B982300551F0E /* SWBApplication.m */, | ||
9BB706A61D1B982300551F0E /* SWBApplication.h */, | ||
9B3FFF511D09DBA20019A709 /* ShadowsocksX-NG-Bridging-Header.h */, | ||
9B3FFF151D072FDE0019A709 /* LaunchAtLoginController.h */, | ||
8EE2EDC1214F6D9F00FB4562 /* AppleScriptUserProxy.swift */, | ||
8EE2EDBF214F6D9F00FB4562 /* HTTPUserProxy.swift */, | ||
9B3FFF161D072FDE0019A709 /* LaunchAtLoginController.m */, | ||
9B3FFF0B1D05D8B80019A709 /* UI */, | ||
9B07EFB01D048E900052D9DF /* Support Files */, | ||
|
@@ -626,6 +638,7 @@ | |
C6D429971DA75988002A5711 /* stop_privoxy.sh in Resources */, | ||
C8E42A6E1D4F2CAF0074C7EA /* UserRulesController.xib in Resources */, | ||
9BEEF06A1D04D4D500FC52B3 /* start_ss_local.sh in Resources */, | ||
8EE2EDC7214F6F0C00FB4562 /* ShadowsocksX-NG in Resources */, | ||
9B16E59A1F99FD0700E54DC5 /* icons8-Eye Filled-50.png in Resources */, | ||
9B938D9C1E864B38005F5636 /* [email protected] in Resources */, | ||
9B3546731E802B1200B510B4 /* ToastWindowController.xib in Resources */, | ||
|
@@ -635,6 +648,7 @@ | |
9B3FFF341D08CEF70019A709 /* SWBQRCodeWindowController.xib in Resources */, | ||
9B3FFF231D088E8D0019A709 /* abp.js in Resources */, | ||
9B07EFAD1D048E880052D9DF /* menu_icon.png in Resources */, | ||
8EE2EDC5214F6DA600FB4562 /* AppleScriptDefinition.sdef in Resources */, | ||
9BAFE2E21E83ED7F00F71CCE /* PreferencesWinController.xib in Resources */, | ||
9B0BFFEB1D0460A70040E62B /* Assets.xcassets in Resources */, | ||
08FCA0FF1E24BE1A0070984F /* example-gui-config.json in Resources */, | ||
|
@@ -816,6 +830,7 @@ | |
isa = PBXSourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
8EE2EDC2214F6D9F00FB4562 /* HTTPUserProxy.swift in Sources */, | ||
9B3FFF171D072FDE0019A709 /* LaunchAtLoginController.m in Sources */, | ||
9B86459D1E7C2CAD00A84029 /* ProxyInterfacesViewCtrl.swift in Sources */, | ||
9B3FFF4F1D09D9D50019A709 /* ProxyConfHelper.m in Sources */, | ||
|
@@ -828,6 +843,7 @@ | |
9B3FFF141D0705810019A709 /* Notifications.swift in Sources */, | ||
9BEEF0701D04DDB100FC52B3 /* ServerProfileManager.swift in Sources */, | ||
9BEEF06E1D04DCE400FC52B3 /* ServerProfile.swift in Sources */, | ||
8EE2EDC3214F6D9F00FB4562 /* AppleScriptUserProxy.swift in Sources */, | ||
9B3FFF0D1D05FEB30019A709 /* Utils.swift in Sources */, | ||
9BEEF0751D04EF3E00FC52B3 /* PreferencesWindowController.swift in Sources */, | ||
9B0BFFE91D0460A70040E62B /* AppDelegate.swift in Sources */, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"> | ||
|
||
<dictionary title="ShadowsocksX-NG"> | ||
|
||
<suite name="ShadowsocksX-NG Suite" code="sktc"> | ||
<enumeration name="Mode" code="mode"> | ||
<enumerator name="auto" code="auto"> | ||
<cocoa string-value="auto"/> | ||
</enumerator> | ||
<enumerator name="manual" code="manu"> | ||
<cocoa string-value="manual"/> | ||
</enumerator> | ||
<enumerator name="global" code="glbl"> | ||
<cocoa string-value="global"/> | ||
</enumerator> | ||
</enumeration> | ||
|
||
<command name="isRunning" code="isruning"> | ||
<cocoa class="ShadowsocksX_NG.AppleScriptUserProxy"/> | ||
<result type="boolean"/> | ||
</command> | ||
|
||
<command name="toggle" code="sstoggle" description="Turn on/off the client."> | ||
<cocoa class="ShadowsocksX_NG.AppleScriptUserProxy"/> | ||
</command> | ||
|
||
<command name="mode" code="currmode"> | ||
<cocoa class="ShadowsocksX_NG.AppleScriptUserProxy"/> | ||
<result type="Mode"/> | ||
</command> | ||
|
||
<command name="change mode" code="chagmode"> | ||
<cocoa class="ShadowsocksX_NG.AppleScriptUserProxy"/> | ||
<direct-parameter type="Mode"/> | ||
</command> | ||
|
||
<command name="servers" code="sevrlist"> | ||
<cocoa class="ShadowsocksX_NG.AppleScriptUserProxy"/> | ||
<result> | ||
<type type="text" list="yes"/> | ||
</result> | ||
</command> | ||
|
||
<command name="change server" code="chagServ"> | ||
<cocoa class="ShadowsocksX_NG.AppleScriptUserProxy"/> | ||
<direct-parameter type="text"/> | ||
</command> | ||
</suite> | ||
|
||
</dictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// AppleScriptCommand.swift | ||
// ShadowsocksX-NG | ||
// | ||
// Created by melonEater on 2018/9/6. | ||
// Copyright © 2018 qiuyuzhou. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
|
||
class AppleScriptUserProxy: NSScriptCommand { | ||
let appdeleget = NSApplication.shared.delegate as! AppDelegate | ||
let SerMgr = ServerProfileManager.instance | ||
|
||
override func performDefaultImplementation() -> Any? { | ||
switch(self.commandDescription.commandName) { | ||
case "isRunning": | ||
return isRunning() | ||
case "toggle": | ||
toggle() | ||
case "mode": | ||
return getMode() | ||
case "change mode": | ||
changeMode(mode: self.directParameter as! String) | ||
case "servers": | ||
return getServerList(); | ||
case "change server": | ||
setServer(remark: self.directParameter as! String) | ||
default: | ||
return nil; | ||
} | ||
return nil | ||
} | ||
|
||
func toggle() { | ||
self.appdeleget.doToggleRunning(showToast: false) | ||
} | ||
|
||
func isRunning() -> Bool { | ||
let isOn = UserDefaults.standard.bool(forKey: "ShadowsocksOn") | ||
return isOn | ||
} | ||
|
||
func getMode() -> String { | ||
return UserDefaults.standard.string(forKey: "ShadowsocksRunningMode") as! String | ||
} | ||
|
||
func changeMode(mode:String) { | ||
appdeleget.changeMode(mode: mode) | ||
} | ||
|
||
func getServerList() -> [String] { | ||
var data = [String]() | ||
|
||
for each in self.SerMgr.profiles{ | ||
data.append(each.remark) | ||
} | ||
|
||
return data | ||
} | ||
|
||
func setServer(remark: String) { | ||
for each in self.SerMgr.profiles{ | ||
if (each.remark == remark) { | ||
self.appdeleget.changeServer(uuid: each.uuid) | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.