LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #738
Claudec53b61732de7
diff --cc Cargo.lockindex efcf9e883,097330a6c..72c0319c4--- a/Cargo.lock+++ b/Cargo.lock@@@ -3078,12 -2987,9 +3078,13 @@@ dependencies ="lightcraft-ui-egui","log","muda",+ "objc2 0.6.4",+ "objc2-app-kit 0.3.2",+ "objc2-foundation 0.3.2",+ "pollster 1.0.1","rfd","serde_json",+ "winit","winresource",]diff --cc README.mdindex 5bf7b3d1d,217092fbf..a82d1df77--- a/README.md+++ b/README.md@@@ -490,8 -481,6 +490,11 @@@ option to start it. For unattended inst| Fedora/RHEL/openSUSE | `lightcraft-<ver>-linux-x86_64.rpm` | `lightcraft-<ver>-linux-aarch64.rpm` | || Tarball | `lightcraft-<ver>-linux-x86_64.tar.gz` | `lightcraft-<ver>-linux-aarch64.tar.gz` | Unpack anywhere |+RISC-V (riscv64): `lightcraft-<ver>-linux-riscv64.tar.gz`, a tarball only (glibc 2.39 or newer, e.g. Ubuntu 24.04+).+++On a Wayland desktop LightCraft runs through XWayland when it is available, because only X11 gives++windows file drag-and-drop; set `LIGHTCRAFT_WAYLAND=1` to use native Wayland (sharper fractional scaling, no drop).++### FreeBSD| Build | File |diff --cc apps/lightcraft/src/main.rsindex 722e051c3,f7cabfa17..2fc1aaf95--- a/apps/lightcraft/src/main.rs+++ b/apps/lightcraft/src/main.rs@@@ -824,80 -754,80 +824,92 @@@ fn main() -> eframe::Result};// the app's copy: `log_file` is still named in the message of a start that failslet app_log_file = log_file.clone();+ #[cfg(all(unix, not(target_os = "macos")))]+ let mut options = options;+ // winit has no file drag-and-drop on Wayland (only on X11), so dropping files from the file+ // manager showed a "no" cursor. Run through XWayland when it's there; LIGHTCRAFT_WAYLAND=1+ // keeps the native Wayland backend.+ #[cfg(all(unix, not(target_os = "macos")))]+ if std::env::var_os("DISPLAY").is_some() && std::env::var_os("LIGHTCRAFT_WAYLAND").is_none() {+ options.event_loop_builder = Some(Box::new(|b| {+ use winit::platform::x11::EventLoopBuilderExtX11;+ b.with_x11();+ }));+ }- let started = eframe::run_native(- "LightCraft",- options,- Box::new(move |cc| {- let (mut session, problem) = open_session(in_memory, library_dir, seed_demo && files.is_empty());- // AI masks: the SAM 3 checkpoint (facebook/sam3) in <config>/models/sam3, or LIGHTCRAFT_SAM3_DIR- // (never required: without it, AI masks offer to download it; see docs/ai-masks.md)- session.segmenter.dir =- std::env::var_os("LIGHTCRAFT_SAM3_DIR").map(std::path::PathBuf::from).or_else(|| config_dir().map(|d| d.join("models").join("sam3")));- // the user's own download locations, one base URL per line (LIGHTCRAFT_SAM3_MIRRORS too)- session.segmenter.mirrors_file = config_dir().map(|d| d.join("models").join("sam3-mirrors.txt"));- let mut app = LightcraftApp::new(session, services(cc.egui_ctx.clone(), app_log_file.as_deref()));- if let Some(ui) = prefs {- app.ui = ui;- }- lightcraft_ui_egui::i18n::set_language(app.ui.language);- app.integrated_titlebar = cfg!(target_os = "macos");- app.notices.extend(prefs_warning);- app.notices.extend(launch_notices);- // what's on disk now: only changes are written- let writer = PrefsWriter {- path: if in_memory { None } else { prefs_path() },- written: serde_json::to_vec_pretty(&app.ui).unwrap_or_default(),- library: app.ui.settings.library_path.clone(),- keep_file: keep_prefs_file,- ..Default::default()- };- // after the snapshot above, so the writer saves the switched-off preference- if let Some(notice) = gpu_crash {- app.ui.settings.gpu = false;- app.notices.push(notice);- }- if let Some(port) = control_port {- let rx = control_server::start(port, cc.egui_ctx.clone());- app = app.with_control(rx);- }- if let Some(mut p) = problem {- // imported once the user has chosen where (into the library, or the temporary session)- p.pending_import = files;- app.library_problem = Some(p);- } else if !files.is_empty() {- // listed and read on the import worker once the window shows (issue #374: never- // here, before the first frame, where a large folder kept the window from- // appearing)- if let Err(e) = lightcraft_ui_egui::import::start_paths(&mut app, files) {- log::warn!("import at launch: {e}");+ let started = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {+ eframe::run_native(+ "LightCraft",+ options,+ Box::new(move |cc| {+ // the window's renderer is up (eframe calls this after creating it)+ win_files_app.started(window_renderer);+ let (mut session, problem) = open_session(in_memory, library_dir, seed_demo && files.is_empty());+ // AI masks: the SAM 3 checkpoint (facebook/sam3) in <config>/models/sam3, or LIGHTCRAFT_SAM3_DIR+ // (never required: without it, AI masks offer to download it; see docs/ai-masks.md)+ // and the user's own download locations, one base URL per line (LIGHTCRAFT_SAM3_MIRRORS too)+ session = session.with_default_sam3_model();+ let mut app = LightcraftApp::new(session, services(cc, app_log_file.as_deref()));+ if let Some(ui) = prefs {+ app.ui = ui;}- app.ui.view = lightcraft_ui_egui::state::ViewMode::PhotoGrid;- }- // native menu bar generated from the command registry (macOS; elsewhere the menus are- // drawn in the window's top bar). LIGHTCRAFT_NO_NATIVE_MENU=1 keeps the in-window menus.- #[cfg(target_os = "macos")]- let menu = (std::env::var_os("LIGHTCRAFT_NO_NATIVE_MENU").is_none()).then(|| native_menu::NativeMenu::install(&mut app, &cc.egui_ctx));- Ok(Box::new(App(- app,- writer,+ lightcraft_ui_egui::i18n::set_language(app.ui.language);+ app.integrated_titlebar = cfg!(target_os = "macos");+ app.notices.extend(prefs_warning);+ app.notices.extend(launch_notices);+ app.notices.extend(window_notice);+ // what's on disk now: only changes are written+ let writer = PrefsWriter {+ path: if in_memory { None } else { prefs_path() },+ written: serde_json::to_vec_pretty(&app.ui).unwrap_or_default(),+ library: app.ui.settings.library_path.clone(),+ keep_file: keep_prefs_file,+ ..Default::default()+ };+ // after the snapshot above, so the writer saves the switched-off preference+ if let Some(notice) = gpu_crash {+ app.ui.settings.gpu = false;+ app.notices.push(notice);+ }+ if let Some(port) = control_port {+ let rx = control_server::start(port, cc.egui_ctx.clone());+ app = app.with_control(rx);+ }+ if let Some(mut p) = problem {+ // imported once the user has chosen where (into the library, or the temporary session)+ p.pending_import = files;+ app.library_problem = Some(p);+ } else if !files.is_empty() {+ // listed and read on the import worker once the window shows (issue #374: never+ // here, before the first frame, where a large folder kept the window from+ // appearing)+ if let Err(e) = lightcraft_ui_egui::import::start_paths(&mut app, files) {+ log::warn!("import at launch: {e}");+ }+ app.ui.view = lightcraft_ui_egui::state::ViewMode::PhotoGrid;+ }+ // native menu bar generated from the command registry (macOS; elsewhere the menus are+ // drawn in the window's top bar). LIGHTCRAFT_NO_NATIVE_MENU=1 keeps the in-window menus.#[cfg(target_os = "macos")]- menu,- )))- }),- );+ let menu =+ (std::env::var_os("LIGHTCRAFT_NO_NATIVE_MENU").is_none()).then(|| native_menu::NativeMenu::install(&mut app, &cc.egui_ctx));+ Ok(Box::new(App(+ app,+ writer,+ #[cfg(target_os = "macos")]+ menu,+ )))+ }),+ )+ }));+ // a panic that still escaped the renderer's start (the probe and error handler should+ // prevent it): an error like any other failed start+ let started = started.unwrap_or_else(|_| Err(eframe::Error::AppCreation("the window's renderer panicked while starting".into())));if let Err(e) = &started {+ // the renderer never came up: start again, which tries the next one in the chain+ if window_gpu::relaunch_after_failure(&win_files) {+ log::error!("LightCraft could not open its window with {}: {e}; trying the next renderer", window_renderer.name());+ return Ok(());+ }startup_failed(&e.to_string(), log_file.as_deref());}started