Refactor task usage and profile auto update

This commit is contained in:
世界
2023-09-22 11:32:51 +08:00
parent 390e063f20
commit 3374f8e727
49 changed files with 823 additions and 636 deletions
+10 -17
View File
@@ -12,7 +12,7 @@ public struct MacApplication: Scene {
Window("sing-box", id: "main", content: {
MainView()
.onAppear {
Task.detached {
Task {
await initialize()
}
}
@@ -61,26 +61,19 @@ public struct MacApplication: Scene {
.menuBarExtraAccess(isPresented: $isMenuPresented)
}
private func initialize() {
let initialShowMenuBarExtra = SharedPreferences.showMenuBarExtra
DispatchQueue.main.async {
showMenuBarExtra = initialShowMenuBarExtra
}
private func initialize() async {
showMenuBarExtra = await SharedPreferences.showMenuBarExtra.get()
}
private func hide(closeApp: Bool) {
Task.detached {
if SharedPreferences.menuBarExtraInBackground {
DispatchQueue.main.async {
hide0(closeApp: closeApp)
}
Task {
if await SharedPreferences.menuBarExtraInBackground.get() {
hide0(closeApp: closeApp)
} else {
DispatchQueue.main.async {
if closeApp {
NSApp.terminate(nil)
} else {
NSApp.keyWindow?.close()
}
if closeApp {
NSApp.terminate(nil)
} else {
NSApp.keyWindow?.close()
}
}
}