fix(desktop): find the sidecar through Tauri's resource directory (P1.3d)

Linux packages keep resources in /usr/lib/<app> (deb) or under $APPDIR
(AppImage), not next to the executable, so the shell never found
service.js there. Setup now records Tauri's resource_dir and the lookup
prefers it, keeping the executable-relative paths as a fallback.

Drop tauri-plugin-updater: it was declared but never registered, and the
updater stays disabled until release signing exists.
This commit is contained in:
shumeiko.it
2026-11-01 00:10:22 +01:00
parent a8250cb375
commit d2ad282498
9 changed files with 47 additions and 277 deletions

View File

@@ -10,7 +10,7 @@ use std::process::Stdio;
use std::process::{Child, Command};
#[cfg(windows)]
use std::sync::Arc;
use std::sync::Mutex;
use std::sync::{Mutex, OnceLock};
use std::time::{Duration, Instant};
use tauri::{AppHandle, Emitter, Manager, State};
use uuid::Uuid;
@@ -303,15 +303,33 @@ fn valid_node_override(custom: Option<&OsStr>) -> Option<PathBuf> {
custom_path.is_file().then_some(custom_path)
}
/// Tauri's resource directory for this install, set once at startup: next to
/// the executable on Windows, `Contents/Resources` in a macOS app bundle,
/// `/usr/lib/<app>` for a deb package and `$APPDIR/usr/lib/<app>` in an AppImage.
static TAURI_RESOURCE_DIR: OnceLock<PathBuf> = OnceLock::new();
pub fn set_resource_dir(dir: PathBuf) {
let _ = TAURI_RESOURCE_DIR.set(dir);
}
/// Directory of the bundled sidecar payload (service.js, node, native,
/// node_modules). Windows installs keep it next to the executable; a macOS app
/// bundle keeps it in `Contents/Resources` (UF-004).
/// node_modules).
fn bundled_resources_dir(exe_dir: &Path) -> PathBuf {
bundled_resources_dir_from(TAURI_RESOURCE_DIR.get().map(PathBuf::as_path), exe_dir)
}
/// Prefers Tauri's resource directory. The paths derived from the executable
/// cover a launch before setup has recorded it: Windows keeps the payload next
/// to the executable, a macOS app bundle in `Contents/Resources` (UF-004).
fn bundled_resources_dir_from(resource_dir: Option<&Path>, exe_dir: &Path) -> PathBuf {
let next_to_exe = exe_dir.join("resources");
let app_bundle = exe_dir
.parent()
.map(|contents| contents.join("Resources").join("resources"));
std::iter::once(next_to_exe.clone())
resource_dir
.map(|dir| dir.join("resources"))
.into_iter()
.chain(std::iter::once(next_to_exe.clone()))
.chain(app_bundle)
.find(|dir| dir.join("service.js").exists())
.unwrap_or(next_to_exe)
@@ -997,6 +1015,22 @@ mod tests {
let _ = std::fs::remove_dir_all(root);
}
#[test]
fn resources_resolve_from_the_tauri_resource_dir_of_a_linux_package() {
let root = std::env::temp_dir().join(format!("waggle-deb-{}", std::process::id()));
let bin = root.join("usr").join("bin");
let resource_dir = root.join("usr").join("lib").join("Waggle");
let resources = resource_dir.join("resources");
std::fs::create_dir_all(&bin).expect("creates bin dir");
std::fs::create_dir_all(&resources).expect("creates package resources");
std::fs::write(resources.join("service.js"), "console.log('ok')").expect("writes service");
assert_eq!(bundled_resources_dir_from(Some(&resource_dir), &bin), resources);
assert_eq!(bundled_resources_dir_from(None, &bin), bin.join("resources"));
let _ = std::fs::remove_dir_all(root);
}
#[test]
fn service_script_prefers_bundled_resource_when_present() {
let root =