forked from passwa11/ClashX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87041b5
commit 5d3e9c6
Showing
5 changed files
with
99 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// ProxyModeChangeCommand.swift | ||
// ClashX | ||
// | ||
// Created by Vince-hz on 2022/1/25. | ||
// Copyright © 2022 west2online. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
|
||
@objc class ProxyModeChangeCommand: NSScriptCommand { | ||
override func performDefaultImplementation() -> Any? { | ||
guard let directParameter = directParameter as? String, | ||
let mode = ClashProxyMode(rawValue: directParameter) | ||
else { | ||
scriptErrorNumber = -1 | ||
scriptErrorString = "please enter a valid parameter. rule, global or direct" | ||
return nil | ||
} | ||
guard let delegate = NSApplication.shared.delegate as? AppDelegate else { | ||
scriptErrorNumber = -2 | ||
scriptErrorString = "can't get application, try again later" | ||
return nil | ||
} | ||
let menuItem: NSMenuItem | ||
switch mode { | ||
case .rule: | ||
menuItem = delegate.proxyModeRuleMenuItem | ||
case .global: | ||
menuItem = delegate.proxyModeGlobalMenuItem | ||
case .direct: | ||
menuItem = delegate.proxyModeDirectMenuItem | ||
} | ||
delegate.actionSwitchProxyMode(menuItem) | ||
return nil | ||
} | ||
} |
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"> | ||
<dictionary xmlns:xi="http://www.w3.org/2003/XInclude" title="ClashX Terminonoly"> | ||
<suite name="Proxy Suite" code="????" description="Proxy setting for AppleScript."> | ||
<command name="toggleProxy" code="clashtog" description="Toggle the system proxy."> | ||
<cocoa class="ClashX.ProxySettingCommand"/> | ||
</command> | ||
<command name="proxyMode" code="clashmod" description="Update proxy mode."> | ||
<cocoa class="ClashX.ProxyModeChangeCommand"/> | ||
<direct-parameter description="The proxy mode to set. direct, global, or rule"> | ||
<type type="text"/> | ||
</direct-parameter> | ||
</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,22 @@ | ||
// | ||
// ProxySettingCommand.swift | ||
// ClashXX | ||
// | ||
// Created by Vince-hz on 2022/1/25. | ||
// Copyright © 2022 west2online. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
|
||
@objc class ProxySettingCommand: NSScriptCommand { | ||
override func performDefaultImplementation() -> Any? { | ||
guard let delegate = NSApplication.shared.delegate as? AppDelegate else { | ||
scriptErrorNumber = -2 | ||
scriptErrorString = "can't get application, try again later" | ||
return nil | ||
} | ||
delegate.actionSetSystemProxy(self) | ||
return nil | ||
} | ||
} |
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