Files
ElyOffice/crates/ely-lok/src/client/install.rs
T
ZacharyZhang-NYandClaude Opus 5.5 c96d39a342 LOK runs on Windows and Linux; packaging stages engines (W-01, K-01)
The kernel is the merged library on every platform; Windows and
Linux find it beside the app in libreoffice/program. All three run
unipoll: macOS through GCD, Linux by answering one request per poll,
Windows through a message-only window on the loop's thread (LOK's
own main thread had deadlocked Calc loads). Patch 0043 flushes
callbacks inline everywhere, so a request sees its result; 0042 stops
MSVC's Boost auto-link. Linux paints with cairo, BGRA; the start-up
check now paints red text and finds red in byte two on every
platform, since getTileMode does not see Skia.

ely-lok on Windows: 180 of 189 pass; on Linux 187. The rest are
listed after 0.1.3 (spelling, Calc dark tiles, show layers and
fields, a11y selection). Tests build file URLs portably and accept
CRLF where Windows writes it.

packaging/stage.sh lays out an app with its engines for Windows and
Linux; licenses.sh finds each licence on all three. ElyMark finds its
page beside the app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 18:27:53 -04:00

106 lines
3.2 KiB
Rust

//! Where the LOK build and the worker binary are.
use std::{
io,
path::{Path, PathBuf},
};
/// The kernel's bundled templates of `kind`, such as `presnt`.
pub fn templates(kind: &str) -> io::Result<Vec<PathBuf>> {
let install = install_dir()?;
let root = install
.parent()
.ok_or_else(|| io::Error::other("the install has no parent"))?;
let common = match cfg!(target_os = "macos") {
true => root.join("Resources/template/common"),
false => root.join("share/template/common"),
};
let mut found = std::fs::read_dir(common.join(kind))?
.map(|entry| entry.map(|entry| entry.path()))
.collect::<io::Result<Vec<_>>>()?;
found.sort();
Ok(found)
}
/// The kernel's folder beside the app, and in this build.
#[cfg(target_os = "macos")]
const LAYOUT: (&str, &str) = ("../Frameworks", "instdir/LibreOffice.app/Contents/Frameworks");
#[cfg(not(target_os = "macos"))]
const LAYOUT: (&str, &str) = ("libreoffice/program", "instdir/program");
/// The LOK build: `ELY_LOK_DIR`, the app bundle's, or engines/.
pub fn install_dir() -> io::Result<PathBuf> {
if let Ok(dir) = std::env::var("ELY_LOK_DIR") {
let path = PathBuf::from(dir);
return if path.try_exists()? {
Ok(path)
} else {
Err(io::Error::new(
io::ErrorKind::NotFound,
format!("ELY_LOK_DIR {} does not exist", path.display()),
))
};
}
let (beside, built) = LAYOUT;
let library = crate::ffi::KERNEL;
let exe = std::env::current_exe()?;
let bundled = exe.parent().unwrap_or(Path::new(".")).join(beside);
if bundled.join(library).try_exists()? {
return Ok(bundled);
}
let dev = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../engines/lo-src").join(built);
if dev.join(library).try_exists()? {
return Ok(dev);
}
Err(io::Error::new(
io::ErrorKind::NotFound,
"no LOK build (set ELY_LOK_DIR)",
))
}
/// The worker binary: env override, else beside this exe.
pub(super) fn worker_bin() -> io::Result<PathBuf> {
if let Ok(bin) = std::env::var("ELY_LOK_WORKER") {
if bin.is_empty() {
return Err(io::Error::new(
io::ErrorKind::NotFound,
"ELY_LOK_WORKER is empty",
));
}
let path = PathBuf::from(&bin);
return if path.try_exists()? {
Ok(path)
} else {
Err(io::Error::new(
io::ErrorKind::NotFound,
format!("ELY_LOK_WORKER {bin} does not exist"),
))
};
}
let sibling = std::env::current_exe()?
.parent()
.unwrap_or(Path::new("."))
.join(if cfg!(windows) {
"ely-lok-worker.exe"
} else {
"ely-lok-worker"
});
if sibling.try_exists()? {
return Ok(sibling);
}
let dev = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../target/debug")
.join(if cfg!(windows) {
"ely-lok-worker.exe"
} else {
"ely-lok-worker"
});
if dev.try_exists()? {
return Ok(dev);
}
Err(io::Error::new(
io::ErrorKind::NotFound,
"no ely-lok-worker binary (set ELY_LOK_WORKER)",
))
}