diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index bce3819..6ce91be 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -28,6 +28,10 @@ tauri-plugin-dialog = "2.3.3" tauri-plugin-notification = "2.3.1" sysinfo = "0.37.0" +[target.'cfg(target_os = "linux")'.dependencies] +shlex = "1.3.0" + [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] tauri-plugin-single-instance = "2.3.3" + diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7895468..c79ab29 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -177,8 +177,9 @@ async fn download( Ok(()) } +#[allow(unused_variables)] #[tauri::command] -fn launch_game(app: AppHandle, name: String, executable: String, wine: bool) { +fn launch_game(app: AppHandle, name: String, executable: String, wine: bool, wine_command: String) { let game_folder = app .path() .app_local_data_dir() @@ -195,33 +196,25 @@ fn launch_game(app: AppHandle, name: String, executable: String, wine: bool) { return; } let result = if wine && platform() == "linux" { - let wine_path_output = Command::new("which").arg("wine").output(); - let wine_path = match wine_path_output { - Ok(output) if output.status.success() => { - let path = String::from_utf8_lossy(&output.stdout).trim().to_string(); - if path.is_empty() { - app.dialog() - .message("Wine is not installed. Please install Wine to run this version of Berry Dash.") - .kind(MessageDialogKind::Error) - .title("Wine not found") - .show(|_| {}); - return; - } - path - } - _ => { - app.dialog() - .message("Wine is not installed. Please install Wine to run this version of Berry Dash.") - .kind(MessageDialogKind::Error) - .title("Wine not found") - .show(|_| {}); - return; - } - }; - Command::new(wine_path) - .arg(&game_path) - .current_dir(&game_folder) - .spawn() + #[cfg(target_os = "linux")] + { + let wine_cmd_to_use = + wine_command.replace("%path%", &format!("\"{}\"", game_path.to_string_lossy())); + + let parts = shlex::split(&wine_cmd_to_use).expect("failed to split command"); + let exe = &parts[0]; + let args = &parts[1..]; + + Command::new(exe) + .args(args) + .current_dir(&game_folder) + .spawn() + } + + #[cfg(not(target_os = "linux"))] + { + Err(std::io::Error::new(std::io::ErrorKind::Other, "not linux")) + } } else { if is_running_by_path(&game_path) { app.dialog() diff --git a/src/app/page.tsx b/src/app/page.tsx index 35370e8..ed3940e 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -100,26 +100,28 @@ export default function Installs () { onClick={async () => { let plat = platform() let willUseWine = false + let cfg = null + while (normalConfig != null) { + cfg = normalConfig + break + } if (plat === 'macos' || plat === 'linux') { if ( !entry.version.platforms.includes(plat) && entry.version.platforms.includes('windows') ) { - while (normalConfig != null) { - if ( - !normalConfig.settings.useWineOnUnixWhenNeeded - ) { - await message( - 'Wine support is disabled in settings and this version requires wine', - { - title: - 'Wine is needed to load this version', - kind: 'error' - } - ) - return - } - break + if ( + cfg != null && + !cfg.settings.useWineOnUnixWhenNeeded + ) { + await message( + 'Wine support is disabled in settings and this version requires wine', + { + title: 'Wine is needed to load this version', + kind: 'error' + } + ) + return } plat = 'windows' willUseWine = true @@ -131,7 +133,8 @@ export default function Installs () { entry.version.executables[ entry.version.platforms.indexOf(plat) ], - wine: willUseWine + wine: willUseWine, + wineCommand: cfg?.settings.wineOnUnixCommand }) }} >