From 6dbbd6383e409386169ecc09899bedba8b789e73 Mon Sep 17 00:00:00 2001 From: tydude001 <291262504+tydude001@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:51:09 -0600 Subject: [PATCH] Single instance: docs for the CPU relaunch, instance.json cleanup and the 0600 lock (#6654 review) docs/development.md's single-instance paragraph now says that the CPU-compatibility relaunch's own --safe-gpu doesn't keep it out of single-instance, that the primary removes its instance.json (while it still names this process) before freeing the lock, and that instance.lock is 0600 on Unix (the settings folder 0700 when single-instance creates it). Docs only. cargo xtask ci (Fedora 44 toolbox, x86_64): fmt, clippy, layers, scorecard, panic_hunt, doctest and wasm pass. In test, three tests fail in crates this branch doesn't change: photocraft-automation's dropping_a_waited_command_cancels_its_job and photocraft-gpu's a_refresh_that_submits_several_times_is_one_measurement (both also failed on main 2ff8f419c), and photocraft-ui-egui's opening_a_document_changes_state_not_structure, which fails in 2 of 3 full runs of that binary and passes on its own. --- docs/development.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/development.md b/docs/development.md index 18a7610ee08..901bf817d6e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -134,7 +134,7 @@ CRAFT_FONTS_DIR="$PWD/../craft-fonts" cargo test --workspace # runs the Japa ## One instance per user -On Windows and Linux the first PhotoCraft holds an exclusive lock on `instance.lock` in the config directory and listens on a loopback port named in `instance.json` (with a fresh 256-bit token; the file is 0600 on Unix). Inside a Flatpak it listens on a Unix socket instead, `$XDG_RUNTIME_DIR/app//instance.sock` (0600), because Flatpak isolates each sandbox's network namespace, loopback included, unless the app is granted `--share=network`, while that runtime directory is shared by all sandboxes of the app (#1540); the lock, token and protocol are the same. A later launch hands its file arguments there and exits, so files opened from Explorer or a file manager become tabs in the running window (#3708). The primary answers `ok` only once its UI has taken the files; a launch that gets anything else (the primary is starting, hung or closing) keeps retrying the lock for up to 10 s, becoming the primary itself once the old one lets go, and then starts a separate instance, so a file is never acknowledged and lost. When the event loop ends (and before the CPU-compatibility relaunch) the primary refuses new files and frees the lock. It applies only with the per-user settings folder: a portable copy (`PhotoCraftData` beside the executable) or `PHOTOCRAFT_CONFIG_DIR` may be shared between users, so those launches run separately. So do `--new-instance` (or `PHOTOCRAFT_NEW_INSTANCE=1`), every `--control` launch, and launches given a per-process option (`--safe-gpu`, `--present-mode`, `--frame-latency`, `--stroke-trace`, `--in-window-menus`, `--automation-*-root`). A `cargo run` while an installed PhotoCraft is running forwards to it: pass `--new-instance` or set `PHOTOCRAFT_CONFIG_DIR`. macOS gets the same behaviour from LaunchServices (`apple_events.rs`). On native Wayland the running window can't bring itself forward (that takes the launcher's `XDG_ACTIVATION_TOKEN`, and winit 0.30 can't activate an existing window with one), so it asks for attention instead and the taskbar highlights it; X11, XWayland and Windows bring it to the front. Code: `apps/photocraft/src/single_instance.rs`. +On Windows and Linux the first PhotoCraft holds an exclusive lock on `instance.lock` in the config directory (0600 on Unix, narrowed on the next start if an earlier version left it readable; the directory is 0700 when single-instance creates it) and listens on a loopback port named in `instance.json` (with a fresh 256-bit token; the file is 0600 on Unix). Inside a Flatpak it listens on a Unix socket instead, `$XDG_RUNTIME_DIR/app//instance.sock` (0600), because Flatpak isolates each sandbox's network namespace, loopback included, unless the app is granted `--share=network`, while that runtime directory is shared by all sandboxes of the app (#1540); the lock, token and protocol are the same. A later launch hands its file arguments there and exits, so files opened from Explorer or a file manager become tabs in the running window (#3708). The primary answers `ok` only once its UI has taken the files; a launch that gets anything else (the primary is starting, hung or closing) keeps retrying the lock for up to 10 s, becoming the primary itself once the old one lets go, and then starts a separate instance, so a file is never acknowledged and lost. When the event loop ends (and before the CPU-compatibility relaunch) the primary refuses new files, removes its `instance.json` (only while it still names this process) and then frees the lock. It applies only with the per-user settings folder: a portable copy (`PhotoCraftData` beside the executable) or `PHOTOCRAFT_CONFIG_DIR` may be shared between users, so those launches run separately. So do `--new-instance` (or `PHOTOCRAFT_NEW_INSTANCE=1`), every `--control` launch, and launches given a per-process option (`--safe-gpu`, `--present-mode`, `--frame-latency`, `--stroke-trace`, `--in-window-menus`, `--automation-*-root`). The CPU-compatibility relaunch is the exception: the `--safe-gpu` it adds itself (it also sets `PHOTOCRAFT_GPU_STARTUP_FAILURE`) doesn't count, so the relaunch takes over as the primary from the launch that failed; a `--safe-gpu` a person passes still runs separately. A `cargo run` while an installed PhotoCraft is running forwards to it: pass `--new-instance` or set `PHOTOCRAFT_CONFIG_DIR`. macOS gets the same behaviour from LaunchServices (`apple_events.rs`). On native Wayland the running window can't bring itself forward (that takes the launcher's `XDG_ACTIVATION_TOKEN`, and winit 0.30 can't activate an existing window with one), so it asks for attention instead and the taskbar highlights it; X11, XWayland and Windows bring it to the front. Code: `apps/photocraft/src/single_instance.rs`. ## Graphics startup and device loss