From dbf5e1ac45b1b9ecee90bde1efdf569553693584 Mon Sep 17 00:00:00 2001 From: Florian BRUNIAUX Date: Thu, 15 Oct 2026 13:49:05 +0200 Subject: [PATCH 1/5] Keep native dashboard visibility in the F menu Let the user hide and show the XENEON window without quitting the helper. Preserve that choice through display rearrangements while touch and server state continue to run. Co-Authored-By: Claude --- CHANGELOG.md | 3 ++ .../FremkitCore/DashboardVisibility.swift | 9 ++++++ native/Sources/FremkitCore/L10n.swift | 6 ++++ .../Sources/FremkitHelper/AppDelegate.swift | 18 +++++++++++ .../Sources/FremkitHelper/KioskWindow.swift | 24 ++++++++++++-- native/Sources/FremkitHelper/StatusMenu.swift | 10 ++++++ .../DashboardVisibilityTests.swift | 31 +++++++++++++++++++ native/Tests/Shim/main.swift | 5 +++ 8 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 native/Sources/FremkitCore/DashboardVisibility.swift create mode 100644 native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d706626..89553517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li ## Unreleased +### Added +- Hide or show the XENEON dashboard from the native F menu without quitting the helper. A hidden dashboard stays hidden through display rearrangements, while touch and data collection continue. + ### Changed - **Clock in the compact bar.** Show an accent-coloured clock icon beside the time, matching the weather icon. - **Homey is a declared connection now.** The Homey connection type built into Fremkit is gone: diff --git a/native/Sources/FremkitCore/DashboardVisibility.swift b/native/Sources/FremkitCore/DashboardVisibility.swift new file mode 100644 index 00000000..2f6922c1 --- /dev/null +++ b/native/Sources/FremkitCore/DashboardVisibility.swift @@ -0,0 +1,9 @@ +/// User visibility survives display loss and geometry changes; data collection is independent. +public struct DashboardVisibility { + public private(set) var hiddenByUser = false + public var displayAvailable = true + public var shouldShow: Bool { displayAvailable && !hiddenByUser } + public init() {} + public mutating func hide() { hiddenByUser = true } + public mutating func show() { hiddenByUser = false } +} diff --git a/native/Sources/FremkitCore/L10n.swift b/native/Sources/FremkitCore/L10n.swift index a0ea86d7..9c28183d 100644 --- a/native/Sources/FremkitCore/L10n.swift +++ b/native/Sources/FremkitCore/L10n.swift @@ -46,6 +46,8 @@ public enum L10nKey: String, CaseIterable { case openAdmin case openAdminInBrowser case reloadDashboard + case hideDashboard + case showDashboard case toggleTouch case toggleFence case toggleDock @@ -100,6 +102,8 @@ public enum L10n { .openAdmin: "Ouvrir l'admin", .openAdminInBrowser: "Admin dans le navigateur", .reloadDashboard: "Recharger le dashboard", + .hideDashboard: "Masquer", + .showDashboard: "Réafficher", .toggleTouch: "Tactile", .toggleFence: "Barrière souris", .toggleDock: "Notifications", @@ -151,6 +155,8 @@ public enum L10n { .openAdmin: "Open the admin", .openAdminInBrowser: "Admin in the browser", .reloadDashboard: "Reload the dashboard", + .hideDashboard: "Hide", + .showDashboard: "Show", .toggleTouch: "Touch", .toggleFence: "Mouse fence", .toggleDock: "Notifications", diff --git a/native/Sources/FremkitHelper/AppDelegate.swift b/native/Sources/FremkitHelper/AppDelegate.swift index b0c8f438..000e63b7 100644 --- a/native/Sources/FremkitHelper/AppDelegate.swift +++ b/native/Sources/FremkitHelper/AppDelegate.swift @@ -182,6 +182,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Display + // Keep the F menu synchronized with the existing dashboard hide/show buttons as well. + func applicationDidHide(_ notification: Notification) { kiosk?.hideDashboard() } + func applicationDidUnhide(_ notification: Notification) { kiosk?.showDashboard() } + + private func refreshDashboardMenu() { + menu?.update { state in + state.dashboardAvailable = edge != nil && kiosk != nil + state.dashboardHidden = kiosk?.isHiddenByUser == true || NSApp.isHidden + } + } + private func edgeDidChange(_ edge: CGRect?) { self.edge = edge driver?.displayBounds = edge @@ -197,11 +208,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate { } else { let url = Self.parseURL(config.url, what: "url") kiosk = KioskWindow(frame: frame, url: url) + kiosk?.onVisibilityChange = { [weak self] in self?.refreshDashboardMenu() } } } else { admin?.kioskFrame = nil kiosk?.setEdgeFrame(nil) } + refreshDashboardMenu() } // MARK: - Server @@ -227,6 +240,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate { } private func wireMenu(_ menu: StatusMenu) { + menu.onToggleDashboard = { [weak self] in + guard let self, self.edge != nil, let kiosk = self.kiosk else { return } + if kiosk.isHiddenByUser || NSApp.isHidden { kiosk.showDashboard() } + else { kiosk.hideDashboard() } + } menu.onOpenAdmin = { [weak self] in self?.admin?.show() } menu.onOpenAdminInBrowser = { [weak self] in diff --git a/native/Sources/FremkitHelper/KioskWindow.swift b/native/Sources/FremkitHelper/KioskWindow.swift index f7fa2450..7e9b4eff 100644 --- a/native/Sources/FremkitHelper/KioskWindow.swift +++ b/native/Sources/FremkitHelper/KioskWindow.swift @@ -74,6 +74,25 @@ final class KioskWindow: NSObject, WKNavigationDelegate { private let window: NSWindow private let webView: WKWebView private let url: URL + private var visibility = DashboardVisibility() + var isHiddenByUser: Bool { visibility.hiddenByUser } + var onVisibilityChange: (() -> Void)? + + func hideDashboard() { + visibility.hide() + window.orderOut(nil) + onVisibilityChange?() + } + + func showDashboard() { + visibility.show() + if visibility.shouldShow { + NSApp.unhide(nil) + NSApp.activate(ignoringOtherApps: true) + window.makeKeyAndOrderFront(nil) + } + onVisibilityChange?() + } /// Pending retry, so a burst of failures queues only one and a manual reload can cancel it. private var retryWork: DispatchWorkItem? @@ -137,13 +156,14 @@ final class KioskWindow: NSObject, WKNavigationDelegate { /// Moves the window onto `rect` (CoreGraphics display bounds), or hides it when the Edge is gone. func setEdgeFrame(_ rect: CGRect?) { + visibility.displayAvailable = rect != nil guard let rect else { window.orderOut(nil) return } let frame = NSRect.fromCGDisplayBounds(rect, primaryHeight: NSRect.primaryScreenHeight) - window.setFrame(frame, display: true) - window.orderFrontRegardless() + window.setFrame(frame, display: visibility.shouldShow) + if visibility.shouldShow { window.orderFrontRegardless() } } func close() { diff --git a/native/Sources/FremkitHelper/StatusMenu.swift b/native/Sources/FremkitHelper/StatusMenu.swift index 7cc94a60..d6248c7c 100644 --- a/native/Sources/FremkitHelper/StatusMenu.swift +++ b/native/Sources/FremkitHelper/StatusMenu.swift @@ -4,6 +4,8 @@ import FremkitCore /// Everything the menu displays, handed over by the delegate on each rebuild. struct MenuState { + var dashboardAvailable = false + var dashboardHidden = false var server: ServerState = .stopped var touch: TouchState = .disabled /// What the fence is really doing, as opposed to what the config asks for. @@ -49,6 +51,7 @@ final class StatusMenu: NSObject { private var state = MenuState() // Status lines, all disabled; the last three are hidden unless they have something to say. + private let dashboardToggle = NSMenuItem() private let serverLine = NSMenuItem() private let touchLine = NSMenuItem() private let fenceLine = NSMenuItem() @@ -66,6 +69,7 @@ final class StatusMenu: NSObject { var onOpenAdmin: (() -> Void)? var onOpenAdminInBrowser: (() -> Void)? var onReload: (() -> Void)? + var onToggleDashboard: (() -> Void)? var onToggleTouch: ((Bool) -> Void)? var onToggleFence: ((Bool) -> Void)? var onToggleDock: ((Bool) -> Void)? @@ -142,6 +146,9 @@ final class StatusMenu: NSObject { menu.addItem(actionItem(L10n.string(.openAdmin), #selector(openAdmin))) menu.addItem(actionItem(L10n.string(.openAdminInBrowser), #selector(openAdminInBrowser))) + dashboardToggle.target = self + dashboardToggle.action = #selector(toggleDashboard) + menu.addItem(dashboardToggle) menu.addItem(actionItem(L10n.string(.reloadDashboard), #selector(reload))) menu.addItem(.separator()) @@ -170,6 +177,8 @@ final class StatusMenu: NSObject { // MARK: - State private func apply() { + dashboardToggle.title = L10n.string(state.dashboardHidden ? .showDashboard : .hideDashboard) + dashboardToggle.isEnabled = state.dashboardAvailable serverLine.title = state.server.label touchLine.title = state.touchLabel fenceLine.isHidden = state.fence != .missingPermission @@ -189,6 +198,7 @@ final class StatusMenu: NSObject { @objc private func openAdmin() { onOpenAdmin?() } @objc private func openAdminInBrowser() { onOpenAdminInBrowser?() } @objc private func reload() { onReload?() } + @objc private func toggleDashboard() { onToggleDashboard?() } @objc private func openLog() { onOpenLog?() } @objc private func quit() { onQuit?() } diff --git a/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift b/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift new file mode 100644 index 00000000..9a712ecc --- /dev/null +++ b/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift @@ -0,0 +1,31 @@ +import XCTest +@testable import FremkitCore + +final class DashboardVisibilityTests: XCTestCase { + func testUserHideSurvivesDisplayReconfiguration() { + var state = DashboardVisibility() + XCTAssertTrue(state.shouldShow) + state.hide() + XCTAssertFalse(state.shouldShow) + state.displayAvailable = false + state.displayAvailable = true + XCTAssertFalse(state.shouldShow) + state.show() + XCTAssertTrue(state.shouldShow) + } + func testShowingWithoutDisplayKeepsWindowAbsent() { + var state = DashboardVisibility() + state.displayAvailable = false + state.hide() + state.show() + XCTAssertFalse(state.shouldShow) + state.displayAvailable = true + XCTAssertTrue(state.shouldShow) + } + func testMenuLabelsAreWrittenInBothLanguages() { + XCTAssertEqual(L10n.string(.hideDashboard, language: .fr), "Masquer") + XCTAssertEqual(L10n.string(.showDashboard, language: .fr), "Réafficher") + XCTAssertEqual(L10n.string(.hideDashboard, language: .en), "Hide") + XCTAssertEqual(L10n.string(.showDashboard, language: .en), "Show") + } +} diff --git a/native/Tests/Shim/main.swift b/native/Tests/Shim/main.swift index de2362d6..15790637 100644 --- a/native/Tests/Shim/main.swift +++ b/native/Tests/Shim/main.swift @@ -105,6 +105,11 @@ let suites: [(String, () -> XCTestCase, [TestMethod])] = [ ("testAnotherSchemeIsIgnored", { ($0 as! HelperURLTests).testAnotherSchemeIsIgnored() }), ("testUnknownTargetIsIgnored", { ($0 as! HelperURLTests).testUnknownTargetIsIgnored() }), ]), + ("DashboardVisibilityTests", { DashboardVisibilityTests() }, [ + ("testUserHideSurvivesDisplayReconfiguration", { ($0 as! DashboardVisibilityTests).testUserHideSurvivesDisplayReconfiguration() }), + ("testShowingWithoutDisplayKeepsWindowAbsent", { ($0 as! DashboardVisibilityTests).testShowingWithoutDisplayKeepsWindowAbsent() }), + ("testMenuLabelsAreWrittenInBothLanguages", { ($0 as! DashboardVisibilityTests).testMenuLabelsAreWrittenInBothLanguages() }), + ]), ("L10nTests", { L10nTests() }, [ ("testPicksFrenchForAFrenchSystem", { ($0 as! L10nTests).testPicksFrenchForAFrenchSystem() }), ("testPicksEnglishForEverythingElse", { ($0 as! L10nTests).testPicksEnglishForEverythingElse() }), From cebab450a47c66ead9d7c5ac35c66eb22124b158 Mon Sep 17 00:00:00 2001 From: Florian BRUNIAUX Date: Thu, 15 Oct 2026 15:43:41 +0200 Subject: [PATCH 2/5] helper: show dashboard without stealing focus Co-Authored-By: Claude --- CHANGELOG.md | 4 +- README.md | 5 ++- native/Sources/FremkitCore/L10n.swift | 8 ++-- .../Sources/FremkitHelper/AppDelegate.swift | 18 +++++--- .../Sources/FremkitHelper/KioskWindow.swift | 42 ++++++++++--------- .../DashboardVisibilityTests.swift | 6 --- native/Tests/Shim/main.swift | 1 - 7 files changed, 44 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89553517..4d524976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,6 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li ## Unreleased -### Added -- Hide or show the XENEON dashboard from the native F menu without quitting the helper. A hidden dashboard stays hidden through display rearrangements, while touch and data collection continue. - ### Changed - **Clock in the compact bar.** Show an accent-coloured clock icon beside the time, matching the weather icon. - **Homey is a declared connection now.** The Homey connection type built into Fremkit is gone: @@ -28,6 +25,7 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li ### Added - **Local Docker and AI models.** Registry widgets can show up to 200 local containers and observed Ollama or MLX models. Fremkit refuses remote Docker contexts, distinguishes a missing CLI from a stopped daemon, and keeps the container list when stats fail. +- **Borrow the Edge display.** Hide or show the dashboard from the helper menu without quitting it. Hidden state survives display rearrangements, and the mouse fence pauses while the Edge is borrowed. Touch and data collection continue; the dashboard reappears after a helper restart. - **Claude sessions: go to the session.** Touch a card and its window comes forward — the exact Orca pane, the Terminal.app or iTerm2 tab, the VS Code window on that folder, or at least the application — for every session, hooked or merely found running. The card also says which application the session lives in, which is what tells two panes of the diff --git a/README.md b/README.md index 6e7b3d6d..6cc37933 100644 --- a/README.md +++ b/README.md @@ -216,8 +216,9 @@ the widget library and the widgets themselves, live, without a reload. helper adds what a browser cannot — its own HID driver for the Edge's touch panel, a fence that keeps the mouse cursor on your other displays, a kiosk window with no chrome and no cursor, the Dock's notification badges, and supervision of the server. Its menu bar **F** shows what is -running: *Open the admin*, *Admin in the browser*, *Reload the dashboard*, the *Touch* / *Mouse -fence* / *Notifications* / *Manage the server* / *Launch at login* toggles, *Log…* and *Quit*, +running: *Open the admin*, *Admin in the browser*, *Hide the dashboard* / *Show the dashboard*, +*Reload the dashboard*, the *Touch* / *Mouse fence* / *Notifications* / *Manage the server* / +*Launch at login* toggles, *Log…* and *Quit*, above state lines such as "Server: running" and "Touch: active". ## Widgets diff --git a/native/Sources/FremkitCore/L10n.swift b/native/Sources/FremkitCore/L10n.swift index 9c28183d..ba1ae465 100644 --- a/native/Sources/FremkitCore/L10n.swift +++ b/native/Sources/FremkitCore/L10n.swift @@ -102,8 +102,8 @@ public enum L10n { .openAdmin: "Ouvrir l'admin", .openAdminInBrowser: "Admin dans le navigateur", .reloadDashboard: "Recharger le dashboard", - .hideDashboard: "Masquer", - .showDashboard: "Réafficher", + .hideDashboard: "Masquer le dashboard", + .showDashboard: "Afficher le dashboard", .toggleTouch: "Tactile", .toggleFence: "Barrière souris", .toggleDock: "Notifications", @@ -155,8 +155,8 @@ public enum L10n { .openAdmin: "Open the admin", .openAdminInBrowser: "Admin in the browser", .reloadDashboard: "Reload the dashboard", - .hideDashboard: "Hide", - .showDashboard: "Show", + .hideDashboard: "Hide the dashboard", + .showDashboard: "Show the dashboard", .toggleTouch: "Touch", .toggleFence: "Mouse fence", .toggleDock: "Notifications", diff --git a/native/Sources/FremkitHelper/AppDelegate.swift b/native/Sources/FremkitHelper/AppDelegate.swift index 000e63b7..357a0960 100644 --- a/native/Sources/FremkitHelper/AppDelegate.swift +++ b/native/Sources/FremkitHelper/AppDelegate.swift @@ -182,14 +182,19 @@ final class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Display - // Keep the F menu synchronized with the existing dashboard hide/show buttons as well. + // Cmd-H in the admin also hides the accessory app; keep the dashboard and menu in sync. func applicationDidHide(_ notification: Notification) { kiosk?.hideDashboard() } func applicationDidUnhide(_ notification: Notification) { kiosk?.showDashboard() } + private func syncMouseFence() { + if config.fence && kiosk?.isHiddenByUser != true { fence?.start() } + else { fence?.stop() } + } + private func refreshDashboardMenu() { menu?.update { state in state.dashboardAvailable = edge != nil && kiosk != nil - state.dashboardHidden = kiosk?.isHiddenByUser == true || NSApp.isHidden + state.dashboardHidden = kiosk?.isHiddenByUser == true } } @@ -208,7 +213,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate { } else { let url = Self.parseURL(config.url, what: "url") kiosk = KioskWindow(frame: frame, url: url) - kiosk?.onVisibilityChange = { [weak self] in self?.refreshDashboardMenu() } + kiosk?.onVisibilityChange = { [weak self] in + self?.syncMouseFence() + self?.refreshDashboardMenu() + } } } else { admin?.kioskFrame = nil @@ -242,7 +250,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { private func wireMenu(_ menu: StatusMenu) { menu.onToggleDashboard = { [weak self] in guard let self, self.edge != nil, let kiosk = self.kiosk else { return } - if kiosk.isHiddenByUser || NSApp.isHidden { kiosk.showDashboard() } + if kiosk.isHiddenByUser { kiosk.showDashboard() } else { kiosk.hideDashboard() } } menu.onOpenAdmin = { [weak self] in self?.admin?.show() } @@ -266,7 +274,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { guard let self else { return } self.config.fence = on self.saveConfig() - if on { self.fence?.start() } else { self.fence?.stop() } + self.syncMouseFence() self.refreshMenu() } diff --git a/native/Sources/FremkitHelper/KioskWindow.swift b/native/Sources/FremkitHelper/KioskWindow.swift index 7e9b4eff..6ef824e5 100644 --- a/native/Sources/FremkitHelper/KioskWindow.swift +++ b/native/Sources/FremkitHelper/KioskWindow.swift @@ -74,25 +74,6 @@ final class KioskWindow: NSObject, WKNavigationDelegate { private let window: NSWindow private let webView: WKWebView private let url: URL - private var visibility = DashboardVisibility() - var isHiddenByUser: Bool { visibility.hiddenByUser } - var onVisibilityChange: (() -> Void)? - - func hideDashboard() { - visibility.hide() - window.orderOut(nil) - onVisibilityChange?() - } - - func showDashboard() { - visibility.show() - if visibility.shouldShow { - NSApp.unhide(nil) - NSApp.activate(ignoringOtherApps: true) - window.makeKeyAndOrderFront(nil) - } - onVisibilityChange?() - } /// Pending retry, so a burst of failures queues only one and a manual reload can cancel it. private var retryWork: DispatchWorkItem? @@ -166,6 +147,29 @@ final class KioskWindow: NSObject, WKNavigationDelegate { if visibility.shouldShow { window.orderFrontRegardless() } } + // MARK: - Visibility + + private var visibility = DashboardVisibility() + var isHiddenByUser: Bool { visibility.hiddenByUser } + var onVisibilityChange: (() -> Void)? + + /// Lends the Edge to the windows behind the dashboard until the user shows it again. + func hideDashboard() { + visibility.hide() + window.orderOut(nil) + onVisibilityChange?() + } + + /// Returns the dashboard without taking keyboard focus from the current application. + func showDashboard() { + visibility.show() + if visibility.shouldShow { + if NSApp.isHidden { NSApp.unhide(nil) } + window.orderFrontRegardless() + } + onVisibilityChange?() + } + func close() { window.orderOut(nil) } diff --git a/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift b/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift index 9a712ecc..99b3fe03 100644 --- a/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift +++ b/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift @@ -22,10 +22,4 @@ final class DashboardVisibilityTests: XCTestCase { state.displayAvailable = true XCTAssertTrue(state.shouldShow) } - func testMenuLabelsAreWrittenInBothLanguages() { - XCTAssertEqual(L10n.string(.hideDashboard, language: .fr), "Masquer") - XCTAssertEqual(L10n.string(.showDashboard, language: .fr), "Réafficher") - XCTAssertEqual(L10n.string(.hideDashboard, language: .en), "Hide") - XCTAssertEqual(L10n.string(.showDashboard, language: .en), "Show") - } } diff --git a/native/Tests/Shim/main.swift b/native/Tests/Shim/main.swift index 15790637..3870e712 100644 --- a/native/Tests/Shim/main.swift +++ b/native/Tests/Shim/main.swift @@ -108,7 +108,6 @@ let suites: [(String, () -> XCTestCase, [TestMethod])] = [ ("DashboardVisibilityTests", { DashboardVisibilityTests() }, [ ("testUserHideSurvivesDisplayReconfiguration", { ($0 as! DashboardVisibilityTests).testUserHideSurvivesDisplayReconfiguration() }), ("testShowingWithoutDisplayKeepsWindowAbsent", { ($0 as! DashboardVisibilityTests).testShowingWithoutDisplayKeepsWindowAbsent() }), - ("testMenuLabelsAreWrittenInBothLanguages", { ($0 as! DashboardVisibilityTests).testMenuLabelsAreWrittenInBothLanguages() }), ]), ("L10nTests", { L10nTests() }, [ ("testPicksFrenchForAFrenchSystem", { ($0 as! L10nTests).testPicksFrenchForAFrenchSystem() }), From f7ca123c18a56f25814583dc18a2a81511873b58 Mon Sep 17 00:00:00 2001 From: Florian BRUNIAUX Date: Thu, 15 Oct 2026 15:49:05 +0200 Subject: [PATCH 3/5] fix: preserve dashboard preference across app hiding Co-Authored-By: Claude --- .../Sources/FremkitCore/DashboardVisibility.swift | 5 ++++- native/Sources/FremkitHelper/AppDelegate.swift | 8 ++++---- native/Sources/FremkitHelper/KioskWindow.swift | 15 ++++++++++++++- .../DashboardVisibilityTests.swift | 14 ++++++++++++++ native/Tests/Shim/main.swift | 1 + 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/native/Sources/FremkitCore/DashboardVisibility.swift b/native/Sources/FremkitCore/DashboardVisibility.swift index 2f6922c1..78ee924c 100644 --- a/native/Sources/FremkitCore/DashboardVisibility.swift +++ b/native/Sources/FremkitCore/DashboardVisibility.swift @@ -1,9 +1,12 @@ /// User visibility survives display loss and geometry changes; data collection is independent. public struct DashboardVisibility { public private(set) var hiddenByUser = false + public private(set) var applicationHidden = false public var displayAvailable = true - public var shouldShow: Bool { displayAvailable && !hiddenByUser } + public var shouldShow: Bool { displayAvailable && !hiddenByUser && !applicationHidden } public init() {} public mutating func hide() { hiddenByUser = true } public mutating func show() { hiddenByUser = false } + public mutating func applicationDidHide() { applicationHidden = true } + public mutating func applicationDidUnhide() { applicationHidden = false } } diff --git a/native/Sources/FremkitHelper/AppDelegate.swift b/native/Sources/FremkitHelper/AppDelegate.swift index 357a0960..f52ed446 100644 --- a/native/Sources/FremkitHelper/AppDelegate.swift +++ b/native/Sources/FremkitHelper/AppDelegate.swift @@ -182,12 +182,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Display - // Cmd-H in the admin also hides the accessory app; keep the dashboard and menu in sync. - func applicationDidHide(_ notification: Notification) { kiosk?.hideDashboard() } - func applicationDidUnhide(_ notification: Notification) { kiosk?.showDashboard() } + // Cmd-H temporarily hides the app without changing the user's dashboard preference. + func applicationDidHide(_ notification: Notification) { kiosk?.applicationDidHide() } + func applicationDidUnhide(_ notification: Notification) { kiosk?.applicationDidUnhide() } private func syncMouseFence() { - if config.fence && kiosk?.isHiddenByUser != true { fence?.start() } + if config.fence && kiosk?.isShowingDashboard == true { fence?.start() } else { fence?.stop() } } diff --git a/native/Sources/FremkitHelper/KioskWindow.swift b/native/Sources/FremkitHelper/KioskWindow.swift index 6ef824e5..dc255141 100644 --- a/native/Sources/FremkitHelper/KioskWindow.swift +++ b/native/Sources/FremkitHelper/KioskWindow.swift @@ -151,6 +151,7 @@ final class KioskWindow: NSObject, WKNavigationDelegate { private var visibility = DashboardVisibility() var isHiddenByUser: Bool { visibility.hiddenByUser } + var isShowingDashboard: Bool { visibility.shouldShow } var onVisibilityChange: (() -> Void)? /// Lends the Edge to the windows behind the dashboard until the user shows it again. @@ -163,13 +164,25 @@ final class KioskWindow: NSObject, WKNavigationDelegate { /// Returns the dashboard without taking keyboard focus from the current application. func showDashboard() { visibility.show() + if NSApp.isHidden { NSApp.unhideWithoutActivation() } if visibility.shouldShow { - if NSApp.isHidden { NSApp.unhide(nil) } window.orderFrontRegardless() } onVisibilityChange?() } + func applicationDidHide() { + visibility.applicationDidHide() + window.orderOut(nil) + onVisibilityChange?() + } + + func applicationDidUnhide() { + visibility.applicationDidUnhide() + if visibility.shouldShow { window.orderFrontRegardless() } + onVisibilityChange?() + } + func close() { window.orderOut(nil) } diff --git a/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift b/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift index 99b3fe03..505eca04 100644 --- a/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift +++ b/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift @@ -22,4 +22,18 @@ final class DashboardVisibilityTests: XCTestCase { state.displayAvailable = true XCTAssertTrue(state.shouldShow) } + func testApplicationHideDoesNotClearUserPreference() { + var state = DashboardVisibility() + state.hide() + state.applicationDidHide() + state.applicationDidUnhide() + XCTAssertTrue(state.hiddenByUser) + XCTAssertFalse(state.shouldShow) + state.show() + XCTAssertTrue(state.shouldShow) + state.applicationDidHide() + XCTAssertFalse(state.shouldShow) + state.applicationDidUnhide() + XCTAssertTrue(state.shouldShow) + } } diff --git a/native/Tests/Shim/main.swift b/native/Tests/Shim/main.swift index 3870e712..26912a36 100644 --- a/native/Tests/Shim/main.swift +++ b/native/Tests/Shim/main.swift @@ -108,6 +108,7 @@ let suites: [(String, () -> XCTestCase, [TestMethod])] = [ ("DashboardVisibilityTests", { DashboardVisibilityTests() }, [ ("testUserHideSurvivesDisplayReconfiguration", { ($0 as! DashboardVisibilityTests).testUserHideSurvivesDisplayReconfiguration() }), ("testShowingWithoutDisplayKeepsWindowAbsent", { ($0 as! DashboardVisibilityTests).testShowingWithoutDisplayKeepsWindowAbsent() }), + ("testApplicationHideDoesNotClearUserPreference", { ($0 as! DashboardVisibilityTests).testApplicationHideDoesNotClearUserPreference() }), ]), ("L10nTests", { L10nTests() }, [ ("testPicksFrenchForAFrenchSystem", { ($0 as! L10nTests).testPicksFrenchForAFrenchSystem() }), From e452cd9db2c052dc4d372fda8511b06c7c25c4fa Mon Sep 17 00:00:00 2001 From: Florian BRUNIAUX Date: Thu, 15 Oct 2026 15:54:08 +0200 Subject: [PATCH 4/5] fix: restore mouse fence after display reconnect Co-Authored-By: Claude --- native/Sources/FremkitHelper/AppDelegate.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/native/Sources/FremkitHelper/AppDelegate.swift b/native/Sources/FremkitHelper/AppDelegate.swift index f52ed446..7b010126 100644 --- a/native/Sources/FremkitHelper/AppDelegate.swift +++ b/native/Sources/FremkitHelper/AppDelegate.swift @@ -222,6 +222,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { admin?.kioskFrame = nil kiosk?.setEdgeFrame(nil) } + syncMouseFence() refreshDashboardMenu() } From 965175a1d89806ff7cf363ab5d2b740746bb972a Mon Sep 17 00:00:00 2001 From: Florian BRUNIAUX Date: Thu, 15 Oct 2026 17:43:48 +0200 Subject: [PATCH 5/5] Share dashboard visibility state with future fences Keep one activation rule for the mouse fence and any additional fence registered by the helper. WindowFence can register its start/stop callback without duplicating hide and reconnect handling. Co-Authored-By: Claude --- .../Sources/FremkitHelper/AppDelegate.swift | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/native/Sources/FremkitHelper/AppDelegate.swift b/native/Sources/FremkitHelper/AppDelegate.swift index 7b010126..4a86edf7 100644 --- a/native/Sources/FremkitHelper/AppDelegate.swift +++ b/native/Sources/FremkitHelper/AppDelegate.swift @@ -11,6 +11,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate { private let poster = EventPoster() private var driver: TouchDriver? private var fence: MouseFence? + /// A future window fence can register here and share the dashboard visibility rule. + private var fenceUpdates: [(Bool) -> Void] = [] private var dockBadges: DockBadges? private var watcher: EdgeDisplay.Watcher? private var kiosk: KioskWindow? @@ -55,6 +57,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate { self?.menu?.update { $0.fence = state } } self.fence = fence + fenceUpdates.append { [weak fence] active in + if active { _ = fence?.start() } + else { fence?.stop() } + } let dockBadges = DockBadges(port: config.port) dockBadges.onState = { [weak self] state in @@ -80,7 +86,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { } if config.touch { driver.start() } - if config.fence { fence.start() } + syncFences() if config.dock { dockBadges.start() } // An orphan from a crashed helper still holds the port and would be mistaken for an @@ -186,9 +192,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidHide(_ notification: Notification) { kiosk?.applicationDidHide() } func applicationDidUnhide(_ notification: Notification) { kiosk?.applicationDidUnhide() } - private func syncMouseFence() { - if config.fence && kiosk?.isShowingDashboard == true { fence?.start() } - else { fence?.stop() } + private func syncFences() { + let active = config.fence && kiosk?.isShowingDashboard == true + for update in fenceUpdates { update(active) } } private func refreshDashboardMenu() { @@ -214,7 +220,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { let url = Self.parseURL(config.url, what: "url") kiosk = KioskWindow(frame: frame, url: url) kiosk?.onVisibilityChange = { [weak self] in - self?.syncMouseFence() + self?.syncFences() self?.refreshDashboardMenu() } } @@ -222,7 +228,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { admin?.kioskFrame = nil kiosk?.setEdgeFrame(nil) } - syncMouseFence() + syncFences() refreshDashboardMenu() } @@ -275,7 +281,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { guard let self else { return } self.config.fence = on self.saveConfig() - self.syncMouseFence() + self.syncFences() self.refreshMenu() }