forked from alvincrisuy/clashX
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from hbsgithub/meta-dev
fix support for shortcuts and add support to toggle tun mode in shortcuts
- Loading branch information
Showing
6 changed files
with
74 additions
and
19 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
01E33AB229B5BF4200FD1006 /* NSColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E33AB129B5BF4200FD1006 /* NSColor+Extension.swift */; }; | ||
01E33AB529B5C5E400FD1006 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 01E33AB429B5C5E300FD1006 /* [email protected] */; }; | ||
185CBAEDFE986E6E1B836359 /* libPods-ClashX Meta.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AA63125BBF03DC1A291D3351 /* libPods-ClashX Meta.a */; }; | ||
275348502A3082FD0077B458 /* TunModeSettingCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2753484F2A3082FD0077B458 /* TunModeSettingCommand.swift */; }; | ||
4905A2C52A2058B000AEDA2E /* GlobalShortCutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4905A2C42A2058B000AEDA2E /* GlobalShortCutViewController.swift */; }; | ||
4905A2C82A2058D400AEDA2E /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = 4905A2C72A2058D400AEDA2E /* KeyboardShortcuts */; }; | ||
4905A2CA2A20841B00AEDA2E /* NSView+Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4905A2C92A20841B00AEDA2E /* NSView+Layout.swift */; }; | ||
|
@@ -163,6 +164,7 @@ | |
01C1462928962E4E00346AF3 /* com.metacubex.ClashX.ProxyConfigHelper.meta.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = com.metacubex.ClashX.ProxyConfigHelper.meta.gz; sourceTree = "<group>"; }; | ||
01E33AB129B5BF4200FD1006 /* NSColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSColor+Extension.swift"; sourceTree = "<group>"; }; | ||
01E33AB429B5C5E300FD1006 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; }; | ||
2753484F2A3082FD0077B458 /* TunModeSettingCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TunModeSettingCommand.swift; sourceTree = "<group>"; }; | ||
3F86DA2DA3CC14731BE1ABF7 /* Pods-ClashX Meta.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ClashX Meta.release.xcconfig"; path = "Pods/Target Support Files/Pods-ClashX Meta/Pods-ClashX Meta.release.xcconfig"; sourceTree = "<group>"; }; | ||
4905A2C42A2058B000AEDA2E /* GlobalShortCutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalShortCutViewController.swift; sourceTree = "<group>"; }; | ||
4905A2C92A20841B00AEDA2E /* NSView+Layout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSView+Layout.swift"; sourceTree = "<group>"; }; | ||
|
@@ -550,8 +552,10 @@ | |
8A2BBEA527A03A920081EBEF /* AppleScript */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
2753484F2A3082FD0077B458 /* TunModeSettingCommand.swift */, | ||
8A2BBEA627A03ACB0081EBEF /* ProxySetting.sdef */, | ||
8ACD21BA27A04C7800BC4632 /* ProxySettingCommand.swift */, | ||
27F9A6272A1FB25500C50C38 /* TunModeSettingCommand.swift */, | ||
8ACD21BC27A04ED500BC4632 /* ProxyModeChangeCommand.swift */, | ||
); | ||
path = AppleScript; | ||
|
@@ -644,8 +648,9 @@ | |
49CF3B1520CD7463001EBF94 /* Project object */ = { | ||
isa = PBXProject; | ||
attributes = { | ||
BuildIndependentTargetsInParallel = YES; | ||
LastSwiftUpdateCheck = 1030; | ||
LastUpgradeCheck = 1020; | ||
LastUpgradeCheck = 1430; | ||
ORGANIZATIONNAME = west2online; | ||
TargetAttributes = { | ||
49CF3B1C20CD7463001EBF94 = { | ||
|
@@ -745,6 +750,7 @@ | |
4952C3D02117027C004A4FA8 /* ConfigFileManager.swift in Sources */, | ||
49BC061C212931F4005A0FE7 /* AboutViewController.swift in Sources */, | ||
4949D154213242F600EF85E6 /* Paths.swift in Sources */, | ||
275348502A3082FD0077B458 /* TunModeSettingCommand.swift in Sources */, | ||
01B1CB0A2A2E20C10073EA34 /* DashboardManager.swift in Sources */, | ||
499ADAFF2498FC6D00C488FE /* ExternalControlViewController.swift in Sources */, | ||
F939724E23A4DB0600FE5A3F /* DateFormatter+.swift in Sources */, | ||
|
@@ -894,6 +900,7 @@ | |
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; | ||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; | ||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | ||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; | ||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; | ||
CLANG_WARN_STRICT_PROTOTYPES = YES; | ||
CLANG_WARN_SUSPICIOUS_MOVE = YES; | ||
|
@@ -902,6 +909,7 @@ | |
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | ||
CODE_SIGN_IDENTITY = "Mac Developer"; | ||
COPY_PHASE_STRIP = NO; | ||
DEAD_CODE_STRIPPING = YES; | ||
DEBUG_INFORMATION_FORMAT = dwarf; | ||
ENABLE_STRICT_OBJC_MSGSEND = YES; | ||
ENABLE_TESTABILITY = YES; | ||
|
@@ -955,6 +963,7 @@ | |
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; | ||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; | ||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | ||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; | ||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; | ||
CLANG_WARN_STRICT_PROTOTYPES = YES; | ||
CLANG_WARN_SUSPICIOUS_MOVE = YES; | ||
|
@@ -963,6 +972,7 @@ | |
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | ||
CODE_SIGN_IDENTITY = "Mac Developer"; | ||
COPY_PHASE_STRIP = NO; | ||
DEAD_CODE_STRIPPING = YES; | ||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; | ||
ENABLE_NS_ASSERTIONS = NO; | ||
ENABLE_STRICT_OBJC_MSGSEND = YES; | ||
|
@@ -992,9 +1002,11 @@ | |
CODE_SIGN_ENTITLEMENTS = ClashX/ClashX.entitlements; | ||
CODE_SIGN_IDENTITY = "-"; | ||
CODE_SIGN_STYLE = Manual; | ||
|
||
COMBINE_HIDPI_IMAGES = YES; | ||
COMPRESS_PNG_FILES = YES; | ||
CURRENT_PROJECT_VERSION = 0; | ||
DEAD_CODE_STRIPPING = YES; | ||
DEVELOPMENT_TEAM = ""; | ||
ENABLE_HARDENED_RUNTIME = YES; | ||
FRAMEWORK_SEARCH_PATHS = ( | ||
|
@@ -1014,12 +1026,11 @@ | |
"$(inherited)", | ||
"$(PROJECT_DIR)/ClashX", | ||
); | ||
MACOSX_DEPLOYMENT_TARGET = 10.13; | ||
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; | ||
MARKETING_VERSION = v1.0; | ||
PRODUCT_BUNDLE_IDENTIFIER = com.metacubex.ClashX.meta; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
PROVISIONING_PROFILE_SPECIFIER = ""; | ||
STRIP_INSTALLED_PRODUCT = NO; | ||
STRIP_PNG_TEXT = YES; | ||
SWIFT_OBJC_BRIDGING_HEADER = "ClashX/ClashX-Bridging-Header.h"; | ||
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; | ||
|
@@ -1037,10 +1048,12 @@ | |
CODE_SIGN_ENTITLEMENTS = ClashX/ClashX.entitlements; | ||
CODE_SIGN_IDENTITY = "-"; | ||
CODE_SIGN_STYLE = Manual; | ||
|
||
COMBINE_HIDPI_IMAGES = YES; | ||
COMPRESS_PNG_FILES = YES; | ||
COPY_PHASE_STRIP = YES; | ||
CURRENT_PROJECT_VERSION = 0; | ||
DEAD_CODE_STRIPPING = YES; | ||
DEPLOYMENT_POSTPROCESSING = YES; | ||
DEVELOPMENT_TEAM = ""; | ||
ENABLE_HARDENED_RUNTIME = YES; | ||
|
@@ -1061,13 +1074,12 @@ | |
"$(inherited)", | ||
"$(PROJECT_DIR)/ClashX", | ||
); | ||
MACOSX_DEPLOYMENT_TARGET = 10.13; | ||
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; | ||
MARKETING_VERSION = v1.0; | ||
OTHER_CODE_SIGN_FLAGS = "--timestamp"; | ||
PRODUCT_BUNDLE_IDENTIFIER = com.metacubex.ClashX.meta; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
PROVISIONING_PROFILE_SPECIFIER = ""; | ||
STRIP_INSTALLED_PRODUCT = YES; | ||
STRIP_PNG_TEXT = YES; | ||
SWIFT_OBJC_BRIDGING_HEADER = "ClashX/ClashX-Bridging-Header.h"; | ||
SWIFT_VERSION = 5.0; | ||
|
@@ -1083,6 +1095,7 @@ | |
CODE_SIGN_IDENTITY = "-"; | ||
CODE_SIGN_STYLE = Manual; | ||
CURRENT_PROJECT_VERSION = 3; | ||
DEAD_CODE_STRIPPING = YES; | ||
DEVELOPMENT_TEAM = ""; | ||
ENABLE_HARDENED_RUNTIME = YES; | ||
INFOPLIST_FILE = "$(SRCROOT)/ProxyConfigHelper/Helper-Info.plist"; | ||
|
@@ -1092,7 +1105,7 @@ | |
"@loader_path/../Frameworks", | ||
); | ||
LIBRARY_SEARCH_PATHS = "$(inherited)"; | ||
MACOSX_DEPLOYMENT_TARGET = 10.13; | ||
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; | ||
MARKETING_VERSION = 1.2; | ||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; | ||
MTL_FAST_MATH = YES; | ||
|
@@ -1125,6 +1138,7 @@ | |
CODE_SIGN_IDENTITY = "-"; | ||
CODE_SIGN_STYLE = Manual; | ||
CURRENT_PROJECT_VERSION = 3; | ||
DEAD_CODE_STRIPPING = YES; | ||
DEPLOYMENT_POSTPROCESSING = YES; | ||
DEVELOPMENT_TEAM = ""; | ||
ENABLE_HARDENED_RUNTIME = YES; | ||
|
@@ -1135,7 +1149,7 @@ | |
"@loader_path/../Frameworks", | ||
); | ||
LIBRARY_SEARCH_PATHS = "$(inherited)"; | ||
MACOSX_DEPLOYMENT_TARGET = 10.13; | ||
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; | ||
MARKETING_VERSION = 1.2; | ||
MTL_FAST_MATH = YES; | ||
OTHER_LDFLAGS = ( | ||
|
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
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,29 @@ | ||
// | ||
// TunModeSettingCommand.swift | ||
// ClashX.Meta | ||
// | ||
// Created by hbsgithub on 2023/5/26. | ||
// Copyright © 2023 west2online. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
|
||
@objc class TunModeSettingCommand: 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 | ||
} | ||
let menuItem: NSMenuItem | ||
menuItem = delegate.tunModeMenuItem | ||
if menuItem.state == .on { | ||
menuItem.state = .on | ||
} else { | ||
menuItem.state = .off | ||
} | ||
delegate.tunMode(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 |
---|---|---|
@@ -1,42 +1,51 @@ | ||
# 全局快捷键 | ||
|
||
ClashX的全局快捷键是通过支持 AppleScript,并以系统的 Automator 程序调用 AppleScript 来完成全局快捷键的实现。 | ||
ClashX Meta的全局快捷键是通过支持 AppleScript,并以系统的 Automator 程序或者Alfred Workflow调用 AppleScript 来完成全局快捷键的实现。 | ||
|
||
ClashX目前仅支持以下功能的AppleScript | ||
ClashX Meta目前仅支持以下功能的AppleScript | ||
|
||
1. 打开(关闭)系统代理 | ||
2. 切换出站模式 | ||
3. 打开(关闭)Tun模式 | ||
|
||
## 通过 Automator 创建全局快捷键 | ||
|
||
[Mac新建全局快捷键](https://www.jianshu.com/p/afee9aeb41a8) | ||
|
||
## 使用Alfred Workflow | ||
|
||
[Alfred-Workflow-for-ClashX-Meta](https://github.com/hbsgithub/Alfred-Workflow-for-ClashX-Meta) | ||
|
||
## 可用的 AppleScript | ||
|
||
你可以在这里选择你需要的 AppleScript 代码,以此创建你需要的快捷键。 | ||
|
||
**以下示例代码为ClashX程序。如果你正在用ClashX Pro,那么请将ClashX替换为 ClashX Pro** | ||
**以下示例代码为ClashX Meta程序。如果你正在用ClashX或ClashX Pro,那么请将ClashX Meta替换为 ClashX或ClashX Pro** | ||
|
||
--- | ||
|
||
打开(关闭)系统代理 | ||
|
||
`tell application "ClashX" to toggleProxy` | ||
`tell application "ClashX Meta" to toggleProxy` | ||
|
||
切换出站模式为全局代理 | ||
|
||
`tell application "ClashX" to proxyMode 'global'` | ||
`tell application "ClashX Meta" to proxyMode 'global'` | ||
|
||
切换出站模式为直连 | ||
|
||
`tell application "ClashX" to proxyMode 'direct'` | ||
`tell application "ClashX Meta" to proxyMode 'direct'` | ||
|
||
切换出站模式为规则代理 | ||
|
||
`tell application "ClashX" to proxyMode 'rule'` | ||
`tell application "ClashX Meta" to proxyMode 'rule'` | ||
|
||
打开(关闭)Tun模式 | ||
|
||
`tell application "ClashX Meta" to TunMode` | ||
|
||
## 已知缺陷 | ||
|
||
1. 无法直接在桌面使用快捷键,你需要进入任意程序中才能启动快捷键 | ||
1. 通过 Automator 创建全局快捷键的方式无法直接在桌面使用快捷键,你需要进入任意程序中才能启动快捷键 | ||
|
||
2. 在任何程序中第一次启用该快捷键都要点击一次确认授权才能启动快捷键 |