feat: remember remote controller selection

This commit is contained in:
yicheng 2021-07-04 14:53:13 +08:00
parent a65ce6b172
commit da8528ef8f
No known key found for this signature in database
GPG Key ID: 7CF411A6623B1C0A
4 changed files with 45 additions and 4 deletions

View File

@ -1074,17 +1074,28 @@
</connections>
</buttonCell>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="NYx-qw-0FN">
<rect key="frame" x="18" y="208" width="444" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="This allows you to control the clash core running in the different machine" id="WkL-aX-66E">
<font key="font" metaFont="system"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="qwK-rg-RXo" secondAttribute="bottom" constant="20" id="1Dj-gP-2GM"/>
<constraint firstItem="Fs7-Ym-fVr" firstAttribute="leading" secondItem="qwK-rg-RXo" secondAttribute="trailing" constant="20" id="2VK-Ze-a7K"/>
<constraint firstItem="NYx-qw-0FN" firstAttribute="top" secondItem="Apx-gL-RAm" secondAttribute="bottom" constant="8" symbolic="YES" id="3Jj-6X-1DG"/>
<constraint firstItem="qwK-rg-RXo" firstAttribute="leading" secondItem="hOe-c3-RXT" secondAttribute="leading" id="4Ls-h5-MsD"/>
<constraint firstItem="NYx-qw-0FN" firstAttribute="leading" secondItem="Gao-fa-Dwr" secondAttribute="leading" constant="20" symbolic="YES" id="4QN-kP-92F"/>
<constraint firstItem="h2z-Vu-j5M" firstAttribute="leading" secondItem="Gao-fa-Dwr" secondAttribute="leading" constant="20" id="664-zM-zta"/>
<constraint firstItem="Apx-gL-RAm" firstAttribute="leading" secondItem="Gao-fa-Dwr" secondAttribute="leading" constant="20" id="Bqp-RP-QGF"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="NYx-qw-0FN" secondAttribute="trailing" constant="20" symbolic="YES" id="NDT-P5-GuC"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="Fs7-Ym-fVr" secondAttribute="trailing" constant="100" id="Rnw-mk-spV"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="Apx-gL-RAm" secondAttribute="trailing" constant="20" symbolic="YES" id="T4S-3l-S7C"/>
<constraint firstItem="Fs7-Ym-fVr" firstAttribute="width" secondItem="qwK-rg-RXo" secondAttribute="width" multiplier="0.971429" id="a5a-pA-stH"/>
<constraint firstItem="h2z-Vu-j5M" firstAttribute="top" secondItem="Apx-gL-RAm" secondAttribute="bottom" constant="20" id="icD-eo-Zvk"/>
<constraint firstItem="h2z-Vu-j5M" firstAttribute="top" secondItem="NYx-qw-0FN" secondAttribute="bottom" constant="8" symbolic="YES" id="jG7-GJ-c7d"/>
<constraint firstAttribute="trailing" secondItem="h2z-Vu-j5M" secondAttribute="trailing" constant="20" id="lJG-V8-SxD"/>
<constraint firstItem="Apx-gL-RAm" firstAttribute="top" secondItem="Gao-fa-Dwr" secondAttribute="top" constant="20" id="mWI-7y-euZ"/>
<constraint firstItem="qwK-rg-RXo" firstAttribute="top" secondItem="h2z-Vu-j5M" secondAttribute="bottom" constant="20" id="pZe-fl-hIB"/>

View File

@ -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() {

View File

@ -16,6 +16,7 @@ class ExternalControlViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
updateButtonStatus()
NSApp.activate(ignoringOtherApps: true)
}
func updateButtonStatus() {

View File

@ -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 状态。";