From c84b80b24f588232fe8ee40c2643f651e1f20096 Mon Sep 17 00:00:00 2001 From: maridogolpeador <354308468+maridogolpeador@users.noreply.github.com> Date: Wed, 25 Nov 2026 02:15:45 -0300 Subject: [PATCH] app: route Command-O to the focused window's importer (#252) Review follow-up. The command set a shared Boolean, so with every window closed there was no importer to present it, and with several windows each one bound the same flag. Each ContentView now owns its importer state and publishes an open action with focusedSceneValue; OpenExecutableCommand reads it with @FocusedValue, calls it for the focused window and is disabled when no window provides it. The inspector button uses the same per-window action. InspectionModel no longer holds the importer flag; requestImport only clears the previous selection error. Signed-off-by: maridogolpeador <354308468+maridogolpeador@users.noreply.github.com> --- CHANGELOG.md | 2 +- app/Sources/Xenora/main.swift | 55 ++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaa4633..afc7a26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game remains unsupported. ### Added -- Added File > Open Executable… with Command-O to the app (#252). It opens the same read-only file importer as the inspector's button, and the chosen file goes through the same inspection path as the button, drag and drop and Finder Open With; nothing is executed. A file-importer failure is now shown in red with the system's description instead of being ignored, a cancelled picker shows nothing, and the message clears on the next selection. `BetterXen --smoke-import-result`, run by `scripts/build-app.sh`, checks cancellation, a shown failure and its clearing; it fails on the previous importer handling. Checked locally on Apple Silicon in the running app (Command-O and the menu item open the picker, cancel shows no error, a second Command-O opens it again); not yet independently reviewed. +- Added File > Open Executable… with Command-O to the app (#252). It opens the focused window's read-only file importer, the same one as that window's button, and is disabled when no window can present it; each window keeps its own importer, so with several windows only the focused one shows the picker. The chosen file goes through the same inspection path as the button, drag and drop and Finder Open With; nothing is executed. A file-importer failure is now shown in red with the system's description instead of being ignored, a cancelled picker shows nothing, and the message clears on the next selection. `BetterXen --smoke-import-result`, run by `scripts/build-app.sh`, checks cancellation, a shown failure and its clearing; it fails on the previous importer handling. Checked locally on Apple Silicon in the running app (Command-O and the menu item open the picker, cancel shows no error, a second Command-O opens it again, with two windows only the focused one presents it, and with every window closed the menu item is disabled); not yet independently reviewed. - Rewrote the README around the six development phases and the first-launchable-application target (#311), with colour-coded Mermaid diagrams (system flow, milestone roadmap, CPU, runtime-service and shader-form charts built from the generated registries), badges, a repository overview, a contributing section and corrected texture-sampling wording. The older X1–X25 capability map is kept in a collapsible section. The diagrams were not render-tested locally. - Added a fast "Repository hygiene" check (`.github/workflows/hygiene.yml`, `scripts/audit/docs_hygiene.py`). It runs on Ubuntu without a Rust toolchain or network access and fails only on merge-conflict markers, broken relative Markdown links and invalid workflow YAML in tracked files. A separate advisory step warns, without failing, when source or script changes have no changelog entry. A local run over the 626 tracked files found no problems, and planted failures of each kind were caught; it has not yet run on GitHub. diff --git a/app/Sources/Xenora/main.swift b/app/Sources/Xenora/main.swift index 1206e27..ccaf0d4 100644 --- a/app/Sources/Xenora/main.swift +++ b/app/Sources/Xenora/main.swift @@ -638,14 +638,13 @@ final class InspectionModel: ObservableObject { @Published var report = "" @Published var status: Int32 = Int32(XENORA_OK) @Published var busy = false - @Published var importing = false /// Why the last file selection could not be used, shown until the next selection. @Published var selectionError: String? - /// Shows the read-only file importer, from the button or File > Open Executable…. + /// Called when a window is about to show the read-only file importer, from its + /// button or File > Open Executable…. Each window presents its own importer. func requestImport() { selectionError = nil - importing = true } /// Handles the importer's completion. A cancelled picker is not a failure. @@ -707,13 +706,40 @@ final class AppDelegate: NSObject, NSApplicationDelegate { } } +/// Opens the file importer of the focused window. Absent when no window can +/// present it, which disables File > Open Executable…. +struct OpenExecutableKey: FocusedValueKey { + typealias Value = () -> Void +} + +extension FocusedValues { + var openExecutable: OpenExecutableKey.Value? { + get { self[OpenExecutableKey.self] } + set { self[OpenExecutableKey.self] = newValue } + } +} + +/// File > Open Executable… (Command-O), routed to the focused window's importer. +struct OpenExecutableCommand: Commands { + @FocusedValue(\.openExecutable) private var openExecutable + + var body: some Commands { + CommandGroup(after: .newItem) { + Button("Open Executable…") { openExecutable?() } + .keyboardShortcut("o") + .disabled(openExecutable == nil) + } + } +} + struct InspectorView: View { @ObservedObject var model: InspectionModel + let openImporter: () -> Void var body: some View { Section("Executable inspection (read-only)") { HStack { - Button("Open Executable…") { model.requestImport() } + Button("Open Executable…") { openImporter() } Text("or drop a file on this window").foregroundStyle(.secondary) } if let error = model.selectionError { @@ -741,12 +767,19 @@ struct ContentView: View { @ObservedObject var model: FrameModel @ObservedObject var loop: FrameLoopModel @ObservedObject var inspection = InspectionModel.shared + /// This window's importer. Kept per window so only the window that asked shows it. + @State private var importing = false private var frame: GuestFrame? { model.frame } private var running: Bool { model.running } + private func openImporter() { + inspection.requestImport() + importing = true + } + var body: some View { Form { - InspectorView(model: inspection) + InspectorView(model: inspection, openImporter: openImporter) Section("Guest display") { if let image = frame?.image { Image(decorative: image, scale: 1) @@ -847,7 +880,7 @@ struct ContentView: View { .foregroundStyle(.secondary) } .formStyle(.grouped) - .fileImporter(isPresented: $inspection.importing, allowedContentTypes: [.item]) { result in + .fileImporter(isPresented: $importing, allowedContentTypes: [.item]) { result in inspection.importFinished(result) } .dropDestination(for: URL.self) { urls, _ in @@ -856,6 +889,7 @@ struct ContentView: View { return true } .frame(minWidth: 520, minHeight: 680) + .focusedSceneValue(\.openExecutable, openImporter) } } @@ -866,12 +900,7 @@ struct BetterXenApp: App { var body: some Scene { WindowGroup("BetterXen") { ContentView(model: model, loop: loop) } - .commands { - CommandGroup(after: .newItem) { - Button("Open Executable…") { InspectionModel.shared.requestImport() } - .keyboardShortcut("o") - } - } + .commands { OpenExecutableCommand() } } } @@ -1052,7 +1081,7 @@ if CommandLine.arguments.contains("--smoke-import-result") { model.importFinished(.failure(CocoaError(.fileReadNoPermission))) if model.selectionError == nil || model.fileName != nil { failures.append("failure is not shown") } model.requestImport() - if model.selectionError != nil || !model.importing { failures.append("reopening keeps the old message") } + if model.selectionError != nil { failures.append("reopening keeps the old message") } model.importFinished(.failure(CocoaError(.fileReadNoPermission))) model.inspect(URL(fileURLWithPath: "/nonexistent/import-result-check")) if model.selectionError != nil || model.fileName != "import-result-check" {