From 55e100b80fb0945f3f2bf07e3bcdc3459a67a0d8 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Sun, 1 Nov 2026 03:00:07 -0500 Subject: [PATCH] Keep tour drafts readable Signed-off-by: Vincent Taverna --- .../ParcelUI/Resources/TourSetup.xcstrings | 7 +- Sources/ParcelUI/Tour/LearningPanel.swift | 4 +- Sources/ParcelUI/Tour/README.md | 31 +++--- Sources/ParcelUI/Tour/TourAllowView.swift | 22 ++++- Sources/ParcelUI/Tour/TourCheckRow.swift | 2 + .../Tour/TourPersonalizationControls.swift | 45 +++++++++ .../Tour/TourPersonalizationEditor.swift | 9 ++ .../Tour/TourPersonalizationView.swift | 45 +-------- Sources/ParcelUI/Tour/TourSetup.swift | 44 ++------- .../TourShortcutWarningPresentation.swift | 6 ++ Sources/ParcelUI/Tour/TourView.swift | 26 +++-- .../Tour/WindowLearningController.swift | 11 ++- .../Tour/LearningLocalizationTests.swift | 19 +++- Tests/ParcelUITests/Tour/TourSetupTests.swift | 95 +++++++++++++++++-- .../Tour/WindowLearningControllerTests.swift | 10 +- 15 files changed, 249 insertions(+), 127 deletions(-) create mode 100644 Sources/ParcelUI/Tour/TourPersonalizationControls.swift create mode 100644 Sources/ParcelUI/Tour/TourPersonalizationEditor.swift diff --git a/Sources/ParcelUI/Resources/TourSetup.xcstrings b/Sources/ParcelUI/Resources/TourSetup.xcstrings index c4f4c3fd..f67e3ab1 100644 --- a/Sources/ParcelUI/Resources/TourSetup.xcstrings +++ b/Sources/ParcelUI/Resources/TourSetup.xcstrings @@ -1,6 +1,7 @@ { "sourceLanguage": "en", "strings": { + "Control Option is also VoiceOver’s key. Use Option Command instead?": {"comment": "Spoken prefix choice question; spell out the modifier names rather than reading glyphs.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Control Option is also VoiceOver’s key. Use Option Command instead?"}}}}, "You’re All Set": {"comment": "Completion title after the tour; no terminal punctuation.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "You’re All Set"}}}}, "Accessibility": {"comment": "Status row for the macOS permission.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Accessibility"}}}}, "Allowed": {"comment": "Accessibility permission is granted.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Allowed"}}}}, @@ -26,7 +27,7 @@ "Review Settings after setup failed (%1$@) and restoration failed (%2$@).": {"comment": "First placeholder is the original error, second is the rollback error; translators may reorder them.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Review Settings after setup failed (%1$@) and restoration failed (%2$@)."}}}}, "%@ Restoring your previous setup also failed: %@. Review Settings and your windows before trying again.": {"comment": "Tidy rollback error. First placeholder is the original error; second is the restoration error.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "%@ Restoring your previous setup also failed: %@. Review Settings and your windows before trying again."}}}}, "%1$@ · %2$@": {"comment": "Shortcut summary: action name followed by its configured shortcut glyphs or spoken equivalent.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "%1$@ · %2$@"}}}}, - "%1$@: %2$@": {"comment": "Accessibility status: setting name followed by Ready, Needs attention, or Not verified.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "%1$@: %2$@"}}}}, + "%1$@: %2$@": {"comment": "First placeholder is a setting or action name; second is its state or conflict detail. Translators may reorder them.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "%1$@: %2$@"}}}}, "%g points": {"comment": "Highlight width in points; placeholder is a fractional number.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "%g points"}}}}, "%lld points": {"comment": "Highlight width in points; placeholder is an integer.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "%#@points@"}, "substitutions": {"points": {"argNum": 1, "formatSpecifier": "lld", "variations": {"plural": {"one": {"stringUnit": {"state": "translated", "value": "%lld point"}}, "other": {"stringUnit": {"state": "translated", "value": "%lld points"}}}}}}}}}, "Welcome to Parcel": {"comment": "Title of tour screen one.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Welcome to Parcel"}}}}, @@ -37,7 +38,7 @@ "Tidy Up": {"comment": "Title of tour screen six, arranging windows only after confirmation.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Tidy Up"}}}}, "Windows that find their place.": {"comment": "Welcome tagline, approved short copy.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Windows that find their place."}}}}, "Parcel needs Accessibility to move your windows.": {"comment": "Permission explanation; Accessibility is the name of the macOS permission.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Parcel needs Accessibility to move your windows."}}}}, - "Pick a style. Tidy saves it.": {"comment": "Personalization is a draft until the final Tidy action.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Pick a style. Tidy saves it."}}}}, + "Pick a style to save when you tidy.": {"comment": "Personalization is a draft until the final Tidy action.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Pick a style to save when you tidy."}}}}, "Ready to tidy this screen?": {"comment": "Question before arranging real windows on the selected display.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Ready to tidy this screen?"}}}}, "Find Parcel in your menu bar anytime.": {"comment": "Completion copy after successful Tidy Up", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Find Parcel in your menu bar anytime."}}}}, "Get Started": {"comment": "Primary action on Welcome to Parcel", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Get Started"}}}}, @@ -54,7 +55,7 @@ "Not Yet": {"comment": "Dismiss the tour and leave automatic tiling off.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Not Yet"}}}}, "Start automatic tiling, or leave it off.": {"comment": "Skip confirmation explaining the two possible outcomes.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Start automatic tiling, or leave it off."}}}}, "Tour progress": {"comment": "VoiceOver label for the six progress dots.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Tour progress"}}}}, - "Screen %1$lld of %2$lld": {"comment": "VoiceOver progress value; placeholder is the current tour screen, 1 through 6.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Screen %1$lld of %2$lld"}}}}, + "Screen %1$lld of %2$lld": {"comment": "VoiceOver progress value; first placeholder is the current screen, second is the total screen count.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Screen %1$lld of %2$lld"}}}}, "Stage Manager and tiling": {"comment": "Single compatibility row for built-in window arranging features.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Stage Manager and tiling"}}}}, "Shortcuts": {"comment": "Compatibility row checking configured keyboard shortcuts.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Shortcuts"}}}}, "Turn Off…": {"comment": "Open Desktop & Dock settings to disable conflicting system window features.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Turn Off…"}}}}, diff --git a/Sources/ParcelUI/Tour/LearningPanel.swift b/Sources/ParcelUI/Tour/LearningPanel.swift index f03fd871..f8212f84 100644 --- a/Sources/ParcelUI/Tour/LearningPanel.swift +++ b/Sources/ParcelUI/Tour/LearningPanel.swift @@ -6,9 +6,11 @@ import QuartzCore @MainActor final class LearningPanel: NSPanel { let interactive: Bool + private let setupWindow: Bool init(title: String, interactive: Bool, setupWindow: Bool = false) { self.interactive = interactive + self.setupWindow = setupWindow super.init( contentRect: .zero, styleMask: setupWindow ? [.titled, .fullSizeContentView] : [.borderless, .nonactivatingPanel], @@ -33,7 +35,7 @@ final class LearningPanel: NSPanel { } override var canBecomeKey: Bool { interactive } - override var canBecomeMain: Bool { false } + override var canBecomeMain: Bool { setupWindow } func place(_ rect: CGRect) { let height = NSScreen.screens.first?.frame.maxY ?? 0 diff --git a/Sources/ParcelUI/Tour/README.md b/Sources/ParcelUI/Tour/README.md index fbcded22..b1b1b824 100644 --- a/Sources/ParcelUI/Tour/README.md +++ b/Sources/ParcelUI/Tour/README.md @@ -1,18 +1,23 @@ # Guided tour -First run uses one panel: Welcome, Allow Parcel, The basics, Power moves, -Make it yours, and Tidy. Menu replay starts at The basics. The cards show -resolved bindings and play miniature demos, never real-window commands. +The content-sized panel has six screens: Welcome, Allow Parcel, The Basics, +Power Moves, Make It Yours, and Tidy Up. Menu replay starts at The Basics. +Cards show actual bindings as keycaps and animate drawings, never real windows. -Automatic tiling stays paused until Tidy succeeds. Skip asks “Tidy now?”: -Tidy uses defaults and discards the draft; Not Yet leaves automatic tiling off. -The v2 completion preference is separate from saved hands-on Practice progress. -Practice is an optional link after successful Tidy, not another tour screen. +Only a brand-new install holds tiling before consent, and that hold is never +saved. Upgrades and replay preserve tiling and shortcuts. Skip asks “Tidy now?”: +Tidy keeps the current configuration and ignores the draft; Not Yet explicitly +leaves automatic tiling off. Unchanged configuration files are not written. -Tidy saves choices atomically, verifies the real arrangement, and rolls back -on failure. Reduced Motion keeps demos static. Keyboard and VoiceOver users -can reach every action; Return invokes the primary action and Escape asks to skip. +Allow observes Accessibility changes and refreshes checks when Parcel activates. +Only new installs draft Open at login on; registration follows consent. +When VoiceOver runs, the prefix choices are Use ⌥⌘ and Keep ⌃⌥. -Unit tests cover navigation, permissions, bindings, drafts, and rollback. -FixtureApp e2e covers startup safety and real-window readback. The rendering -suite can export light/dark QA images with `PARCEL_TOUR_QA_DIR`. +Tidy saves changed choices atomically, verifies the arrangement, and rolls back +on failure. Reduce Motion keeps demos static. Return invokes the primary action; +Escape asks to skip. Screen changes announce their title to VoiceOver. +Practice with your windows is an optional link after Tidy, not another screen. + +Tests cover navigation, permissions, bindings, login, replay, drafts, and rollback. +FixtureApp e2e checks startup safety, window readback, and keyboard reactivation. +`PARCEL_TOUR_QA_DIR` exports light/dark, larger-text, and high-contrast renders. diff --git a/Sources/ParcelUI/Tour/TourAllowView.swift b/Sources/ParcelUI/Tour/TourAllowView.swift index f9a03aaa..6a136f9f 100644 --- a/Sources/ParcelUI/Tour/TourAllowView.swift +++ b/Sources/ParcelUI/Tour/TourAllowView.swift @@ -16,7 +16,7 @@ struct TourAllowView: View { Form { TourCheckRow( title: "Accessibility", - status: TourText.text(setup.permission == .granted ? "Allowed" : "Not allowed"), + status: accessibilityStatus, ready: setup.permission == .granted, known: setup.permission != .checking, fix: "Open Settings", action: openAccessibility) TourCheckRow( @@ -27,11 +27,14 @@ struct TourAllowView: View { title: "Shortcuts", status: shortcutStatus, ready: setup.shortcuts != nil && !setup.hasShortcutClash && setup.shortcuts?.limitations.isEmpty == true, - known: setup.shortcuts != nil, fix: "Choose Another Prefix", action: openShortcuts) + known: setup.shortcuts != nil, fix: "Choose Another Prefix", action: openShortcuts, + statusAccessibilityLabel: shortcutAccessibilityStatus) if setup.showsVoiceOverChoice { VStack(alignment: .leading, spacing: 8) { Text(TourText.text("⌃⌥ is also VoiceOver’s key. Use ⌥⌘ instead?")) .fixedSize(horizontal: false, vertical: true) + .accessibilityLabel( + TourText.text("Control Option is also VoiceOver’s key. Use Option Command instead?")) HStack { Button(TourText.text("Use ⌥⌘")) { choosePrefix(true) } .accessibilityLabel(TourText.text("Use Option Command")) @@ -57,6 +60,11 @@ struct TourAllowView: View { } } + private var accessibilityStatus: String { + if setup.permission == .checking { return TourText.text("Checking…") } + return TourText.text(setup.permission == .granted ? "Allowed" : "Not allowed") + } + private var systemStatus: String { guard let system = setup.system else { return TourText.text("Checking…") } if system.isClear { return TourText.text("Off") } @@ -66,13 +74,21 @@ struct TourAllowView: View { private var shortcutStatus: String { guard let shortcuts = setup.shortcuts else { return TourText.text("Checking…") } if let warning = shortcuts.warnings.first { - return warning.messages.first ?? TourShortcutWarningPresentation(warning: warning).title + return TourShortcutWarningPresentation(warning: warning).detail } if let notice = shortcuts.modeNotices.first { return notice } if let limitation = shortcuts.limitations.first { return limitation } return TourText.text("No conflicts") } + private var shortcutAccessibilityStatus: String { + if let warning = setup.shortcuts?.warnings.first { + return TourShortcutWarningPresentation(warning: warning).detailAccessibilityLabel + } + if let notice = setup.shortcuts?.modeNoticeAccessibilityLabels.first { return notice } + return shortcutStatus + } + private func choosePrefix(_ alternate: Bool) { controller.runSetup { try await setup.chooseVoiceOverPrefix(useAlternate: alternate) } } diff --git a/Sources/ParcelUI/Tour/TourCheckRow.swift b/Sources/ParcelUI/Tour/TourCheckRow.swift index 98ed05fb..b761e404 100644 --- a/Sources/ParcelUI/Tour/TourCheckRow.swift +++ b/Sources/ParcelUI/Tour/TourCheckRow.swift @@ -7,6 +7,7 @@ struct TourCheckRow: View { let known: Bool var fix: String? var action: () -> Void = {} + var statusAccessibilityLabel: String? var body: some View { VStack(alignment: .leading, spacing: 6) { @@ -30,6 +31,7 @@ struct TourCheckRow: View { private var stateText: some View { Text(status) + .accessibilityLabel(statusAccessibilityLabel ?? status) .foregroundStyle(.secondary) .fixedSize(horizontal: false, vertical: true) } diff --git a/Sources/ParcelUI/Tour/TourPersonalizationControls.swift b/Sources/ParcelUI/Tour/TourPersonalizationControls.swift new file mode 100644 index 00000000..4c8549d9 --- /dev/null +++ b/Sources/ParcelUI/Tour/TourPersonalizationControls.swift @@ -0,0 +1,45 @@ +import ParcelConfig +import SwiftUI + +struct TourPersonalizationControls: View { + let configuration: ParcelConfiguration + @Bindable var editor: TourPersonalizationEditor + + var body: some View { + VStack(alignment: .leading, spacing: 16) { + TourMiniature( + configuration: configuration, layout: editor.values.layout, windowCount: editor.values.windowCount, + kind: .layout + ) + .frame(height: TourSetupView.miniatureHeight) + .frame(maxWidth: .infinity) + Text(TourText.text("Pick a style to save when you tidy.")) + Form { + Picker(TourText.text("Layout"), selection: $editor.values.layout) { + ForEach(ConfigLayout.allCases, id: \.self) { Text($0.settingsTitle).tag($0) } + } + .accessibilityIdentifier("tour.layout") + Stepper(value: $editor.values.windowCount, in: 1...5) { + LabeledContent(TourText.text("Windows per screen"), value: editor.values.windowCount.formatted()) + } + .accessibilityIdentifier("tour.count") + Picker(TourText.text("Highlight style"), selection: $editor.values.highlight) { + ForEach(ConfigHighlight.allCases, id: \.self) { Text(highlightTitle($0)).tag($0) } + } + .accessibilityIdentifier("tour.highlight") + Picker(TourText.text("When full"), selection: $editor.values.whenFull) { + Text(TourText.text("Stack")).tag(ConfigWhenFull.stack) + Text(TourText.text("Float")).tag(ConfigWhenFull.float) + } + .pickerStyle(.segmented) + .accessibilityIdentifier("tour.overflow") + } + .formStyle(.grouped) + .fixedSize(horizontal: false, vertical: true) + } + } + + private func highlightTitle(_ highlight: ConfigHighlight) -> String { + highlight == .active ? TourText.text("Border on active window") : highlight.label + } +} diff --git a/Sources/ParcelUI/Tour/TourPersonalizationEditor.swift b/Sources/ParcelUI/Tour/TourPersonalizationEditor.swift new file mode 100644 index 00000000..6b9dca93 --- /dev/null +++ b/Sources/ParcelUI/Tour/TourPersonalizationEditor.swift @@ -0,0 +1,9 @@ +import Observation + +// Retired SwiftUI controls retain their draft until their bindings are released. +@MainActor @Observable +final class TourPersonalizationEditor { + var values: TourPersonalization + + init(_ values: TourPersonalization) { self.values = values } +} diff --git a/Sources/ParcelUI/Tour/TourPersonalizationView.swift b/Sources/ParcelUI/Tour/TourPersonalizationView.swift index 6e1fc343..330fd593 100644 --- a/Sources/ParcelUI/Tour/TourPersonalizationView.swift +++ b/Sources/ParcelUI/Tour/TourPersonalizationView.swift @@ -1,52 +1,11 @@ -import ParcelConfig import SwiftUI struct TourPersonalizationView: View { let controller: WindowLearningController - @Bindable private var setup: TourSetupController - - init(controller: WindowLearningController) { - self.controller = controller - setup = controller.setup - } var body: some View { - if let draft = setup.draft { - VStack(alignment: .leading, spacing: 16) { - TourMiniature( - configuration: controller.configuration, layout: draft.layout, windowCount: draft.windowCount, - kind: .layout - ) - .frame(height: TourSetupView.miniatureHeight) - .frame(maxWidth: .infinity) - Text(TourText.text("Pick a style. Tidy saves it.")) - Form { - Picker(TourText.text("Layout"), selection: $setup.draftLayout) { - ForEach(ConfigLayout.allCases, id: \.self) { Text($0.settingsTitle).tag($0) } - } - .accessibilityIdentifier("tour.layout") - Stepper(value: $setup.draftWindowCount, in: 1...5) { - LabeledContent(TourText.text("Windows per screen"), value: draft.windowCount.formatted()) - } - .accessibilityIdentifier("tour.count") - Picker(TourText.text("Highlight style"), selection: $setup.draftHighlight) { - ForEach(ConfigHighlight.allCases, id: \.self) { Text(highlightTitle($0)).tag($0) } - } - .accessibilityIdentifier("tour.highlight") - Picker(TourText.text("When full"), selection: $setup.draftWhenFull) { - Text(TourText.text("Stack")).tag(ConfigWhenFull.stack) - Text(TourText.text("Float")).tag(ConfigWhenFull.float) - } - .pickerStyle(.segmented) - .accessibilityIdentifier("tour.overflow") - } - .formStyle(.grouped) - .fixedSize(horizontal: false, vertical: true) - } + if let editor = controller.setup.draftEditor { + TourPersonalizationControls(configuration: controller.configuration, editor: editor) } } - - private func highlightTitle(_ highlight: ConfigHighlight) -> String { - highlight == .active ? TourText.text("Border on active window") : highlight.label - } } diff --git a/Sources/ParcelUI/Tour/TourSetup.swift b/Sources/ParcelUI/Tour/TourSetup.swift index f96c9e17..8c2afa1f 100644 --- a/Sources/ParcelUI/Tour/TourSetup.swift +++ b/Sources/ParcelUI/Tour/TourSetup.swift @@ -182,7 +182,8 @@ public final class TourSetupController { public private(set) var shortcuts: TourShortcutCheck? public private(set) var system: TourSystemCheck? public private(set) var login: TourLoginStatus? - public private(set) var draft: TourPersonalization? + private(set) var draftEditor: TourPersonalizationEditor? + public var draft: TourPersonalization? { draftEditor?.values } public private(set) var isBusy = false public private(set) var errorMessage: String? public private(set) var didTidy = false @@ -206,7 +207,7 @@ public final class TourSetupController { shortcuts = nil system = nil login = nil - draft = nil + draftEditor = nil didTidy = false undo = nil enableLoginByDefault = defaultOpenAtLogin && !hasAppliedLoginDefault @@ -252,7 +253,7 @@ public final class TourSetupController { try await perform { if tidyNow { try await commitLoginDraft() } try await requireActions().skip(tidyNow) - draft = nil + draftEditor = nil didTidy = tidyNow isSkipConfirmationPresented = false skipWasRequested = false @@ -267,7 +268,7 @@ public final class TourSetupController { shortcuts = nil system = nil login = nil - draft = nil + draftEditor = nil try await checkCurrentStep() } @@ -302,7 +303,7 @@ public final class TourSetupController { if draft == nil { var values = try requireActions().personalization() values.windowCount = min(5, max(1, values.windowCount)) - draft = values + draftEditor = TourPersonalizationEditor(values) } case .welcome, .basics, .powerMoves, .tidy, .complete: break } @@ -416,40 +417,13 @@ public final class TourSetupController { } public func updateDraft(_ draft: TourPersonalization) throws { - guard step == .personalize, !isBusy, draft.workspace == self.draft?.workspace, draft.isValid, + guard step == .personalize, !isBusy, let editor = draftEditor, draft.workspace == editor.values.workspace, + draft.isValid, (1...5).contains(draft.windowCount) else { throw TourSetupFailure.invalidDraft } - self.draft = draft - } - - public var draftLayout: ConfigLayout { - get { requireDraft().layout } - set { editDraft(\.layout, newValue) } - } - public var draftWindowCount: Int { - get { requireDraft().windowCount } - set { editDraft(\.windowCount, newValue) } - } - public var draftHighlight: ConfigHighlight { - get { requireDraft().highlight } - set { editDraft(\.highlight, newValue) } - } - public var draftWhenFull: ConfigWhenFull { - get { requireDraft().whenFull } - set { editDraft(\.whenFull, newValue) } - } - - private func requireDraft() -> TourPersonalization { - guard let draft else { preconditionFailure("Personalization controls require a draft") } - return draft - } - - private func editDraft(_ path: WritableKeyPath, _ value: Value) { - var draft = requireDraft() - draft[keyPath: path] = value - do { try updateDraft(draft) } catch { errorMessage = error.localizedDescription } + editor.values = draft } public func setOpenAtLogin(_ enabled: Bool) async throws { diff --git a/Sources/ParcelUI/Tour/TourShortcutWarningPresentation.swift b/Sources/ParcelUI/Tour/TourShortcutWarningPresentation.swift index 46374c27..756bc2d6 100644 --- a/Sources/ParcelUI/Tour/TourShortcutWarningPresentation.swift +++ b/Sources/ParcelUI/Tour/TourShortcutWarningPresentation.swift @@ -3,6 +3,8 @@ import Foundation struct TourShortcutWarningPresentation { let title: String let titleAccessibilityLabel: String + let detail: String + let detailAccessibilityLabel: String let suggestions: String let suggestionsAccessibilityLabel: String @@ -11,6 +13,10 @@ struct TourShortcutWarningPresentation { title = String(format: titleFormat, warning.command.settingsTitle, warning.chord.displayString) titleAccessibilityLabel = String( format: titleFormat, warning.command.settingsTitle, warning.chord.accessibilityLabel) + let message = warning.messages.first ?? TourText.text("Needs attention") + let detailFormat = TourText.text("%1$@: %2$@") + detail = String(format: detailFormat, title, message) + detailAccessibilityLabel = String(format: detailFormat, titleAccessibilityLabel, message) let suggestionsFormat = TourText.text("Try an alternative: %@") suggestions = String( format: suggestionsFormat, warning.suggestions.map(\.displayString).formatted(.list(type: .or))) diff --git a/Sources/ParcelUI/Tour/TourView.swift b/Sources/ParcelUI/Tour/TourView.swift index fb10fad3..e30dee0f 100644 --- a/Sources/ParcelUI/Tour/TourView.swift +++ b/Sources/ParcelUI/Tour/TourView.swift @@ -13,19 +13,16 @@ struct TourView: View { if controller.setup.isPresented { TourSetupView(controller: controller) } else { - ScrollView { - VStack(alignment: .leading, spacing: 16) { - HStack { - Text(UIStrings.text("A little tour, your way.")).font(.title2.bold()) - Spacer() - Button(UIStrings.text("Later")) { controller.pause() } - .disabled(controller.setup.isBusy) - } - learningContent - Spacer(minLength: 0) + VStack(alignment: .leading, spacing: 16) { + HStack { + Text(UIStrings.text("A little tour, your way.")).font(.title2.bold()) + Spacer() + Button(UIStrings.text("Later")) { controller.pause() } + .disabled(controller.setup.isBusy) } - .padding(24) + learningContent } + .padding(24) } } .frame(width: 440, alignment: .topLeading) @@ -90,10 +87,11 @@ struct TourView: View { Text(controller.instruction.detail) .fixedSize(horizontal: false, vertical: true) .accessibilityLabel(controller.instruction.detailAccessibilityLabel ?? controller.instruction.detail) - if let shortcut = controller.instruction.shortcut, - let label = controller.instruction.shortcutAccessibilityLabel + if controller.instruction.shortcut != nil, + let command = controller.tour.command(state: controller.state, configuration: controller.configuration), + let chord = controller.configuration.keybindings[command] { - Text(shortcut).font(.title3.monospaced()).accessibilityLabel(label) + ShortcutLabel(chord: chord) } if controller.tour.progress.track == .mouse && !controller.instruction.ready { Text(UIStrings.text("Open two tiled windows to give this a try.")).font(.caption) diff --git a/Sources/ParcelUI/Tour/WindowLearningController.swift b/Sources/ParcelUI/Tour/WindowLearningController.swift index 8762c045..aa698343 100644 --- a/Sources/ParcelUI/Tour/WindowLearningController.swift +++ b/Sources/ParcelUI/Tour/WindowLearningController.swift @@ -1,4 +1,5 @@ public import AppKit +import Dispatch import Observation public import ParcelConfig public import ParcelCore @@ -25,6 +26,8 @@ public final class WindowLearningController { defaults.set(true, forKey: "onboardingCompleted") onTourResolved?() if hide { + setupTask?.cancel() + setupTask = nil stopSetupObservations() setup.dismiss() panel?.orderOut(nil) @@ -188,9 +191,11 @@ public final class WindowLearningController { self?.refreshSetup(permissionOnly: true) } voiceOverObservation = NSWorkspace.shared.observe(\.isVoiceOverEnabled, options: [.new]) { - [weak self] _, change in - guard let enabled = change.newValue else { return } - MainActor.assumeIsolated { self?.setup.updateVoiceOver(enabled) } + [weak self] _, _ in + DispatchQueue.main.async { [weak self] in + guard let self, self.setup.isPresented else { return } + self.setup.updateVoiceOver(NSWorkspace.shared.isVoiceOverEnabled) + } } activationObservation = NotificationCenter.default.addObserver( forName: NSApplication.didBecomeActiveNotification, object: nil, queue: .main diff --git a/Tests/ParcelUITests/Tour/LearningLocalizationTests.swift b/Tests/ParcelUITests/Tour/LearningLocalizationTests.swift index f4a1b14e..7c5f3d7a 100644 --- a/Tests/ParcelUITests/Tour/LearningLocalizationTests.swift +++ b/Tests/ParcelUITests/Tour/LearningLocalizationTests.swift @@ -47,6 +47,21 @@ struct LearningLocalizationTests { } } + @Test func screenBodiesKeepOneShortSentenceWithoutSemicolons() throws { + let catalog = try loadCatalog("TourSetup") + let keys = [ + "Windows that find their place.", "Parcel needs Accessibility to move your windows.", + "Pick a style to save when you tidy.", "Ready to tidy this screen?", + "Find Parcel in your menu bar anytime.", + ] + for key in keys { + let english = try #require(catalog.strings[key]?.localizations["en"]?.stringUnit?.value) + #expect(english.split(whereSeparator: \.isWhitespace).count <= 12) + #expect(english.filter { ".!?".contains($0) }.count == 1) + #expect(!english.contains(";")) + } + } + @Test func pluralFormatNormalizationKeepsArgumentPositions() { #expect(normalizedPluralFormat("%#@points@", arguments: ["points": 1]) == "%1$#@points@") #expect( @@ -94,11 +109,11 @@ struct LearningLocalizationTests { #expect(catalogs[table]?.strings[step.primaryTitle] != nil) } case "title" where file.lastPathComponent == "TourCheckRow.swift": - for key in ["Stage Manager / macOS tiling", "Shortcuts"] { + for key in ["Accessibility", "Stage Manager and tiling", "Shortcuts"] { #expect(catalogs[table]?.strings[key] != nil) } case "fix" where file.lastPathComponent == "TourCheckRow.swift": - for key in ["Turn Off…", "Choose Another Prefix"] { + for key in ["Open Settings", "Turn Off…", "Choose Another Prefix"] { #expect(catalogs[table]?.strings[key] != nil) } case "String.LocalizationValue(name)" where file.lastPathComponent == "WindowRulesText.swift": diff --git a/Tests/ParcelUITests/Tour/TourSetupTests.swift b/Tests/ParcelUITests/Tour/TourSetupTests.swift index 14e8d9fe..035c9f42 100644 --- a/Tests/ParcelUITests/Tour/TourSetupTests.swift +++ b/Tests/ParcelUITests/Tour/TourSetupTests.swift @@ -995,18 +995,51 @@ struct TourSetupTests { setup.begin(.keyboard) try await fixture.reachPersonalization() let workspace = try #require(setup.draft).workspace - setup.draftLayout = .rows - setup.draftWindowCount = 2 - setup.draftHighlight = .active - setup.draftWhenFull = .float - #expect(setup.draftLayout == .rows) - #expect(setup.draftWindowCount == 2) - #expect(setup.draftHighlight == .active) - #expect(setup.draftWhenFull == .float) + let editor = try #require(setup.draftEditor) + editor.values.layout = .rows + editor.values.windowCount = 2 + editor.values.highlight = .active + editor.values.whenFull = .float + #expect(setup.draft?.layout == .rows) + #expect(setup.draft?.windowCount == 2) + #expect(setup.draft?.highlight == .active) + #expect(setup.draft?.whenFull == .float) #expect(setup.draft?.workspace == workspace) #expect(fixture.tidyAttempts.isEmpty) } + @Test func retiredPersonalizationBindingsRemainReadableWithoutEditingTheNewTour() async throws { + let fixture = TourSetupFixture() + let setup = fixture.controller + setup.begin(.keyboard) + try await fixture.reachPersonalization() + let retiredEditor = try #require(setup.draftEditor) + let saved = retiredEditor.values + setup.begin(.mouse) + #expect(setup.draft == nil) + #expect(retiredEditor.values == saved) + retiredEditor.values.layout = .rows + #expect(setup.draft == nil) + try await fixture.reachPersonalization() + let currentEditor = try #require(setup.draftEditor) + #expect(currentEditor !== retiredEditor) + #expect(setup.draft == saved) + } + + @Test func shortcutWarningNamesTheAffectedChordAndConflictWithSpokenKeys() throws { + let chord = try #require(ParcelConfiguration.defaults.keybindings[.focusLeft]) + let warning = try #require( + SettingsShortcutChecker.warnings( + bindings: [.focusLeft: chord, .focusRight: chord], environment: .init() + ).first) + let presentation = TourShortcutWarningPresentation(warning: warning) + let message = try #require(warning.messages.first) + #expect(presentation.detail.contains(chord.displayString)) + #expect(presentation.detail.contains(message)) + #expect(presentation.detailAccessibilityLabel.contains(chord.accessibilityLabel)) + #expect(presentation.detailAccessibilityLabel.contains(message)) + } + @Test func atomicSettingsBatchDoesNotPublishPartiallyValidChoices() throws { let directory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) @@ -1156,6 +1189,52 @@ extension AppKitTestSuite { #expect(Double(longestRun) / Double(bitmap.pixelsHigh) < 0.28) } + @Test(arguments: [ColorScheme.light, .dark], [PermissionStatus.missing, .granted]) + func voiceOverChoicesAndAccessibilityStateFitTheAllowPanel( + colorScheme: ColorScheme, permission: PermissionStatus + ) async throws { + let suite = "tour-voiceover-render.\(UUID().uuidString)" + let defaults = try #require(UserDefaults(suiteName: suite)) + defer { defaults.removePersistentDomain(forName: suite) } + let learning = try WindowLearningController(defaults: defaults, onFailure: { Issue.record($0) }) + defer { learning.stop() } + let fixture = TourSetupFixture() + fixture.permission = permission + var configuration = ParcelConfiguration.defaults + configuration.motion.enabled = false + learning.update(state: LearningScene.state(), configuration: configuration, active: false) + let setup = learning.setup + setup.actions = fixture.controller.actions + setup.begin(.keyboard, firstRun: true, defaultOpenAtLogin: true) + setup.updateVoiceOver(true) + try await setup.next() + #expect(setup.step == .allow) + #expect(setup.showsVoiceOverChoice) + #expect(setup.permission == permission) + #expect(fixture.loginWrites.isEmpty) + let host = NSHostingView(rootView: TourView(controller: learning).environment(\.colorScheme, colorScheme)) + host.appearance = NSAppearance(named: colorScheme == .light ? .aqua : .darkAqua) + host.sizingOptions = [.preferredContentSize, .intrinsicContentSize] + host.frame = CGRect(x: 0, y: 0, width: 440, height: 1) + for _ in 0..<3 { + host.layoutSubtreeIfNeeded() + host.frame.size = host.fittingSize + } + #expect(host.bounds.width == 440) + #expect(host.bounds.height < 800) + let bitmap = try #require(host.bitmapImageRepForCachingDisplay(in: host.bounds)) + host.cacheDisplay(in: host.bounds, to: bitmap) + try assertNoLargeEmptyRegions(bitmap) + if let path = ProcessInfo.processInfo.environment["PARCEL_TOUR_QA_DIR"] { + try #require(path.hasPrefix("/")) + let appearance = colorScheme == .light ? "light" : "dark" + let state = permission == .granted ? "allowed" : "missing" + let name = "02-allow-\(appearance)-voiceOver-\(state).png" + let png = try #require(bitmap.representation(using: .png, properties: [:])) + try png.write(to: URL(fileURLWithPath: path).appendingPathComponent(name), options: .atomic) + } + } + @Test( arguments: TourSetupStep.allCases, [ diff --git a/Tests/ParcelUITests/Tour/WindowLearningControllerTests.swift b/Tests/ParcelUITests/Tour/WindowLearningControllerTests.swift index fd07bd82..0d393558 100644 --- a/Tests/ParcelUITests/Tour/WindowLearningControllerTests.swift +++ b/Tests/ParcelUITests/Tour/WindowLearningControllerTests.swift @@ -212,13 +212,19 @@ extension AppKitTestSuite.WindowLearningControllerTests { let controller = try make(defaults) defer { controller.stop() } let host = NSHostingView(rootView: TourView(controller: controller)) - host.frame = CGRect(x: 0, y: 0, width: 440, height: 400) + host.sizingOptions = [.preferredContentSize, .intrinsicContentSize] + host.frame = CGRect(x: 0, y: 0, width: 440, height: 1) + host.layoutSubtreeIfNeeded() + let fittingSize = host.fittingSize + #expect(fittingSize.width == 440) + #expect(fittingSize.height > 150 && fittingSize.height < 600) + host.frame.size = fittingSize host.layoutSubtreeIfNeeded() let bitmap = try #require(host.bitmapImageRepForCachingDisplay(in: host.bounds)) host.cacheDisplay(in: host.bounds, to: bitmap) #expect(bitmap.tiffRepresentation?.isEmpty == false) #expect(bitmap.pixelsWide >= 440) - #expect(bitmap.pixelsHigh >= 400) + #expect(bitmap.pixelsHigh >= Int(fittingSize.height)) } } -- knotmirror 0.0.1