Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion macos/Sources/HerdrMacOS/HerdrApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ struct HerdrApp: App {

var body: some Scene {
Settings {
HideSettingsView(model: appDelegate.model)
HideSettingsScene(model: appDelegate.model)
}
.commands {
ShellCommands(model: appDelegate.model)
Expand Down
19 changes: 17 additions & 2 deletions macos/Sources/HerdrMacOS/HideSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ import SwiftUI
/// and made Settings read as a different application. The tokens are the same
/// ones the sidebar and the tab strip use: the four-step surface ladder,
/// hairline borders, no shadows, and the spacing and radius scales.
/// What the menu bar's Settings scene shows: the settings view under the same
/// model environment the main window gives its content, so a control shared
/// with the main window (a keycap, a tooltip target) resolves the model in
/// both hosts. The scene is a second window with no ancestor of its own, and
/// a view that read the model from the environment trapped there.
struct HideSettingsScene: View {
@ObservedObject var model: ShellModel
var initialTab: HideSettingsTab = .general

var body: some View {
HideSettingsView(model: model, initialTab: initialTab)
.environmentObject(model)
}
}

struct HideSettingsView: View {
@ObservedObject var model: ShellModel
/// The sheet has no title bar, so it carries its own close button. The
Expand Down Expand Up @@ -52,7 +67,7 @@ struct HideSettingsView: View {
accentHex: $accentHex,
fontSize: $fontSize
)
case .agents: HideAgentSettings()
case .agents: HideAgentSettings(model: model)
case .pet: HidePetSettings(model: model)
case .devices: HideDeviceSettings(model: model)
case .shortcuts: HideShortcutSettings(model: model)
Expand Down Expand Up @@ -438,7 +453,7 @@ private struct HideAppearanceSettings: View {
}

private struct HideAgentSettings: View {
@EnvironmentObject private var model: ShellModel
@ObservedObject var model: ShellModel

var body: some View {
HideSettingsGroup(
Expand Down
44 changes: 44 additions & 0 deletions macos/Tests/HerdrMacOSTests/SettingsSceneTabsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import AppKit
import Foundation
import SwiftUI
import Testing

@testable import HerdrMacOS

/// The menu bar's Settings scene is a second window with no ancestor of its
/// own: a tab, or a control a tab shares with the main window, that reads the
/// model from an environment the scene does not provide traps the first time
/// it is shown. Every tab is rendered here exactly as that scene renders it.
@Test @MainActor func everySettingsTabRendersFromTheSettingsScene() throws {
let root = FileManager.default.temporaryDirectory
.appendingPathComponent("settings-scene-\(UUID().uuidString)", isDirectory: true)
let stateURL = root.appendingPathComponent("state.json")
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: root) }

let bridge = CoreBridge(arguments: [
"HerdrMacOS",
"--verification-ui-fixture",
"--workspace-root", root.path,
"--state-path", stateURL.path,
])
let model = ShellModel(core: bridge)

for tab in HideSettingsTab.allCases {
let host = NSHostingView(rootView: HideSettingsScene(model: model, initialTab: tab))
let window = NSWindow(
contentRect: NSRect(origin: .zero, size: HideTheme.settingsSheetSize),
styleMask: [.titled],
backing: .buffered,
defer: false
)
// AppKit releases a closed window on its own; ARC must not release it
// a second time when this scope ends.
window.isReleasedWhenClosed = false
window.contentView = host
host.layoutSubtreeIfNeeded()
host.displayIfNeeded()
#expect(host.fittingSize.height > 0, "\(tab) rendered nothing")
window.close()
}
}
Loading