Fix sidecar not found on Windows/macOS/Linux: switch from externalBin to resources
Tauri's externalBin only bundled the single sidecar executable, but PyInstaller's onedir output requires companion DLLs and _internal/. The binary was also renamed with a target triple suffix that resolve_sidecar_path() didn't look for, causing it to fall back to dev mode which used a compile-time CI path (CARGO_MANIFEST_DIR). - Switch from externalBin to bundle.resources to include all sidecar files - Pass Tauri resource_dir to sidecar manager for platform-aware path resolution - Remove rename_binary() since externalBin target triple naming is no longer needed - Remove broken production-to-dev fallback that could never work on user machines Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,22 @@ pub mod ipc;
|
||||
pub mod messages;
|
||||
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Child, ChildStdin, Command, Stdio};
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
|
||||
use crate::sidecar::messages::IPCMessage;
|
||||
|
||||
/// Resource directory set by the Tauri app during setup.
|
||||
/// Used to locate the bundled sidecar binary and its companion files.
|
||||
static RESOURCE_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||
|
||||
/// Set the resource directory for sidecar resolution.
|
||||
/// Must be called from the Tauri setup before any sidecar operations.
|
||||
pub fn init_resource_dir(dir: PathBuf) {
|
||||
RESOURCE_DIR.set(dir).ok();
|
||||
}
|
||||
|
||||
/// Get the global sidecar manager singleton.
|
||||
pub fn sidecar() -> &'static SidecarManager {
|
||||
static INSTANCE: OnceLock<SidecarManager> = OnceLock::new();
|
||||
@@ -41,34 +52,56 @@ impl SidecarManager {
|
||||
}
|
||||
|
||||
/// Resolve the frozen sidecar binary path (production mode).
|
||||
///
|
||||
/// Searches for the PyInstaller-built sidecar in the Tauri resource directory
|
||||
/// (set via `init_resource_dir`) and falls back to paths relative to the
|
||||
/// current executable.
|
||||
fn resolve_sidecar_path() -> Result<std::path::PathBuf, String> {
|
||||
let exe = std::env::current_exe().map_err(|e| format!("Cannot get current exe: {e}"))?;
|
||||
let exe_dir = exe
|
||||
.parent()
|
||||
.ok_or_else(|| "Cannot get exe parent directory".to_string())?;
|
||||
|
||||
let binary_name = if cfg!(target_os = "windows") {
|
||||
"voice-to-notes-sidecar.exe"
|
||||
} else {
|
||||
"voice-to-notes-sidecar"
|
||||
};
|
||||
|
||||
// Tauri places externalBin next to the app binary
|
||||
let path = exe_dir.join(binary_name);
|
||||
if path.exists() {
|
||||
return Ok(path);
|
||||
let mut candidates: Vec<std::path::PathBuf> = Vec::new();
|
||||
|
||||
// Primary: Tauri resource directory (set during app setup)
|
||||
if let Some(resource_dir) = RESOURCE_DIR.get() {
|
||||
// Resources are placed under sidecar/ subdirectory
|
||||
candidates.push(resource_dir.join("sidecar").join(binary_name));
|
||||
// Also check flat layout in resource dir
|
||||
candidates.push(resource_dir.join(binary_name));
|
||||
}
|
||||
|
||||
// Also check inside a subdirectory (onedir PyInstaller output)
|
||||
let subdir_path = exe_dir.join("voice-to-notes-sidecar").join(binary_name);
|
||||
if subdir_path.exists() {
|
||||
return Ok(subdir_path);
|
||||
// Fallback: relative to the current executable
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
if let Some(exe_dir) = exe.parent() {
|
||||
// sidecar/ subdirectory next to exe (Windows MSI, Linux AppImage)
|
||||
candidates.push(exe_dir.join("sidecar").join(binary_name));
|
||||
// Flat layout next to exe
|
||||
candidates.push(exe_dir.join(binary_name));
|
||||
// PyInstaller onedir subdirectory
|
||||
candidates.push(
|
||||
exe_dir
|
||||
.join("voice-to-notes-sidecar")
|
||||
.join(binary_name),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for path in &candidates {
|
||||
if path.exists() {
|
||||
return Ok(path.canonicalize().unwrap_or_else(|_| path.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
Err(format!(
|
||||
"Sidecar binary not found. Looked for:\n {}\n {}",
|
||||
path.display(),
|
||||
subdir_path.display(),
|
||||
"Sidecar binary not found. Checked:\n{}",
|
||||
candidates
|
||||
.iter()
|
||||
.map(|p| format!(" {}", p.display()))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -114,15 +147,8 @@ impl SidecarManager {
|
||||
if Self::is_dev_mode() {
|
||||
self.start_python_dev()
|
||||
} else {
|
||||
match Self::resolve_sidecar_path() {
|
||||
Ok(path) => self.start_binary(&path),
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"[sidecar-rs] Frozen binary not found ({e}), falling back to dev mode"
|
||||
);
|
||||
self.start_python_dev()
|
||||
}
|
||||
}
|
||||
let path = Self::resolve_sidecar_path()?;
|
||||
self.start_binary(&path)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user