Improve parts of launch/download logic

This commit is contained in:
2026-01-07 17:29:14 -07:00
parent e89b0fac8a
commit e0ba25da77

View File

@@ -19,8 +19,6 @@ use tokio::io::AsyncReadExt;
use tokio::{io::AsyncWriteExt, time::timeout}; use tokio::{io::AsyncWriteExt, time::timeout};
use zip::ZipArchive; use zip::ZipArchive;
#[cfg(target_os = "linux")]
use std::os::unix::fs::PermissionsExt;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use tauri_plugin_decorum::WebviewWindowExt; use tauri_plugin_decorum::WebviewWindowExt;
@@ -223,19 +221,14 @@ async fn download(
return "-1".to_string(); return "-1".to_string();
} }
#[cfg(target_os = "linux")] #[cfg(any(target_os = "linux", target_os = "macos"))]
{ {
let executable_path = game_path.join(&name).join(&executable); use std::{fs, os::unix::fs::PermissionsExt};
let mut perms = fs::metadata(&executable_path).unwrap().permissions();
perms.set_mode(0o755);
fs::set_permissions(executable_path, perms).unwrap();
}
#[cfg(target_os = "macos")]
{
use std::fs;
use std::os::unix::fs::PermissionsExt;
let macos_app_path = game_path let executable_path = if cfg!(target_os = "linux") {
game_path.join(&name).join(&executable)
} else {
game_path
.join(&name) .join(&name)
.join(&executable) .join(&executable)
.join("Contents") .join("Contents")
@@ -245,11 +238,12 @@ async fn download(
.chars() .chars()
.take(executable.chars().count() - 4) .take(executable.chars().count() - 4)
.collect::<String>(), .collect::<String>(),
); )
};
let mut perms = fs::metadata(&macos_app_path).unwrap().permissions(); let mut perms = fs::metadata(&executable_path).unwrap().permissions();
perms.set_mode(0o755); perms.set_mode(0o755);
fs::set_permissions(&macos_app_path, perms).unwrap(); fs::set_permissions(&executable_path, perms).unwrap();
} }
return "1".to_string(); return "1".to_string();
} }
@@ -263,41 +257,26 @@ fn launch_game(app: AppHandle, name: String, executable: String) {
.unwrap() .unwrap()
.join("game") .join("game")
.join(&name); .join(&name);
let game_path = game_folder.join(&executable); if !game_folder.exists() {
if !game_path.exists() {
app.dialog()
.message(
format!(
"Executable \"{}\" not found.\n\nTry reinstalling the game or make a support request in the Community link on the sidebar.",
game_path.display().to_string()
)
)
.kind(MessageDialogKind::Error)
.title("Game not found")
.show(|_| {});
return;
}
if is_running_by_path(&game_path) {
app.dialog()
.message(format!("The version {} is already running.", name))
.kind(MessageDialogKind::Error)
.title("Game already running")
.show(|_| {});
return; return;
} }
if platform() == "macos" { if platform() == "macos" {
Command::new("open") Command::new("open")
.arg(&game_path) .arg(&executable)
.current_dir(&game_folder) .current_dir(&game_folder)
.spawn() .spawn()
.unwrap(); .unwrap();
} else { } else if platform() == "linux" {
Command::new(&game_path) Command::new(format!("./{}", &executable))
.current_dir(&game_folder)
.spawn()
.unwrap();
} else if platform() == "windows" {
Command::new(&game_folder.join(&executable))
.current_dir(&game_folder) .current_dir(&game_folder)
.spawn() .spawn()
.unwrap(); .unwrap();
}
} }
#[tauri::command] #[tauri::command]