diff --git a/Cargo.lock b/Cargo.lock index eac70b2..f2093c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3179,6 +3179,7 @@ dependencies = [ "tauri-plugin-clipboard-manager", "tauri-plugin-dialog", "tauri-plugin-opener", + "tauri-plugin-single-instance", "tokio", "tokio-util", "tracing", @@ -4693,6 +4694,22 @@ dependencies = [ "zbus", ] +[[package]] +name = "tauri-plugin-single-instance" +version = "2.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3214becf9ef5783c0ae99a3bb25adf5353a7a16ebf53e74b909e29205735c6c" +dependencies = [ + "serde", + "serde_json", + "tauri", + "thiserror 2.0.19", + "tokio", + "tracing", + "windows-sys 0.60.2", + "zbus", +] + [[package]] name = "tauri-runtime" version = "2.11.3" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 42e18ab..926de4b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -34,6 +34,10 @@ tokio = { version = "1", features = ["rt-multi-thread"] } # `plan_cancel` trips the same `CancellationToken` the core threads through `exec`. tokio-util = "0.7" tracing = "0.1" +# One window, always. Launching PipDock again focuses the window that exists rather than opening +# a second one — two of them would be two `Sessions` slots over one set of environments, each +# certain it owned the mutation in flight. +tauri-plugin-single-instance = "2.4.3" tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dev-dependencies] diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 258587f..a8536cf 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -36,6 +36,21 @@ pub fn run() { use tauri::Manager as _; tauri::Builder::default() + // **First, before every other plugin.** The single-instance handler has to be registered + // before anything that could take a lock or open the store, because a second launch runs + // this far and then hands off — and the reason it must hand off at all is that two windows + // would be two `AppState`s over one machine: two `Sessions` slots, each certain it owned + // the mutation in flight, and two `PD-RES-003` guards that cannot see each other. + .plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { + // Focus the window that already exists. Restoring first matters: a minimized window + // that is only focused stays minimized, and the user sees their second launch do + // nothing at all. + if let Some(window) = app.get_webview_window("main") { + let _ = window.unminimize(); + let _ = window.show(); + let _ = window.set_focus(); + } + })) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_clipboard_manager::init()) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 89f1199..6a9b219 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -17,7 +17,11 @@ "height": 760, "minWidth": 900, "minHeight": 560, + "maxWidth": 1600, + "maxHeight": 1100, "resizable": true, + "maximizable": false, + "fullscreen": false, "theme": "Dark" } ], diff --git a/ui/src/components/PdSidebar.tsx b/ui/src/components/PdSidebar.tsx index b52a7ce..80a15d4 100644 --- a/ui/src/components/PdSidebar.tsx +++ b/ui/src/components/PdSidebar.tsx @@ -1,7 +1,7 @@ import { useTranslation } from 'react-i18next' import { NAV_KEYS, type NavKey } from '@/components/nav' -import { useEnvStore, useUiStore } from '@/stores' +import { PANEL_PHASES, useEnvStore, usePlanStore, useUiStore } from '@/stores' /** Tabs whose screens land in a later milestone. Kept in place, not hidden. */ const NOT_YET: readonly NavKey[] = ['security'] @@ -12,6 +12,12 @@ const NOT_YET: readonly NavKey[] = ['security'] * `Ctrl+1..8` maps to `NAV_KEYS` positionally, which is why that order is load-bearing. Tabs * without a screen yet stay in place and stay focusable rather than being hidden: hiding them * would renumber every shortcut after them, and the user would relearn the map twice. + * + * **Every tab is disabled while a plan owns the content area.** `PdPlanPanel` replaces `
` + * for the whole of a preview, an execution and its summary; navigating away left the plan parked + * in Rust with nothing on screen driving it, and the user's next Update answered `PD-RES-003` + * about a plan they could no longer see. `App.tsx` already refuses `Ctrl+1..8` while the guard + * dialog is open, for the same reason — this is that rule applied to the panel and to the mouse. */ export function PdSidebar() { const { t } = useTranslation() @@ -19,6 +25,8 @@ export function PdSidebar() { const setNav = useUiStore((s) => s.setNav) // UI-SPEC §3's layout sketch shows `Updates (7)`. A primitive, so this selector is stable. const updatesCount = useEnvStore((s) => s.updatesCount) + // A boolean rather than the phase, so an unrelated phase change does not re-render the sidebar. + const planBusy = usePlanStore((s) => PANEL_PHASES.has(s.phase)) return (