-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Showing
13 changed files
with
548 additions
and
115 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,66 @@ | ||
import SwiftUI | ||
|
||
enum RunMode: String { | ||
case global | ||
case off | ||
case manual | ||
case tunnel | ||
|
||
var icon: String { | ||
switch self { | ||
case .global: | ||
return "IconG" | ||
case .off: | ||
return "IconOff" | ||
case .manual: | ||
return "IconM" | ||
case .tunnel: | ||
return "IconT" | ||
} | ||
} | ||
} | ||
|
||
class AppState: ObservableObject { | ||
static let shared = AppState() // 单例实例 | ||
|
||
@Published var runMode: RunMode = .off | ||
@Published var windowController: NSWindowController? | ||
@Published var aboutWindowController: NSWindowController? | ||
@Published var languageManager = LanguageManager() | ||
@Published var themeManager = ThemeManager() | ||
|
||
// 使用 Completion Handler 的异步设置 | ||
func setRunMode(mode: RunMode, completion: @escaping () -> Void) { | ||
DispatchQueue.global().async { | ||
DispatchQueue.main.async { | ||
self.runMode = mode | ||
UserDefaults.set(forKey: .runMode, value: mode.rawValue) | ||
completion() | ||
} | ||
} | ||
} | ||
|
||
private var _runningProfile: String = UserDefaults.get(forKey: .runningProfile) ?? "" | ||
var runningProfile: String { | ||
get { | ||
_runningProfile | ||
} | ||
set { | ||
_runningProfile = newValue | ||
UserDefaults.standard.set(newValue, forKey: "runningProfile") | ||
objectWillChange.send() // 通知更新 | ||
} | ||
} | ||
|
||
private var _runningRouting: String = UserDefaults.get(forKey: .runningRouting) ?? "" | ||
var runningRouting: String { | ||
get { | ||
_runningRouting | ||
} | ||
set { | ||
_runningRouting = newValue | ||
UserDefaults.standard.set(newValue, forKey: "runningRouting") | ||
objectWillChange.send() // 通知更新 | ||
} | ||
} | ||
} |
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
Oops, something went wrong.