diff --git a/ClashX/Base.lproj/Main.storyboard b/ClashX/Base.lproj/Main.storyboard index 137faed..8da87e2 100644 --- a/ClashX/Base.lproj/Main.storyboard +++ b/ClashX/Base.lproj/Main.storyboard @@ -1074,17 +1074,28 @@ + + + + + + + + + + + - + diff --git a/ClashX/General/Managers/RemoteControlManager.swift b/ClashX/General/Managers/RemoteControlManager.swift index 5e9eec9..af416fc 100644 --- a/ClashX/General/Managers/RemoteControlManager.swift +++ b/ClashX/General/Managers/RemoteControlManager.swift @@ -23,6 +23,12 @@ class RemoteControl: Codable { } class RemoteControlManager { + enum Recorder { + @UserDefault("selectedRemoteControlConfigID", defaultValue: "") + static var selected: String + } + + static let shared = RemoteControlManager() static var configs: [RemoteControl] = loadConfig() { didSet { @@ -33,7 +39,12 @@ class RemoteControlManager { } } - static var selectConfig: RemoteControl? + static var selectConfig: RemoteControl? { + didSet { + Recorder.selected = selectConfig?.uuid ?? "" + } + } + private static var menuSeparator: NSMenuItem? static func loadConfig() -> [RemoteControl] { @@ -52,6 +63,21 @@ class RemoteControlManager { menuSeparator = separator updateMenuItems() updateDropDownMenuItems() + DispatchQueue.main.asyncAfter(deadline: .now() + 3) { + RemoteControlManager.recoverSelection() + } + } + + static private func recoverSelection() { + if Recorder.selected != "" { + if let config = configs.first(where: { $0.uuid == Recorder.selected }) { + selectConfig = config + updateRemoteControl() + updateMenuItems() + } else { + Recorder.selected = "" + } + } } static func updateMenuItems() { diff --git a/ClashX/ViewControllers/ExternalControlViewController.swift b/ClashX/ViewControllers/ExternalControlViewController.swift index a6bae21..48b1b72 100644 --- a/ClashX/ViewControllers/ExternalControlViewController.swift +++ b/ClashX/ViewControllers/ExternalControlViewController.swift @@ -16,6 +16,7 @@ class ExternalControlViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() updateButtonStatus() + NSApp.activate(ignoringOtherApps: true) } func updateButtonStatus() { diff --git a/ClashX/zh-Hans.lproj/Main.strings b/ClashX/zh-Hans.lproj/Main.strings index 9071f6b..c8aeb21 100644 --- a/ClashX/zh-Hans.lproj/Main.strings +++ b/ClashX/zh-Hans.lproj/Main.strings @@ -180,10 +180,13 @@ "yO6-uZ-IRv.headerCell.title" = "Api Url"; /* Class = "NSMenu"; title = "Remote Controller"; ObjectID = "1He-Eq-fSy"; */ -"1He-Eq-fSy.title" = "远程控制"; +"1He-Eq-fSy.title" = "远程控制器"; /* Class = "NSMenuItem"; title = "Remote Controller"; ObjectID = "BRR-WK-aeP"; */ -"BRR-WK-aeP.title" = "远程控制"; +"BRR-WK-aeP.title" = "远程控制器"; /* Class = "NSMenuItem"; title = " Manage"; ObjectID = "hlb-KQ-Fdr"; */ "hlb-KQ-Fdr.title" = "管理"; + +/* Class = "NSTextFieldCell"; title = "This allows you to control the clash core running in the different machine"; ObjectID = "WkL-aX-66E"; */ +"WkL-aX-66E.title" = "远程控制器允许你控制其他设备上的 Clash 状态。";