-
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
278 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
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.