From a465fd2b1c9a1dd3867c8499168553c4796fae5d Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 17 Oct 2026 19:06:54 -0700 Subject: [PATCH 1/5] A second launch that sets only environment overrides keeps its own process PHOTOCRAFT_PRESENT_MODE, PHOTOCRAFT_FRAME_LATENCY, PHOTOCRAFT_STROKE_TRACE, PHOTOCRAFT_IN_WINDOW_MENUS and the two automation roots are documented as the equivalent of the per-launch flags, and a per-launch flag makes a launch keep its own process. A launch that sets only variables left launch_options empty, so it handed its files to the running instance (or merely raised its window) and exited before any override was read. Those variables now count as the flags they stand for; empty and 0 mean off, as with PHOTOCRAFT_NEW_INSTANCE. Test: each variable maps to its flag, a value that means off maps to nothing, and skip_reason names the flag. --- apps/photocraft/src/main.rs | 4 ++ apps/photocraft/src/single_instance.rs | 53 +++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/apps/photocraft/src/main.rs b/apps/photocraft/src/main.rs index 05355e55bf..8d51aa651f 100644 --- a/apps/photocraft/src/main.rs +++ b/apps/photocraft/src/main.rs @@ -369,6 +369,10 @@ fn main() -> eframe::Result { #[cfg(not(target_os = "macos"))] let single_instance = { let new_instance_env = std::env::var("PHOTOCRAFT_NEW_INSTANCE").ok(); + // A variable documented as the equivalent of a per-launch flag counts as that flag: a + // launch that sets only `PHOTOCRAFT_PRESENT_MODE` (say) has per-process options too, so it + // keeps its own process instead of handing its files over and being ignored. + launch_options.extend_from_slice(&single_instance::env_launch_options()); let context = single_instance::LaunchContext { per_user_settings: app_dirs::current().mode == app_dirs::Mode::Platform, new_instance_flag: new_instance, diff --git a/apps/photocraft/src/single_instance.rs b/apps/photocraft/src/single_instance.rs index d2cd65c678..d607e231e0 100644 --- a/apps/photocraft/src/single_instance.rs +++ b/apps/photocraft/src/single_instance.rs @@ -82,10 +82,35 @@ pub struct LaunchContext<'a> { pub control: bool, /// Paths that aren't valid Unicode: this launch reports them. pub unreadable_paths: bool, - /// Options that only apply to the process they're given to (`--safe-gpu`, …). + /// Options that only apply to the process they're given to (`--safe-gpu`, …), including the + /// ones this launch's environment sets (see [`env_launch_options`]). pub launch_options: &'a [&'static str], } +/// Variables documented as the equivalent of a per-launch flag, each with the flag it stands for +/// (`PHOTOCRAFT_PRESENT_MODE` is `--present-mode`). Setting one asks for the same thing as giving +/// the flag, so it belongs to this process alone. +const ENV_LAUNCH_OPTIONS: [(&str, &str); 6] = [ + ("PHOTOCRAFT_PRESENT_MODE", "--present-mode"), + ("PHOTOCRAFT_FRAME_LATENCY", "--frame-latency"), + ("PHOTOCRAFT_STROKE_TRACE", "--stroke-trace"), + ("PHOTOCRAFT_IN_WINDOW_MENUS", "--in-window-menus"), + ("PHOTOCRAFT_AUTOMATION_READ_ROOT", "--automation-read-root"), + ("PHOTOCRAFT_AUTOMATION_WRITE_ROOT", "--automation-write-root"), +]; + +/// The per-process options this launch's environment sets, named as the flags they stand for. A +/// launch that sets only variables would otherwise hand its files to the running instance, which +/// never sees the override, and exit. Empty and `0` mean off, as with `PHOTOCRAFT_NEW_INSTANCE`. +pub fn env_launch_options() -> Vec<&'static str> { + env_launch_options_from(|name| std::env::var_os(name)) +} + +/// [`env_launch_options`] with the reader given, so the rule is testable without the environment. +fn env_launch_options_from(get: impl Fn(&str) -> Option) -> Vec<&'static str> { + ENV_LAUNCH_OPTIONS.iter().filter(|(name, _)| get(name).is_some_and(|v| !v.is_empty() && v != "0")).map(|(_, flag)| *flag).collect() +} + /// Why this launch runs as its own instance, or `None` to take part in single-instance. pub fn skip_reason(c: &LaunchContext) -> Option { if !c.per_user_settings { @@ -645,4 +670,30 @@ mod tests { let reason = skip_reason(&LaunchContext { launch_options: &["--safe-gpu"], ..base }); assert!(reason.is_some_and(|r| r.contains("--safe-gpu"))); } + + /// A variable documented as the equivalent of a per-launch flag counts as that flag: a launch + /// that sets only variables has per-process options, so it keeps its own process rather than + /// handing its files to the running instance, which never sees the override. + #[test] + fn an_environment_override_counts_as_a_process_option() { + let with = |values: &[(&str, &str)]| env_launch_options_from(|n| values.iter().find(|(k, _)| *k == n).map(|(_, v)| (*v).into())); + assert_eq!(with(&[("PHOTOCRAFT_PRESENT_MODE", "novsync")]), vec!["--present-mode"]); + assert_eq!( + with(&[("PHOTOCRAFT_STROKE_TRACE", "strokes.csv"), ("PHOTOCRAFT_AUTOMATION_WRITE_ROOT", "/tmp/out")]), + vec!["--stroke-trace", "--automation-write-root"] + ); + // Nothing set, or a value that means off (`0`, empty), is an ordinary launch. + assert!(with(&[]).is_empty()); + assert!(with(&[("PHOTOCRAFT_IN_WINDOW_MENUS", "0"), ("PHOTOCRAFT_FRAME_LATENCY", "")]).is_empty()); + let base = LaunchContext { + per_user_settings: true, + new_instance_flag: false, + new_instance_env: None, + control: false, + unreadable_paths: false, + launch_options: &[], + }; + let reason = skip_reason(&LaunchContext { launch_options: &with(&[("PHOTOCRAFT_PRESENT_MODE", "novsync")]), ..base }); + assert!(reason.as_deref().is_some_and(|r| r.contains("--present-mode")), "{reason:?}"); + } } From b5fb2fde62138023becdd6b685f389da3f6cacd3 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 17 Oct 2026 20:07:00 -0700 Subject: [PATCH 2/5] single_instance: each environment override is off the way it is read --- apps/photocraft/src/single_instance.rs | 67 +++++++++++++++++++++----- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/apps/photocraft/src/single_instance.rs b/apps/photocraft/src/single_instance.rs index d607e231e0..a42c2120fd 100644 --- a/apps/photocraft/src/single_instance.rs +++ b/apps/photocraft/src/single_instance.rs @@ -88,27 +88,61 @@ pub struct LaunchContext<'a> { } /// Variables documented as the equivalent of a per-launch flag, each with the flag it stands for -/// (`PHOTOCRAFT_PRESENT_MODE` is `--present-mode`). Setting one asks for the same thing as giving -/// the flag, so it belongs to this process alone. -const ENV_LAUNCH_OPTIONS: [(&str, &str); 6] = [ - ("PHOTOCRAFT_PRESENT_MODE", "--present-mode"), - ("PHOTOCRAFT_FRAME_LATENCY", "--frame-latency"), - ("PHOTOCRAFT_STROKE_TRACE", "--stroke-trace"), - ("PHOTOCRAFT_IN_WINDOW_MENUS", "--in-window-menus"), - ("PHOTOCRAFT_AUTOMATION_READ_ROOT", "--automation-read-root"), - ("PHOTOCRAFT_AUTOMATION_WRITE_ROOT", "--automation-write-root"), +/// (`PHOTOCRAFT_PRESENT_MODE` is `--present-mode`) and the rule that says whether its value asks for +/// that option at all. Setting one asks for the same thing as giving the flag, so it belongs to this +/// process alone. +const ENV_LAUNCH_OPTIONS: [(&str, &str, ValueRule); 6] = [ + ("PHOTOCRAFT_PRESENT_MODE", "--present-mode", present_mode_is_on), + ("PHOTOCRAFT_FRAME_LATENCY", "--frame-latency", frame_latency_is_on), + ("PHOTOCRAFT_STROKE_TRACE", "--stroke-trace", stroke_trace_is_on), + ("PHOTOCRAFT_IN_WINDOW_MENUS", "--in-window-menus", flag_is_on), + ("PHOTOCRAFT_AUTOMATION_READ_ROOT", "--automation-read-root", path_is_set), + ("PHOTOCRAFT_AUTOMATION_WRITE_ROOT", "--automation-write-root", path_is_set), ]; +/// Whether a variable's value asks this launch for its own option. Each rule matches how that +/// variable is read where it takes effect, so a value ignored there keeps no process here either. +type ValueRule = fn(&str) -> bool; + +/// A value `presentation::parse` accepts: it warns and ignores the rest, so an unrecognised +/// `PHOTOCRAFT_PRESENT_MODE` changes nothing and so needs no process of its own. +fn present_mode_is_on(value: &str) -> bool { + !value.trim().is_empty() && crate::presentation::parse(Some(value.trim()), None).0.mode.is_some() +} + +/// [`present_mode_is_on`] for `PHOTOCRAFT_FRAME_LATENCY`, which takes `1` to `3`. +fn frame_latency_is_on(value: &str) -> bool { + !value.trim().is_empty() && crate::presentation::parse(None, Some(value.trim())).0.latency.is_some() +} + +/// Anything except `""`, `0`, `off` and `false`, which is how `StrokeTrace::from_value` reads it: the +/// rest is a stderr summary or a CSV path. +fn stroke_trace_is_on(value: &str) -> bool { + !matches!(value.trim(), "" | "0" | "off" | "false") +} + +/// Any value except empty and `0`, as `main.rs` reads `PHOTOCRAFT_IN_WINDOW_MENUS` - which is why +/// `off` means on there, and why this rule is not shared with the stroke trace above. +fn flag_is_on(value: &str) -> bool { + let value = value.trim(); + !value.is_empty() && value != "0" +} + +/// A path is an option; an empty value is no path. Not trimmed: a path may end in a space. +fn path_is_set(value: &str) -> bool { + !value.is_empty() +} + /// The per-process options this launch's environment sets, named as the flags they stand for. A /// launch that sets only variables would otherwise hand its files to the running instance, which -/// never sees the override, and exit. Empty and `0` mean off, as with `PHOTOCRAFT_NEW_INSTANCE`. +/// never sees the override, and exit. pub fn env_launch_options() -> Vec<&'static str> { env_launch_options_from(|name| std::env::var_os(name)) } /// [`env_launch_options`] with the reader given, so the rule is testable without the environment. fn env_launch_options_from(get: impl Fn(&str) -> Option) -> Vec<&'static str> { - ENV_LAUNCH_OPTIONS.iter().filter(|(name, _)| get(name).is_some_and(|v| !v.is_empty() && v != "0")).map(|(_, flag)| *flag).collect() + ENV_LAUNCH_OPTIONS.iter().filter(|(name, _, is_on)| get(name).is_some_and(|v| is_on(&v.to_string_lossy()))).map(|(_, flag, _)| *flag).collect() } /// Why this launch runs as its own instance, or `None` to take part in single-instance. @@ -682,9 +716,18 @@ mod tests { with(&[("PHOTOCRAFT_STROKE_TRACE", "strokes.csv"), ("PHOTOCRAFT_AUTOMATION_WRITE_ROOT", "/tmp/out")]), vec!["--stroke-trace", "--automation-write-root"] ); - // Nothing set, or a value that means off (`0`, empty), is an ordinary launch. + // Nothing set, or a value that means off, is an ordinary launch. Each variable is off the way + // it is read where it takes effect, not by one rule shared across all six. assert!(with(&[]).is_empty()); assert!(with(&[("PHOTOCRAFT_IN_WINDOW_MENUS", "0"), ("PHOTOCRAFT_FRAME_LATENCY", "")]).is_empty()); + // The trace is off at `off` and `false` as well, and a value the presentation parser rejects + // is ignored there, so neither keeps a process of its own here. + assert!(with(&[("PHOTOCRAFT_STROKE_TRACE", "off"), ("PHOTOCRAFT_PRESENT_MODE", "maybe"), ("PHOTOCRAFT_FRAME_LATENCY", "4")]).is_empty()); + assert!(with(&[("PHOTOCRAFT_AUTOMATION_READ_ROOT", "")]).is_empty()); + // Spaces are not part of a value, except in a path, where they can be. + assert_eq!(with(&[("PHOTOCRAFT_PRESENT_MODE", " novsync "), ("PHOTOCRAFT_STROKE_TRACE", " 1 ")]), vec!["--present-mode", "--stroke-trace"]); + // `PHOTOCRAFT_IN_WINDOW_MENUS=off` means menus in the window there, so it means it here too. + assert_eq!(with(&[("PHOTOCRAFT_IN_WINDOW_MENUS", "off")]), vec!["--in-window-menus"]); let base = LaunchContext { per_user_settings: true, new_instance_flag: false, From d3d1506e13e37fd363304a5fa4f2337dbfe7770d Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 17 Oct 2026 20:16:25 -0700 Subject: [PATCH 3/5] single_instance: the menu override is on and off exactly as main.rs reads it --- apps/photocraft/src/single_instance.rs | 29 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/photocraft/src/single_instance.rs b/apps/photocraft/src/single_instance.rs index a42c2120fd..ad893bd58a 100644 --- a/apps/photocraft/src/single_instance.rs +++ b/apps/photocraft/src/single_instance.rs @@ -104,31 +104,33 @@ const ENV_LAUNCH_OPTIONS: [(&str, &str, ValueRule); 6] = [ /// variable is read where it takes effect, so a value ignored there keeps no process here either. type ValueRule = fn(&str) -> bool; -/// A value `presentation::parse` accepts: it warns and ignores the rest, so an unrecognised -/// `PHOTOCRAFT_PRESENT_MODE` changes nothing and so needs no process of its own. +/// A value `presentation::parse` accepts, handed over as written: it trims, treats empty as unset and +/// warns and ignores anything it does not recognise, so an unrecognised `PHOTOCRAFT_PRESENT_MODE` +/// changes nothing there and so needs no process of its own here. fn present_mode_is_on(value: &str) -> bool { - !value.trim().is_empty() && crate::presentation::parse(Some(value.trim()), None).0.mode.is_some() + crate::presentation::parse(Some(value), None).0.mode.is_some() } /// [`present_mode_is_on`] for `PHOTOCRAFT_FRAME_LATENCY`, which takes `1` to `3`. fn frame_latency_is_on(value: &str) -> bool { - !value.trim().is_empty() && crate::presentation::parse(None, Some(value.trim())).0.latency.is_some() + crate::presentation::parse(None, Some(value)).0.latency.is_some() } /// Anything except `""`, `0`, `off` and `false`, which is how `StrokeTrace::from_value` reads it: the -/// rest is a stderr summary or a CSV path. +/// rest is a stderr summary or a CSV path. It trims, so `" 0 "` is off there and off here. fn stroke_trace_is_on(value: &str) -> bool { !matches!(value.trim(), "" | "0" | "off" | "false") } -/// Any value except empty and `0`, as `main.rs` reads `PHOTOCRAFT_IN_WINDOW_MENUS` - which is why -/// `off` means on there, and why this rule is not shared with the stroke trace above. +/// Any value except empty and exactly `0`, as `main.rs` reads `PHOTOCRAFT_IN_WINDOW_MENUS` - which is +/// why `off` means on there, why this rule is not shared with the stroke trace above, and why it does +/// not trim: a padded `" 0 "` enables the menus there, so it keeps a process here too. fn flag_is_on(value: &str) -> bool { - let value = value.trim(); !value.is_empty() && value != "0" } -/// A path is an option; an empty value is no path. Not trimmed: a path may end in a space. +/// A path is an option; an empty value is no path. Not trimmed: a path may end in a space. An empty +/// root is read as no root unless `--control` is given, and that flag keeps its own process already. fn path_is_set(value: &str) -> bool { !value.is_empty() } @@ -724,8 +726,15 @@ mod tests { // is ignored there, so neither keeps a process of its own here. assert!(with(&[("PHOTOCRAFT_STROKE_TRACE", "off"), ("PHOTOCRAFT_PRESENT_MODE", "maybe"), ("PHOTOCRAFT_FRAME_LATENCY", "4")]).is_empty()); assert!(with(&[("PHOTOCRAFT_AUTOMATION_READ_ROOT", "")]).is_empty()); - // Spaces are not part of a value, except in a path, where they can be. + // Spaces are part of the value only where the reader keeps them: the trace and the two + // presentation values are trimmed where they take effect, the menu flag and a path are not. assert_eq!(with(&[("PHOTOCRAFT_PRESENT_MODE", " novsync "), ("PHOTOCRAFT_STROKE_TRACE", " 1 ")]), vec!["--present-mode", "--stroke-trace"]); + assert_eq!( + with(&[("PHOTOCRAFT_IN_WINDOW_MENUS", " 0 "), ("PHOTOCRAFT_AUTOMATION_WRITE_ROOT", " /tmp/out ")]), + vec!["--in-window-menus", "--automation-write-root"] + ); + // A whitespace-only menu value is not empty, so it enables the menus there and here too. + assert_eq!(with(&[("PHOTOCRAFT_IN_WINDOW_MENUS", " ")]), vec!["--in-window-menus"]); // `PHOTOCRAFT_IN_WINDOW_MENUS=off` means menus in the window there, so it means it here too. assert_eq!(with(&[("PHOTOCRAFT_IN_WINDOW_MENUS", "off")]), vec!["--in-window-menus"]); let base = LaunchContext { From a1c9743eacbeb28a10ecac71f5eb9d00907452b1 Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 18 Oct 2026 13:09:47 -0700 Subject: [PATCH 4/5] launch args: the environment overrides fold into launch_options again #6499 moved the argument parsing into parse_launch_args, and main() now destructures the result without mut, so the line that folds the PHOTOCRAFT_* overrides into launch_options fails with E0596. One mut on that field; nothing else in the change moves. --- apps/photocraft/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/photocraft/src/main.rs b/apps/photocraft/src/main.rs index 8796620d58..d4f47c1b39 100644 --- a/apps/photocraft/src/main.rs +++ b/apps/photocraft/src/main.rs @@ -496,7 +496,7 @@ fn main() -> eframe::Result { unreadable_paths, safe_gpu, new_instance, - launch_options, + mut launch_options, present_mode_arg, frame_latency_arg, stroke_trace_arg, From 84df1468d89fe9ad4a15e5596eeb41a376ac8217 Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 18 Oct 2026 13:55:31 -0700 Subject: [PATCH 5/5] launch args: keep the `mut` off macOS builds CodeRabbit on #7242: the LaunchArgs destructuring asked for a mutable launch_options, but the only mutation happens inside the cfg(not(target_os = "macos")) block, so a macOS build warns about an unused mut. The binding is made mutable inside that block instead, where the fold happens. No behaviour change on any platform; upstream CI has no macOS leg, so this is warning hygiene, not a CI fix. --- apps/photocraft/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/photocraft/src/main.rs b/apps/photocraft/src/main.rs index d4f47c1b39..4a9a11b9d0 100644 --- a/apps/photocraft/src/main.rs +++ b/apps/photocraft/src/main.rs @@ -496,7 +496,7 @@ fn main() -> eframe::Result { unreadable_paths, safe_gpu, new_instance, - mut launch_options, + launch_options, present_mode_arg, frame_latency_arg, stroke_trace_arg, @@ -525,6 +525,9 @@ fn main() -> eframe::Result { // A variable documented as the equivalent of a per-launch flag counts as that flag: a // launch that sets only `PHOTOCRAFT_PRESENT_MODE` (say) has per-process options too, so it // keeps its own process instead of handing its files over and being ignored. + // Folded in here, inside the block that only non-macOS builds compile, so the binding + // above keeps its `mut` off macOS, where nothing is folded in. + let mut launch_options = launch_options; launch_options.extend_from_slice(&single_instance::env_launch_options()); let context = single_instance::LaunchContext { per_user_settings: app_dirs::current().mode == app_dirs::Mode::Platform,