Skip to content

Commit c62509a

Browse files
nedtwiggEdgarTwigg
authored andcommitted
Fix windows standalone launching.
1 parent cd0708a commit c62509a

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

  • standalone/src-tauri/src

standalone/src-tauri/src/lib.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,45 @@ fn resolve_sidecar_path(resource_dir: Option<PathBuf>, manifest_dir: &Path) -> P
256256
manifest_dir.join("..").join("sidecar").join("main.js")
257257
}
258258

259+
fn strip_windows_verbatim_prefix(path_string: &str) -> Option<PathBuf> {
260+
if let Some(stripped) = path_string.strip_prefix(r"\\?\UNC\") {
261+
return Some(PathBuf::from(format!(r"\\{stripped}")));
262+
}
263+
if let Some(stripped) = path_string.strip_prefix(r"\\?\") {
264+
return Some(PathBuf::from(stripped));
265+
}
266+
267+
None
268+
}
269+
270+
fn sidecar_script_arg_path(path: &Path) -> PathBuf {
271+
if let Some(path) = strip_windows_verbatim_prefix(&path.to_string_lossy()) {
272+
return path;
273+
}
274+
275+
path.to_path_buf()
276+
}
277+
259278
fn start_sidecar(app: &AppHandle) -> Result<SidecarState, String> {
260279
let sidecar_path = resolve_sidecar_path(
261280
app.path().resource_dir().ok(),
262281
Path::new(env!("CARGO_MANIFEST_DIR")),
263282
);
283+
let sidecar_arg_path = sidecar_script_arg_path(&sidecar_path);
264284
append_log(format!(
265285
"[sidecar] resolved script: {}",
266286
sidecar_path.display()
267287
));
288+
append_log(format!(
289+
"[sidecar] script argument: {}",
290+
sidecar_arg_path.display()
291+
));
268292

269293
let (mut rx, mut child) = app
270294
.shell()
271295
.sidecar("node")
272296
.map_err(|err| format!("failed to resolve bundled Node.js runtime: {err}"))?
273-
.arg(&sidecar_path)
297+
.arg(&sidecar_arg_path)
274298
.set_raw_out(false)
275299
.spawn()
276300
.map_err(|err| format!("failed to start Node.js sidecar: {err}"))?;
@@ -419,7 +443,7 @@ pub fn run() {
419443

420444
#[cfg(test)]
421445
mod tests {
422-
use super::resolve_sidecar_path;
446+
use super::{resolve_sidecar_path, strip_windows_verbatim_prefix};
423447
use std::fs;
424448
use std::path::{Path, PathBuf};
425449
use std::time::{SystemTime, UNIX_EPOCH};
@@ -479,4 +503,28 @@ mod tests {
479503
manifest_dir.join("..").join("sidecar").join("main.js")
480504
);
481505
}
506+
507+
#[test]
508+
fn strips_windows_verbatim_prefix_for_node_main_script() {
509+
let path = strip_windows_verbatim_prefix(
510+
r"\\?\C:\Users\EdgarTwigg\AppData\Local\MouseTerm\_up_\sidecar\main.js",
511+
)
512+
.expect("expected verbatim path to be stripped");
513+
514+
assert_eq!(
515+
path,
516+
PathBuf::from(r"C:\Users\EdgarTwigg\AppData\Local\MouseTerm\_up_\sidecar\main.js")
517+
);
518+
}
519+
520+
#[test]
521+
fn strips_windows_verbatim_unc_prefix_for_node_main_script() {
522+
let path = strip_windows_verbatim_prefix(r"\\?\UNC\server\share\MouseTerm\sidecar\main.js")
523+
.expect("expected verbatim UNC path to be stripped");
524+
525+
assert_eq!(
526+
path,
527+
PathBuf::from(r"\\server\share\MouseTerm\sidecar\main.js")
528+
);
529+
}
482530
}

0 commit comments

Comments
 (0)