fix(macos): sync restored fullscreen chrome

This commit is contained in:
edde746
2026-05-09 11:35:36 +02:00
parent bb66ab6526
commit afda61119e
8 changed files with 112 additions and 36 deletions
+42 -11
View File
@@ -88,12 +88,17 @@ class WindowUtilsPlugin: NSObject, FlutterPlugin {
static func setWindow(_ window: NSWindow) {
instance?.window = window
instance?.windowDelegate?.window = window
}
/// Apply custom traffic light positions. Called by MainFlutterWindow on startup.
static func setInitialTrafficLightPositions() {
static func installWindowDelegate() {
guard let instance = instance, let window = instance.window else { return }
instance.applyTrafficLightPositions(custom: true, window: window)
instance.installWindowDelegate(window: window)
}
static func syncWindowChrome() {
guard let instance = instance else { return }
instance.syncWindowChrome()
}
/// Apply traffic light positions. Called by WindowDelegate during fullscreen transitions.
@@ -102,6 +107,12 @@ class WindowUtilsPlugin: NSObject, FlutterPlugin {
instance.applyTrafficLightPositions(custom: custom, window: window)
}
static func setTrafficLightsVisible(_ visible: Bool, window: NSWindow) {
for buttonType in [NSWindow.ButtonType.closeButton, .miniaturizeButton, .zoomButton] {
window.standardWindowButton(buttonType)?.isHidden = !visible
}
}
private func applyTrafficLightPositions(custom: Bool, window: NSWindow) {
if custom {
for (buttonType, offset) in WindowUtilsPlugin.customButtonPositions {
@@ -130,9 +141,11 @@ class WindowUtilsPlugin: NSObject, FlutterPlugin {
case "setTrafficLightsVisible":
let args = call.arguments as? [String: Any]
let visible = args?["visible"] as? Bool ?? true
for buttonType in [NSWindow.ButtonType.closeButton, .miniaturizeButton, .zoomButton] {
window.standardWindowButton(buttonType)?.isHidden = !visible
}
WindowUtilsPlugin.setTrafficLightsVisible(visible, window: window)
result(nil)
case "syncWindowChrome":
syncWindowChrome()
result(nil)
case "enterFullscreen":
@@ -159,12 +172,30 @@ class WindowUtilsPlugin: NSObject, FlutterPlugin {
self.window = window
if enableWindowDelegate {
let delegate = WindowDelegate()
delegate.channel = channel
delegate.window = window
windowDelegate = delegate
window.delegate = delegate
installWindowDelegate(window: window)
}
windowDelegate?.syncWindowChrome()
}
private func installWindowDelegate(window: NSWindow) {
let delegate = windowDelegate ?? WindowDelegate()
delegate.channel = channel
delegate.window = window
windowDelegate = delegate
window.delegate = delegate
}
private func syncWindowChrome() {
guard let window = window else { return }
if windowDelegate == nil {
installWindowDelegate(window: window)
} else {
windowDelegate?.channel = channel
windowDelegate?.window = window
window.delegate = windowDelegate
}
windowDelegate?.syncWindowChrome()
}
private func withButton(