diff --git a/Sources/ParcelApp/NativeAppRuntime.swift b/Sources/ParcelApp/NativeAppRuntime.swift index b5b7643a..1fd7291e 100644 --- a/Sources/ParcelApp/NativeAppRuntime.swift +++ b/Sources/ParcelApp/NativeAppRuntime.swift @@ -78,12 +78,10 @@ final class NativeAppRuntime: AppRuntime { private var hotkeyGate = HotkeyDispatchGate() private var effectiveShortcuts: [ConfigCommand: KeyChord]? private var registeredShortcutConfiguration: ParcelConfiguration? - private var notice: String? private var compositionProblem: MenuProblem? private lazy var configViewer = AppConfigViewer { [weak self] error in self?.services.composition?.report(error) } - private var noticeActions: [NoticeAction] = [] private var hotkeyInputFailure: AppInputFailure? private var mouseInputFailure: AppInputFailure? private var highlightPreference = MenuHighlightPreference() @@ -278,7 +276,7 @@ final class NativeAppRuntime: AppRuntime { active: engine.isRunning && engine.isAutomaticTilingEnabled) self.controls?.update( state: snapshot.state, configuration: self.learningConfiguration, - active: engine.isRunning && engine.isAutomaticTilingEnabled) + active: engine.isRunning && engine.systemWindowConflict == nil) do { for topic in changes.receive(snapshot) { try await self.server?.publish( @@ -833,7 +831,7 @@ final class NativeAppRuntime: AppRuntime { active: engine.isRunning && engine.isAutomaticTilingEnabled) controls?.update( state: engine.snapshot.state, configuration: learningConfiguration, - active: engine.isRunning && engine.isAutomaticTilingEnabled) + active: engine.isRunning && engine.systemWindowConflict == nil) } deinit { @@ -898,7 +896,6 @@ extension NativeAppRuntime { try await self.services.send(command, in: workspace.key) } } - shell.showNotice(notice) shell.showSuspensionStatus(services.engine.flatMap { Self.suspensionStatus($0.snapshot) }) refreshMenuProblem() } @@ -1134,9 +1131,18 @@ extension NativeAppRuntime { func showSettings() { shell?.showSettings() } func showNotice(_ notice: String?) { showNotice(notice, actions: []) } func showNotice(_ notice: String?, actions: [NoticeAction]) { - self.notice = notice - noticeActions = notice == nil ? [] : actions - shell?.showNotice(notice) + if let notice { feedback?.controller.showTransientNotice(notice) } + refreshMenuProblem() + } + + func showNotice(_ report: AppNotices.Report) { + prepareFeedback() + feedback?.controller.showTransientNotice(report.message, kind: report.kind.rawValue, count: report.count) + refreshMenuProblem() + } + + func clearNotice(_ kind: AppNotices.Kind) { + feedback?.controller.clearTransientNotice(kind: kind.rawValue) refreshMenuProblem() } @@ -1176,16 +1182,16 @@ extension NativeAppRuntime { Self.menuProblem( shortcutsOff: shortcutsOff, secureInput: secureInput.isEnabled, secureInputOwner: secureInput.ownerName, updateReady: updater.isReadyToRestart, - configuration: compositionProblem == .configuration)) + configuration: compositionProblem)) } static func menuProblem( - shortcutsOff: Bool, secureInput: Bool, secureInputOwner: String?, updateReady: Bool, configuration: Bool + shortcutsOff: Bool, secureInput: Bool, secureInputOwner: String?, updateReady: Bool, configuration: MenuProblem? ) -> MenuProblem? { if shortcutsOff { return .shortcutsOff } - if secureInput { return .secureInput(ownerName: secureInputOwner) } + if case .configuration = configuration { return configuration } if updateReady { return .updateReady } - if configuration { return .configuration } + if secureInput { return .secureInput(ownerName: secureInputOwner) } return nil } @@ -1196,7 +1202,7 @@ extension NativeAppRuntime { private func resolveMenuProblem(_ problem: MenuProblem) { switch problem { case .shortcutsOff: - openNoticeAction(Self.shortcutRepairAction(noticeActions)) + openNoticeAction(Self.shortcutRepairAction(services.composition?.notices.shortcutRepairActions ?? [])) case .secureInput: break case .updateReady: guard updater.restartToUpdate() else { @@ -1204,10 +1210,13 @@ extension NativeAppRuntime { refreshMenuProblem() return } - case .configuration: + case .configuration(let reason): do { try configViewer.show( - fileURL: store.fileURL, line: services.composition?.diagnostics.first?.location.line ?? 1) + fileURL: store.fileURL, + line: services.composition?.diagnostics.first(where: { $0.severity == .error })?.location.line, + reason: reason + ) } catch { services.composition?.report(error) } } } @@ -1328,7 +1337,7 @@ private enum SystemSettingsFailure: Error { extension NativeAppRuntime { func closeStackWindow(_ window: WindowID) { - guard let engine = services.engine, engine.isRunning, engine.isAutomaticTilingEnabled, let nativeWorld, + guard let engine = services.engine, engine.isRunning, let nativeWorld, let key = engine.snapshot.state.workspace(containing: window), engine.snapshot.state.isActive(key), engine.snapshot.state.workspaces[key]?.tree?.stacks.contains(where: { $0.windows.count > 1 && $0.windows.contains(window) @@ -1338,12 +1347,12 @@ extension NativeAppRuntime { dispatch { [weak self, weak engine] in defer { self?.closingWindows.remove(window) } try await nativeWorld.close(window) { edited in - guard let engine, self?.services.engine === engine, engine.isRunning, engine.isAutomaticTilingEnabled + guard let engine, self?.services.engine === engine, engine.isRunning else { return false } guard StackCloseConfirmation.confirm(title: title, edited: edited), - self?.services.engine === engine, engine.isRunning, engine.isAutomaticTilingEnabled, + self?.services.engine === engine, engine.isRunning, let key = engine.snapshot.state.workspace(containing: window), engine.snapshot.state.isActive(key), engine.snapshot.state.workspaces[key]?.tree?.stacks.contains(where: { $0.windows.count > 1 && $0.windows.contains(window) @@ -1355,7 +1364,7 @@ extension NativeAppRuntime { } func focusStackWindow(_ window: WindowID) { - guard let engine = services.engine, engine.isRunning, engine.isAutomaticTilingEnabled, let world, + guard let engine = services.engine, engine.isRunning, let world, let key = engine.snapshot.state.workspace(containing: window), engine.snapshot.state.isActive(key), engine.snapshot.state.workspaces[key]?.tree?.stacks.contains(where: { $0.windows.count > 1 && $0.windows.contains(window) @@ -1366,7 +1375,7 @@ extension NativeAppRuntime { self?.services.composition?.report(failure) return } - guard let engine, self?.services.engine === engine, engine.isRunning, engine.isAutomaticTilingEnabled, + guard let engine, self?.services.engine === engine, engine.isRunning, let key = engine.snapshot.state.workspace(containing: window), engine.snapshot.state.isActive(key) else { return } engine.send(.focusChanged(window)) @@ -1395,7 +1404,7 @@ extension NativeAppRuntime { } private func performHoverAction(_ request: HoverActionRequest) async throws { - guard let engine = services.engine, engine.isRunning, engine.isAutomaticTilingEnabled, + guard let engine = services.engine, engine.isRunning, engine.systemWindowConflict == nil, engine.snapshot.state.workspace(containing: request.window) == request.workspace, engine.snapshot.state.isActive(request.workspace), engine.snapshot.state.windows[request.window] != nil @@ -1425,7 +1434,7 @@ extension NativeAppRuntime { } private func cycleStackWindow(_ window: WindowID, direction: CycleDirection) { - guard let engine = services.engine, engine.isRunning, engine.isAutomaticTilingEnabled, + guard let engine = services.engine, engine.isRunning, let key = engine.snapshot.state.workspace(containing: window), engine.snapshot.state.isActive(key) else { return } engine.send( diff --git a/Tests/ParcelAppTests/AppMouseControlTests.swift b/Tests/ParcelAppTests/AppMouseControlTests.swift index d2f08a1a..082e84fe 100644 --- a/Tests/ParcelAppTests/AppMouseControlTests.swift +++ b/Tests/ParcelAppTests/AppMouseControlTests.swift @@ -76,25 +76,26 @@ extension AppKitTestSuite { @Test func inputTimeoutExplainsWhyControlsStopped() { let notices = AppNotices() - notices.report(InputError.tapTimedOut, kind: .input) + let report = notices.report(InputError.tapTimedOut, kind: .input) #expect( - notices.visible == [ - "Mouse controls stopped after an input timeout. Restart Parcel when it is responsive." - ]) + report.message == "Mouse controls stopped after an input timeout. Restart Parcel when it is responsive." + ) #expect(notices.counts[.input] == 1) } - @Test func localizedFailuresRefreshWithoutReplacingInputTimeoutGuidance() { + @Test func localizedFailuresRemainIndependentOfInputTimeoutGuidance() { let notices = AppNotices() - notices.report(InputError.tapTimedOut, kind: .input) - notices.report(AppFailure(message: "First rule failure"), kind: .internalFailure) - notices.report(AppFailure(message: "Second rule failure"), kind: .internalFailure) - notices.report(InputError.tapEnableFailed, kind: .input) + let timeout = notices.report(InputError.tapTimedOut, kind: .input) + let first = notices.report(AppFailure(message: "First rule failure"), kind: .internalFailure) + let second = notices.report(AppFailure(message: "Second rule failure"), kind: .internalFailure) + let input = notices.report(InputError.tapEnableFailed, kind: .input) #expect( - notices.visible == [ - "Mouse controls stopped after an input timeout. Restart Parcel when it is responsive.", - "Second rule failure", - ]) + timeout.message + == "Mouse controls stopped after an input timeout. Restart Parcel when it is responsive.") + #expect(first.message == "First rule failure") + #expect(second.message == "Second rule failure") + #expect(input.message == AppNotices.Kind.input.message) + #expect(notices.shortcutRepairActions.isEmpty) #expect(notices.counts[.input] == 2) #expect(notices.counts[.internalFailure] == 2) } diff --git a/Tests/ParcelAppTests/LearningRuntimeTests.swift b/Tests/ParcelAppTests/LearningRuntimeTests.swift index c435b7b8..4c6460cd 100644 --- a/Tests/ParcelAppTests/LearningRuntimeTests.swift +++ b/Tests/ParcelAppTests/LearningRuntimeTests.swift @@ -10,7 +10,7 @@ import Testing extension AppKitTestSuite { @Suite(.serialized) @MainActor struct LearningRuntimeTests { - @Test func chipFocusGoesThroughWorldAndRejectsStaleOrPausedRequests() async throws { + @Test func chipFocusGoesThroughWorldWhileAutomaticTilingIsOffAndRejectsStaleRequests() async throws { let scene = try scene() let runtime = scene.runtime let world = scene.world @@ -28,7 +28,11 @@ extension AppKitTestSuite { world.focused = nil runtime.services.setAutomaticTilingEnabled(false) runtime.focusStackWindow(WindowID(rawValue: 2)) - #expect(world.focused == nil) + _ = try await engine.perform(.retile) + #expect(world.focused == WindowID(rawValue: 2)) + #expect(engine.snapshot.state.focusedWindow == WindowID(rawValue: 2)) + #expect(!engine.isAutomaticTilingEnabled) + world.focused = nil try await runtime.restoreAndStopEngine() runtime.focusStackWindow(WindowID(rawValue: 2)) #expect(world.focused == nil) diff --git a/Tests/ParcelE2ETests/HoverControlsEndToEndTests.swift b/Tests/ParcelE2ETests/HoverControlsEndToEndTests.swift index f2df0f7b..45a1a580 100644 --- a/Tests/ParcelE2ETests/HoverControlsEndToEndTests.swift +++ b/Tests/ParcelE2ETests/HoverControlsEndToEndTests.swift @@ -10,7 +10,8 @@ import Testing @testable import ParcelTestSupport extension RealAppEndToEndTests { - @Test func hoverPrimaryFocusAndFloatButtonsControlTheirFixtureWindow() async throws { + @Test(arguments: [true, false]) + func hoverPrimaryFocusAndFloatButtonsControlTheirFixtureWindow(automaticTiling: Bool) async throws { var configuration = E2EConfiguration() configuration.layout = .side configuration.ratio = 0.6 @@ -29,6 +30,7 @@ extension RealAppEndToEndTests { let original = try session.frames(for: fixture) let primaryFrame = try #require(original[first.number]) let secondaryFrame = try #require(original[second.number]) + if !automaticTiling { try await session.command("toggle-automatic-tiling") } try await session.command("e2e-hover-click", String(second.number), "primary") try await waitUntil("hover Primary moves its target rather than the focused window") { @@ -64,6 +66,8 @@ extension RealAppEndToEndTests { let tiled = try await session.settledWindows(for: fixture, count: 2) #expect(tiled.allSatisfy { !$0.floating }) try await session.expectLayout(tiled, fixture: fixture, layout: .side) + let config: AppConfig = try await session.query("config") + #expect(config.automaticTilingEnabled == automaticTiling) #expect(NSWorkspace.shared.frontmostApplication?.processIdentifier != appPID) } } diff --git a/Tests/ParcelE2ETests/LearningEndToEndTests.swift b/Tests/ParcelE2ETests/LearningEndToEndTests.swift index 910b49be..43cca8b6 100644 --- a/Tests/ParcelE2ETests/LearningEndToEndTests.swift +++ b/Tests/ParcelE2ETests/LearningEndToEndTests.swift @@ -72,15 +72,24 @@ extension RealAppEndToEndTests { let selected = try #require(selectedChip) #expect(selected.window == WindowID(rawValue: target.number)) let committed = try session.frames(for: fixture) - try await session.command("pause") - try await waitUntil("paused tiling removes stack chip panels") { - try !serverWindows().contains { $0.pid == pid && $0.layer == NSWindow.Level.floating.rawValue } + try await session.command("toggle-automatic-tiling") + try await remainTrue( + "Automatic tiling off keeps explicit stack controls and real frames", duration: .milliseconds(400) + ) { + try serverWindows().contains { panel in + panel.pid == pid && panel.layer == NSWindow.Level.floating.rawValue + && framesMatch( + panel.bounds.frame, + Rect( + x: group.frame.minX, y: group.frame.minY, width: group.frame.width, + height: group.frame.height)) + } && session.frames(for: fixture) == committed } - #expect(try session.frames(for: fixture) == committed) } } - @Test func middleClickClosesOnlyItsFixtureWindowWithoutATour() async throws { + @Test(arguments: [true, false]) + func middleClickClosesOnlyItsFixtureWindowWithoutATour(automaticTiling: Bool) async throws { var configuration = E2EConfiguration() configuration.outerGap = 20 try await withSession(configuration: configuration) { session in @@ -90,6 +99,7 @@ extension RealAppEndToEndTests { let before = try await liveLearningState(session, fixture: fixture) let group = try #require(StackChips.groups(in: before).first) let target = try #require(group.chips.last) + if !automaticTiling { try await session.command("toggle-automatic-tiling") } try await session.command("e2e-chip-middle-click", String(target.window.rawValue)) try await waitUntil("middle click closes its fixture window") { let reply = try await fixture.snapshot() diff --git a/Tests/ParcelE2ETests/StackControlsEndToEndTests.swift b/Tests/ParcelE2ETests/StackControlsEndToEndTests.swift index ba78988a..99a6fdb6 100644 --- a/Tests/ParcelE2ETests/StackControlsEndToEndTests.swift +++ b/Tests/ParcelE2ETests/StackControlsEndToEndTests.swift @@ -40,7 +40,8 @@ extension RealAppEndToEndTests { } } - @Test func stackArrowsAndGripScrollCycleFixtureFocusWithoutMovingTiles() async throws { + @Test(arguments: [true, false]) + func stackArrowsAndGripScrollCycleFixtureFocusWithoutMovingTiles(automaticTiling: Bool) async throws { var configuration = E2EConfiguration() configuration.windowCap = 1 try await withSession(configuration: configuration) { session in @@ -61,6 +62,7 @@ extension RealAppEndToEndTests { let native = try #require(snapshot.windows.first { $0.number == original.rawValue }) _ = try await fixture.control(FixtureControl(action: "focus", window: native.index)) try await expectStackFixtureFocus(original, fixture: fixture, session: session) + if !automaticTiling { try await session.command("toggle-automatic-tiling") } try await session.command("e2e-stack-input", "scroll-next", String(original.rawValue)) try await expectStackFixtureFocus(next, fixture: fixture, session: session) #expect(try session.frames(for: fixture) == before)