Bring back this, either works or doesn't on linux and windows. I will have to test
This commit is contained in:
@@ -22,14 +22,18 @@ use zip::ZipArchive;
|
|||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use tauri_plugin_decorum::WebviewWindowExt;
|
use tauri_plugin_decorum::WebviewWindowExt;
|
||||||
|
|
||||||
fn is_running_by_path(path: &PathBuf) -> bool {
|
#[allow(unused)]
|
||||||
|
fn is_running_by_path(path: &Path) -> bool {
|
||||||
let sys = System::new_all();
|
let sys = System::new_all();
|
||||||
sys.processes().values().any(|proc| {
|
let target = path.canonicalize().ok();
|
||||||
if let Some(exe) = proc.exe() {
|
if target.is_none() {
|
||||||
exe == path
|
return false;
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
let target = target.unwrap();
|
||||||
|
sys.processes().values().any(|proc| {
|
||||||
|
proc.exe()
|
||||||
|
.and_then(|exe| exe.canonicalize().ok())
|
||||||
|
.map_or(false, |exe| exe == target)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,12 +249,13 @@ async fn download(
|
|||||||
perms.set_mode(0o755);
|
perms.set_mode(0o755);
|
||||||
fs::set_permissions(&executable_path, perms).unwrap();
|
fs::set_permissions(&executable_path, perms).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "1".to_string();
|
return "1".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn launch_game(app: AppHandle, name: String, executable: String) {
|
fn launch_game(app: AppHandle, name: String, executable: String, display_name: String) {
|
||||||
let game_folder = app
|
let game_folder = app
|
||||||
.path()
|
.path()
|
||||||
.app_local_data_dir()
|
.app_local_data_dir()
|
||||||
@@ -261,6 +266,21 @@ fn launch_game(app: AppHandle, name: String, executable: String) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if already running on macos, it'll auto take the user to that proccess
|
||||||
|
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||||
|
{
|
||||||
|
if is_running_by_path(&game_folder.join(&executable)) {
|
||||||
|
app.dialog()
|
||||||
|
.message(format!(
|
||||||
|
"{} is already running, if this doesn't seem true, try to kill the proccess.",
|
||||||
|
display_name
|
||||||
|
))
|
||||||
|
.kind(MessageDialogKind::Error)
|
||||||
|
.title("Game already running")
|
||||||
|
.show(|_| {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if platform() == "macos" {
|
if platform() == "macos" {
|
||||||
Command::new("open")
|
Command::new("open")
|
||||||
.arg(&executable)
|
.arg(&executable)
|
||||||
@@ -277,24 +297,6 @@ fn launch_game(app: AppHandle, name: String, executable: String) {
|
|||||||
.current_dir(&game_folder)
|
.current_dir(&game_folder)
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
async fn uninstall_version(app: AppHandle, name: String) {
|
|
||||||
let game_path = app
|
|
||||||
.path()
|
|
||||||
.app_local_data_dir()
|
|
||||||
.unwrap()
|
|
||||||
.join("game")
|
|
||||||
.join(&name);
|
|
||||||
if game_path.exists() {
|
|
||||||
if let Err(_) = tokio::fs::remove_dir_all(&game_path).await {
|
|
||||||
app.emit("version-failed", &name).unwrap();
|
|
||||||
} else {
|
|
||||||
app.emit("version-uninstalled", &name).unwrap();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
app.emit("version-uninstalled", &name).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,7 +344,6 @@ pub fn run() {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
download,
|
download,
|
||||||
launch_game,
|
launch_game,
|
||||||
uninstall_version,
|
|
||||||
open_folder,
|
open_folder,
|
||||||
folder_size
|
folder_size
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -91,9 +91,12 @@ export default function Installs () {
|
|||||||
if (normalConfig?.settings.useLegacyInteractButtons) return
|
if (normalConfig?.settings.useLegacyInteractButtons) return
|
||||||
const verInfo = getVersionInfo(entry)
|
const verInfo = getVersionInfo(entry)
|
||||||
if (verInfo == undefined) return
|
if (verInfo == undefined) return
|
||||||
|
const gameInfo = getGameInfo(verInfo.game)
|
||||||
|
if (gameInfo == undefined) return
|
||||||
invoke('launch_game', {
|
invoke('launch_game', {
|
||||||
name: verInfo.id,
|
name: verInfo.id,
|
||||||
executable: verInfo.executable
|
executable: verInfo.executable,
|
||||||
|
displayName: `${gameInfo.name} v${verInfo.versionName}`
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
onMouseEnter={() => setHoveredIds(prev => [...prev, entry])}
|
onMouseEnter={() => setHoveredIds(prev => [...prev, entry])}
|
||||||
|
|||||||
Reference in New Issue
Block a user