Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]] {
Expand Down
73 changes: 73 additions & 0 deletions src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,50 @@ fn find_program(names: &[&str]) -> Option<PathBuf> {
})
}

/// 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<PathBuf> {
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)
Comment thread
sudo-py-dev marked this conversation as resolved.
Resolved
};
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::<u64>().ok())
.flatten()
})
.collect::<Option<Vec<_>>>()?
};
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 {
Expand All @@ -163,6 +207,9 @@ 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()),
#[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))
Expand Down Expand Up @@ -238,4 +285,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));
}
}
Loading