diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d706626..4d524976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,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/DashboardVisibility.swift b/native/Sources/FremkitCore/DashboardVisibility.swift new file mode 100644 index 00000000..78ee924c --- /dev/null +++ b/native/Sources/FremkitCore/DashboardVisibility.swift @@ -0,0 +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 && !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/FremkitCore/L10n.swift b/native/Sources/FremkitCore/L10n.swift index a0ea86d7..ba1ae465 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 le dashboard", + .showDashboard: "Afficher le dashboard", .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 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 b0c8f438..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 @@ -182,6 +188,22 @@ final class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Display + // 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 syncFences() { + let active = config.fence && kiosk?.isShowingDashboard == true + for update in fenceUpdates { update(active) } + } + + private func refreshDashboardMenu() { + menu?.update { state in + state.dashboardAvailable = edge != nil && kiosk != nil + state.dashboardHidden = kiosk?.isHiddenByUser == true + } + } + private func edgeDidChange(_ edge: CGRect?) { self.edge = edge driver?.displayBounds = edge @@ -197,11 +219,17 @@ 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?.syncFences() + self?.refreshDashboardMenu() + } } } else { admin?.kioskFrame = nil kiosk?.setEdgeFrame(nil) } + syncFences() + refreshDashboardMenu() } // MARK: - Server @@ -227,6 +255,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 { kiosk.showDashboard() } + else { kiosk.hideDashboard() } + } menu.onOpenAdmin = { [weak self] in self?.admin?.show() } menu.onOpenAdminInBrowser = { [weak self] in @@ -248,7 +281,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.syncFences() self.refreshMenu() } diff --git a/native/Sources/FremkitHelper/KioskWindow.swift b/native/Sources/FremkitHelper/KioskWindow.swift index f7fa2450..dc255141 100644 --- a/native/Sources/FremkitHelper/KioskWindow.swift +++ b/native/Sources/FremkitHelper/KioskWindow.swift @@ -137,13 +137,50 @@ 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() } + } + + // MARK: - Visibility + + 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. + func hideDashboard() { + visibility.hide() + window.orderOut(nil) + onVisibilityChange?() + } + + /// Returns the dashboard without taking keyboard focus from the current application. + func showDashboard() { + visibility.show() + if NSApp.isHidden { NSApp.unhideWithoutActivation() } + if visibility.shouldShow { + window.orderFrontRegardless() + } + onVisibilityChange?() + } + + func applicationDidHide() { + visibility.applicationDidHide() + window.orderOut(nil) + onVisibilityChange?() + } + + func applicationDidUnhide() { + visibility.applicationDidUnhide() + if visibility.shouldShow { window.orderFrontRegardless() } + onVisibilityChange?() } 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..505eca04 --- /dev/null +++ b/native/Tests/FremkitCoreTests/DashboardVisibilityTests.swift @@ -0,0 +1,39 @@ +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 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 de2362d6..26912a36 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() }), + ("testApplicationHideDoesNotClearUserPreference", { ($0 as! DashboardVisibilityTests).testApplicationHideDoesNotClearUserPreference() }), + ]), ("L10nTests", { L10nTests() }, [ ("testPicksFrenchForAFrenchSystem", { ($0 as! L10nTests).testPicksFrenchForAFrenchSystem() }), ("testPicksEnglishForEverythingElse", { ($0 as! L10nTests).testPicksEnglishForEverythingElse() }),