Rewrite menu bar extra with AppKit

This commit is contained in:
世界
2026-01-05 19:19:11 +08:00
parent 91edd77b00
commit ce0d7ead88
17 changed files with 666 additions and 301 deletions
+21 -10
View File
@@ -1,11 +1,14 @@
import ApplicationLibrary
import Libbox
import Library
import NetworkExtension
import SwiftUI
public struct MacApplication: Scene {
@State private var showMenuBarExtra = false
@State private var isMenuPresented = false
@State private var menuBarExtraSpeedMode = MenuBarExtraSpeedMode.enabled.rawValue
@StateObject private var environments = ExtensionEnvironments()
@State private var statusBarController: StatusBarController?
private let profileEditor: (Binding<String>, Bool) -> AnyView = { text, isEditable in
AnyView(ProfileEditorWrapperView(text: text, isEditable: isEditable))
@@ -21,7 +24,20 @@ public struct MacApplication: Scene {
}
}
.environment(\.showMenuBarExtra, $showMenuBarExtra)
.environment(\.menuBarExtraSpeedMode, $menuBarExtraSpeedMode)
.environmentObject(environments)
.onChangeCompat(of: showMenuBarExtra) { newValue in
statusBarController?.updateVisibility(newValue)
Task {
await SharedPreferences.showMenuBarExtra.set(newValue)
}
}
.onChangeCompat(of: menuBarExtraSpeedMode) { newValue in
statusBarController?.updateSpeedMode(newValue)
Task {
await SharedPreferences.menuBarExtraSpeedMode.set(newValue)
}
}
})
.windowResizability(.contentSize)
.commands {
@@ -48,15 +64,6 @@ public struct MacApplication: Scene {
}
}
MenuBarExtra(isInserted: $showMenuBarExtra) {
MenuView(isMenuPresented: $isMenuPresented)
.environmentObject(environments)
} label: {
Image("MenuIcon")
}
.menuBarExtraStyle(.window)
.menuBarExtraAccess(isPresented: $isMenuPresented)
WindowGroup(for: EditProfileContentView.Context.self) { $context in
EditProfileContentWindow(context: context)
.environment(\.profileEditor, profileEditor)
@@ -67,6 +74,10 @@ public struct MacApplication: Scene {
private func initialize() async {
showMenuBarExtra = await SharedPreferences.showMenuBarExtra.get()
menuBarExtraSpeedMode = await SharedPreferences.menuBarExtraSpeedMode.get()
statusBarController = StatusBarController(environments: environments)
statusBarController?.updateVisibility(showMenuBarExtra)
statusBarController?.updateSpeedMode(menuBarExtraSpeedMode)
}
private func hide(closeApp: Bool) {