fix(desktop): find the sidecar in a macOS app bundle and fit the startup screen (UF-004, UF-017)
- The packaged macOS app stayed on "Starting Waggle…": the shell looked for node, service.js, native/ and node_modules/ next to the executable, the Windows layout, while a macOS bundle keeps them in Contents/Resources/resources. bundled_resources_dir() checks both. - The startup screen used min-height 100vh on an unstyled body, which showed scroll bars, and a fixed light text colour that is invisible in the light theme. It is now styled from index.html, fixed to the window, with a dark text colour for the light theme.
This commit is contained in:
@@ -301,6 +301,20 @@ fn valid_node_override(custom: Option<&OsStr>) -> Option<PathBuf> {
|
||||
custom_path.is_file().then_some(custom_path)
|
||||
}
|
||||
|
||||
/// 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).
|
||||
fn bundled_resources_dir(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())
|
||||
.chain(app_bundle)
|
||||
.find(|dir| dir.join("service.js").exists())
|
||||
.unwrap_or(next_to_exe)
|
||||
}
|
||||
|
||||
/// Resolve the Node.js binary path.
|
||||
/// Priority: WAGGLE_NODE_PATH env → bundled resources/node[.exe] → system PATH "node"
|
||||
fn resolve_node_path() -> String {
|
||||
@@ -313,16 +327,17 @@ fn resolve_node_path() -> String {
|
||||
eprintln!("[waggle] Ignoring WAGGLE_NODE_PATH because it is not a runtime file");
|
||||
}
|
||||
|
||||
// 2. Bundled Node.js in resources/ directory (next to exe)
|
||||
// 2. Bundled Node.js in the bundled resources directory
|
||||
let exe_dir = std::env::current_exe()
|
||||
.ok()
|
||||
.and_then(|p| p.parent().map(|d| d.to_path_buf()));
|
||||
|
||||
if let Some(ref dir) = exe_dir {
|
||||
let resources = bundled_resources_dir(dir);
|
||||
let bundled = if cfg!(windows) {
|
||||
dir.join("resources").join("node.exe")
|
||||
resources.join("node.exe")
|
||||
} else {
|
||||
dir.join("resources").join("node")
|
||||
resources.join("node")
|
||||
};
|
||||
if bundled.exists() {
|
||||
return bundled.to_string_lossy().to_string();
|
||||
@@ -583,7 +598,7 @@ fn resolve_service_script(
|
||||
current_dir: &Path,
|
||||
) -> Result<ServiceScript, String> {
|
||||
if let Some(dir) = exe_dir {
|
||||
let bundled = dir.join("resources").join("service.js");
|
||||
let bundled = bundled_resources_dir(dir).join("service.js");
|
||||
if bundled.exists() {
|
||||
return Ok(ServiceScript {
|
||||
path: bundled,
|
||||
@@ -640,7 +655,7 @@ fn build_service_command(
|
||||
cmd.env("WAGGLE_SKIP_LITELLM", "1");
|
||||
|
||||
if let Some(ref dir) = exe_dir {
|
||||
let resources_dir = dir.join("resources");
|
||||
let resources_dir = bundled_resources_dir(dir);
|
||||
let native_dir = resources_dir.join("native");
|
||||
let node_modules_dir = resources_dir.join("node_modules");
|
||||
let configured_data_dir = std::env::var_os("WAGGLE_DATA_DIR");
|
||||
@@ -957,6 +972,30 @@ mod tests {
|
||||
assert!(state.verified_port().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn service_script_resolves_from_a_macos_app_bundle() {
|
||||
let root =
|
||||
std::env::temp_dir().join(format!("waggle-app-bundle-{}", std::process::id()));
|
||||
let macos = root.join("Waggle.app").join("Contents").join("MacOS");
|
||||
let resources = root
|
||||
.join("Waggle.app")
|
||||
.join("Contents")
|
||||
.join("Resources")
|
||||
.join("resources");
|
||||
std::fs::create_dir_all(&macos).expect("creates MacOS dir");
|
||||
std::fs::create_dir_all(&resources).expect("creates bundle resources");
|
||||
std::fs::write(resources.join("service.js"), "console.log('ok')").expect("writes service");
|
||||
|
||||
let script = resolve_service_script(Some(&macos), Path::new("/nonexistent"))
|
||||
.expect("bundled script resolves from Contents/Resources");
|
||||
|
||||
assert_eq!(script.kind, ServiceScriptKind::Bundled);
|
||||
assert_eq!(script.path, resources.join("service.js"));
|
||||
assert_eq!(bundled_resources_dir(&macos), resources);
|
||||
|
||||
let _ = std::fs::remove_dir_all(root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn service_script_prefers_bundled_resource_when_present() {
|
||||
let root =
|
||||
|
||||
Reference in New Issue
Block a user