[V1] Changed Windows Auto-Detect Binary

This commit is contained in:
Youwes09
2026-02-25 21:40:52 -06:00
parent 70afb08f83
commit 817af0d10a
2 changed files with 79 additions and 40 deletions
+11 -21
View File
@@ -113,33 +113,23 @@ jobs:
run: | run: |
mkdir -p src-tauri/binaries mkdir -p src-tauri/binaries
# 1. Prefer an exe whose name contains "Launcher" (case-insensitive), # The Windows bundle has no standalone launcher exe — it ships
# searched recursively but NOT inside any jre/ or runtime/ subtree. # "Suwayomi Launcher.bat" which calls jre\bin\javaw.exe -jar Suwayomi-Launcher.jar.
LAUNCHER=$(find suwayomi-extracted -name "*[Ll]auncher*.exe" \ # Tauri sidecars must be real executables, so we stage javaw.exe as the
! -path "*/jre/*" ! -path "*/runtime/*" | head -1) # sidecar. lib.rs will invoke it with the correct -jar + working-dir args.
JAVAW=$(find suwayomi-extracted -path "*/jre/bin/javaw.exe" | head -1)
# 2. Fall back to any top-level .exe that isn't a JVM executable. if [ -z "$JAVAW" ]; then
if [ -z "$LAUNCHER" ]; then echo "ERROR: could not find jre/bin/javaw.exe"
LAUNCHER=$(find suwayomi-extracted -maxdepth 1 -name "*.exe" \
! -name "java.exe" ! -name "javaw.exe" ! -name "javaw_g.exe" | head -1)
fi
# 3. Wider recursive search, still excluding the JRE tree.
if [ -z "$LAUNCHER" ]; then
LAUNCHER=$(find suwayomi-extracted -name "*.exe" \
! -path "*/jre/*" ! -path "*/runtime/*" \
! -name "java.exe" ! -name "javaw.exe" ! -name "javaw_g.exe" | head -1)
fi
if [ -z "$LAUNCHER" ]; then
echo "ERROR: could not find Windows launcher"
ls -lR suwayomi-extracted/ ls -lR suwayomi-extracted/
exit 1 exit 1
fi fi
echo "Using launcher: $LAUNCHER" echo "Using javaw: $JAVAW"
cp "$JAVAW" "src-tauri/binaries/suwayomi-server-x86_64-pc-windows-msvc.exe"
cp "$LAUNCHER" "src-tauri/binaries/suwayomi-server-x86_64-pc-windows-msvc.exe" # Copy the full bundle so the .jar and jre/ tree are available at runtime.
# lib.rs sets the working directory to this folder before spawning.
cp -r suwayomi-extracted src-tauri/binaries/suwayomi-bundle cp -r suwayomi-extracted src-tauri/binaries/suwayomi-bundle
- name: Patch tauri.conf.json for CI - name: Patch tauri.conf.json for CI
+68 -19
View File
@@ -197,19 +197,37 @@ fn suwayomi_data_dir() -> PathBuf {
} }
} }
/// Everything needed to spawn the server process.
struct ServerInvocation {
/// Path to the executable (javaw.exe on Windows, the sidecar script on macOS/Linux).
bin: std::ffi::OsString,
/// Extra args prepended before the Suwayomi rootDir flag.
/// On Windows: ["-jar", "<path-to-jar>"]
/// Elsewhere: []
prefix_args: Vec<String>,
/// Working directory for the child process.
/// On Windows this must be the bundle folder so javaw can find the JRE and jar.
/// Elsewhere: None (inherit).
working_dir: Option<PathBuf>,
}
/// Resolve the server binary path. /// Resolve the server binary path.
/// ///
/// If the frontend passes a non-empty `binary` string (user override in /// If the frontend passes a non-empty `binary` string (user override in
/// Settings) we always use that — on Linux this is the nixpkgs/Flatpak path. /// Settings) we always use that — on Linux this is the nixpkgs/Flatpak path.
/// ///
/// Otherwise we look for the Tauri-bundled sidecar inside the .app's /// Otherwise we look for the Tauri-bundled sidecar inside the resource dir
/// Resources directory (macOS) or alongside the binary (other platforms). /// and, on Windows, build the javaw + jar invocation from the suwayomi-bundle.
fn resolve_server_binary( fn resolve_server_binary(
binary: &str, binary: &str,
app: &tauri::AppHandle, app: &tauri::AppHandle,
) -> Result<std::ffi::OsString, String> { ) -> Result<ServerInvocation, String> {
if !binary.trim().is_empty() { if !binary.trim().is_empty() {
return Ok(std::ffi::OsString::from(binary)); return Ok(ServerInvocation {
bin: std::ffi::OsString::from(binary),
prefix_args: vec![],
working_dir: None,
});
} }
let resource_dir = app let resource_dir = app
@@ -217,11 +235,29 @@ fn resolve_server_binary(
.resource_dir() .resource_dir()
.map_err(|e| format!("Could not locate resource dir: {e}"))?; .map_err(|e| format!("Could not locate resource dir: {e}"))?;
// Tauri places sidecars as <stem>-<target-triple> in the resource dir. // ── Windows: invoke the bundled javaw.exe with -jar Suwayomi-Launcher.jar ──
#[cfg(target_os = "windows")]
{
let sidecar = resource_dir.join("suwayomi-server-x86_64-pc-windows-msvc.exe");
let bundle_dir = resource_dir.join("suwayomi-bundle");
let jar = bundle_dir.join("Suwayomi-Launcher.jar");
if sidecar.exists() && jar.exists() {
return Ok(ServerInvocation {
bin: sidecar.into_os_string(),
prefix_args: vec![
"-jar".to_string(),
jar.to_string_lossy().into_owned(),
],
working_dir: Some(bundle_dir),
});
}
}
// ── macOS / Linux: sidecar script is self-contained ──
let candidates = [ let candidates = [
"suwayomi-server-aarch64-apple-darwin", "suwayomi-server-aarch64-apple-darwin",
"suwayomi-server-x86_64-apple-darwin", "suwayomi-server-x86_64-apple-darwin",
"suwayomi-server-x86_64-pc-windows-msvc.exe",
// plain name as a dev/Linux fallback // plain name as a dev/Linux fallback
"suwayomi-server", "suwayomi-server",
]; ];
@@ -229,7 +265,11 @@ fn resolve_server_binary(
for name in &candidates { for name in &candidates {
let p = resource_dir.join(name); let p = resource_dir.join(name);
if p.exists() { if p.exists() {
return Ok(p.into_os_string()); return Ok(ServerInvocation {
bin: p.into_os_string(),
prefix_args: vec![],
working_dir: None,
});
} }
} }
@@ -251,31 +291,40 @@ fn spawn_server(binary: String, app: tauri::AppHandle) -> Result<(), String> {
let data_dir = suwayomi_data_dir(); let data_dir = suwayomi_data_dir();
seed_server_conf(&data_dir); seed_server_conf(&data_dir);
let bin = resolve_server_binary(&binary, &app)?; let invocation = resolve_server_binary(&binary, &app)?;
let shell = app.shell(); let shell = app.shell();
match shell
.command(&bin) let rootdir_flag = format!(
// Tell Suwayomi where to put its data (rootDir flag). "-Dsuwayomi.tachidesk.config.server.rootDir={}",
data_dir.to_string_lossy()
);
// Build the full arg list: prefix_args (e.g. -jar foo.jar) + rootDir flag.
let args: Vec<String> = invocation.prefix_args.into_iter().chain(std::iter::once(rootdir_flag)).collect();
// On Windows, set the working directory to the bundle folder so javaw.exe
// can resolve the JRE and jar relative paths correctly.
let cmd = shell
.command(&invocation.bin)
.env("JAVA_TOOL_OPTIONS", "-Djava.awt.headless=true") .env("JAVA_TOOL_OPTIONS", "-Djava.awt.headless=true")
.args([&format!( .args(&args)
"-Dsuwayomi.tachidesk.config.server.rootDir={}", .current_dir(invocation.working_dir.unwrap_or_else(|| std::env::current_dir().unwrap_or_default()));
data_dir.to_string_lossy()
)]) match cmd.spawn() {
.spawn()
{
Ok((_rx, child)) => { Ok((_rx, child)) => {
println!("Spawned server: {:?}", bin); println!("Spawned server: {:?}", invocation.bin);
let mut guard = state.0.lock().unwrap(); let mut guard = state.0.lock().unwrap();
*guard = Some(child); *guard = Some(child);
Ok(()) Ok(())
} }
Err(e) => { Err(e) => {
eprintln!("Failed to spawn {:?}: {}", bin, e); eprintln!("Failed to spawn {:?}: {}", invocation.bin, e);
Err(e.to_string()) Err(e.to_string())
} }
} }
} }
#[tauri::command] #[tauri::command]
fn kill_server(app: tauri::AppHandle) -> Result<(), String> { fn kill_server(app: tauri::AppHandle) -> Result<(), String> {
kill_tachidesk(&app); kill_tachidesk(&app);