From 3b9d376f7b0200b6eced9dac050bf690e282533e Mon Sep 17 00:00:00 2001 From: sudo-py-dev <104791322+sudo-py-dev@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:55:09 +0000 Subject: [PATCH 1/2] Detect Linux LibreOffice installations outside PATH and add compact UI regression tests Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/app.rs | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ src/externals.rs | 78 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 173 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 5c2d0dd..41554b7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -7297,6 +7297,102 @@ mod tests { } } + #[test] + fn settings_sections_stay_within_screen_at_small_logical_sizes() { + // At the minimum 760x520 window, these smaller logical sizes also + // represent roughly 2x and 1.5x UI zoom. + for size in [ + [380.0, 260.0], + [507.0, 347.0], + [760.0, 520.0], + [900.0, 700.0], + ] { + for tab in SettingsTab::ALL { + let ctx = egui::Context::default(); + let cc = eframe::CreationContext::_new_kittest(ctx.clone()); + let mut app = FmxApp::new( + &cc, + Launch { + request: instance::Request::Focus, + self_test: true, + single_instance: false, + }, + ); + app.show_settings = true; + app.settings_tab = tab; + theme::apply(&ctx, ThemeChoice::Light, true); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, size.into()); + for _ in 0..4 { + ctx.run_ui( + egui::RawInput { + screen_rect: Some(screen), + ..Default::default() + }, + |ui| app.settings_window(ui.ctx()), + ) + .textures_delta + .clear(); + } + let bounds = ctx + .memory(|m| m.area_rect(Id::unique("settings_dialog"))) + .unwrap(); + assert!( + screen.contains_rect(bounds), + "tab={tab:?}, size={size:?}, bounds={bounds:?}" + ); + } + } + } + + #[test] + fn editor_panels_stay_within_available_space() { + for size in [ + [500.0, 300.0], + [760.0, 320.0], + [900.0, 320.0], + [900.0, 450.0], + [1100.0, 500.0], + ] { + for tool in [ + Tool::PdfMerge, + Tool::Trim, + Tool::Download, + Tool::DiscToIso, + Tool::RemoveImageMetadata, + ] { + let ctx = egui::Context::default(); + let cc = eframe::CreationContext::_new_kittest(ctx.clone()); + let mut app = FmxApp::new( + &cc, + Launch { + request: instance::Request::Focus, + self_test: true, + single_instance: false, + }, + ); + app.tool = tool; + theme::apply(&ctx, ThemeChoice::Light, true); + for _ in 0..4 { + ctx.run_ui(egui::RawInput::default(), |ui| { + let bounds = egui::Rect::from_min_size(ui.cursor().min, size.into()); + let response = ui + .scope_builder(egui::UiBuilder::new().max_rect(bounds), |ui| { + app.task_editor(ui) + }); + assert!( + response.response.rect.width() <= size[0] + 1.0 + && response.response.rect.height() <= size[1] + 1.0, + "tool={tool:?}, size={size:?}, bounds={bounds:?}, response={:?}", + response.response.rect + ); + }) + .textures_delta + .clear(); + } + } + } + } + #[test] fn welcome_pages_fit_small_and_large_windows() { for size in [[360.0, 480.0], [900.0, 700.0]] { diff --git a/src/externals.rs b/src/externals.rs index 28aa155..54e70dd 100644 --- a/src/externals.rs +++ b/src/externals.rs @@ -144,6 +144,50 @@ fn find_program(names: &[&str]) -> Option { }) } +/// The Document Foundation's Linux packages can install into a versioned +/// /opt/libreoffice... directory without an unversioned command on PATH. +#[cfg(target_os = "linux")] +fn find_linux_libreoffice(usr: &Path, opt: &Path) -> Option { + use std::os::unix::fs::PermissionsExt; + + let executable = |path: &Path| { + std::fs::metadata(path).is_ok_and(|m| m.is_file() && m.permissions().mode() & 0o111 != 0) + }; + for path in [ + usr.join("bin/soffice"), + usr.join("bin/libreoffice"), + usr.join("lib/libreoffice/program/soffice"), + ] { + if executable(&path) { + return Some(path); + } + } + + std::fs::read_dir(opt) + .ok()? + .filter_map(Result::ok) + .filter_map(|entry| { + let name = entry.file_name(); + let suffix = name.to_str()?.strip_prefix("libreoffice")?; + let version = if suffix.is_empty() { + Vec::new() + } else { + suffix + .split('.') + .map(|part| { + (!part.is_empty() && part.bytes().all(|b| b.is_ascii_digit())) + .then(|| part.parse::().ok()) + .flatten() + }) + .collect::>>()? + }; + let path = entry.path().join("program/soffice"); + executable(&path).then_some((version, path)) + }) + .max() + .map(|(_, path)| path) +} + /// Located external programs plus what the found ffmpeg can encode. #[derive(Clone, Debug, Default)] pub struct Toolbox { @@ -163,7 +207,13 @@ impl Toolbox { .filter_map(|ext| { let found = match (ext, override_path.as_deref()) { (External::Ffmpeg, Some(path)) => path.is_file().then(|| path.to_path_buf()), - _ => find_program(ext.binaries()), + _ => find_program(ext.binaries()).or_else(|| { + #[cfg(target_os = "linux")] + if ext == External::Soffice { + return find_linux_libreoffice(Path::new("/usr"), Path::new("/opt")); + } + None + }), }; found.map(|p| (ext, p)) }) @@ -238,4 +288,30 @@ mod tests { assert!(tb.get(External::Ffmpeg).is_none()); assert_eq!(tb.missing(&[External::Ffmpeg]), Some(External::Ffmpeg)); } + + #[cfg(target_os = "linux")] + #[test] + fn finds_debian_libreoffice_layouts_and_prefers_system_command() { + use std::os::unix::fs::PermissionsExt; + + let dir = tempfile::tempdir().unwrap(); + let usr = dir.path().join("usr"); + let opt = dir.path().join("opt"); + let install = |path: &Path, mode| { + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write(path, b"#!/bin/sh\n").unwrap(); + std::fs::set_permissions(path, std::fs::Permissions::from_mode(mode)).unwrap(); + }; + assert_eq!(find_linux_libreoffice(&usr, &opt), None); + let old = opt.join("libreoffice7.9/program/soffice"); + let new = opt.join("libreoffice7.10/program/soffice"); + install(&old, 0o755); + install(&new, 0o755); + install(&opt.join("libreoffice99.0/program/soffice"), 0o644); + install(&opt.join("libreoffice-backup/program/soffice"), 0o755); + assert_eq!(find_linux_libreoffice(&usr, &opt), Some(new)); + let system = usr.join("bin/soffice"); + install(&system, 0o755); + assert_eq!(find_linux_libreoffice(&usr, &opt), Some(system)); + } } From cce8c4649e7886d1f90d0a58712bd1af8786ba41 Mon Sep 17 00:00:00 2001 From: sudo-py-dev <104791322+sudo-py-dev@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:03:31 +0000 Subject: [PATCH 2/2] Refactor Linux LibreOffice detection into a dedicated match arm Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/externals.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/externals.rs b/src/externals.rs index 54e70dd..32214fd 100644 --- a/src/externals.rs +++ b/src/externals.rs @@ -207,13 +207,10 @@ impl Toolbox { .filter_map(|ext| { let found = match (ext, override_path.as_deref()) { (External::Ffmpeg, Some(path)) => path.is_file().then(|| path.to_path_buf()), - _ => find_program(ext.binaries()).or_else(|| { - #[cfg(target_os = "linux")] - if ext == External::Soffice { - return find_linux_libreoffice(Path::new("/usr"), Path::new("/opt")); - } - None - }), + #[cfg(target_os = "linux")] + (External::Soffice, _) => find_program(ext.binaries()) + .or_else(|| find_linux_libreoffice(Path::new("/usr"), Path::new("/opt"))), + _ => find_program(ext.binaries()), }; found.map(|p| (ext, p)) })