Make it so only one instance can be loaded
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
"@fortawesome/fontawesome-svg-core": "7.0.0",
|
||||
"@fortawesome/free-brands-svg-icons": "7.0.0",
|
||||
"@fortawesome/free-solid-svg-icons": "7.0.0",
|
||||
"@fortawesome/react-fontawesome": "0.2.2",
|
||||
"@fortawesome/react-fontawesome": "0.2.3",
|
||||
"@tailwindcss/postcss": "4.1.11",
|
||||
"@tauri-apps/cli": "2.7.1",
|
||||
"@types/crypto-js": "4.2.2",
|
||||
|
||||
@@ -26,6 +26,7 @@ zip = "4.3.0"
|
||||
libc = "0.2.174"
|
||||
tauri-plugin-dialog = "2.3.1"
|
||||
tauri-plugin-notification = "2.3.0"
|
||||
sysinfo = "0.36.1"
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-single-instance = "2.3.2"
|
||||
|
||||
@@ -10,6 +10,7 @@ use std::{
|
||||
process::Command,
|
||||
time::Duration,
|
||||
};
|
||||
use sysinfo::System;
|
||||
use tauri::{AppHandle, Emitter, Manager};
|
||||
use tauri_plugin_dialog::{DialogExt, MessageDialogKind};
|
||||
use tauri_plugin_opener::OpenerExt;
|
||||
@@ -48,6 +49,17 @@ pub async fn unzip_to_dir(zip_path: PathBuf, out_dir: PathBuf) -> zip::result::Z
|
||||
.map_err(|e| zip::result::ZipError::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))?
|
||||
}
|
||||
|
||||
fn is_running_by_path(path: &PathBuf) -> bool {
|
||||
let sys = System::new_all();
|
||||
sys.processes().values().any(|proc| {
|
||||
if let Some(exe) = proc.exe() {
|
||||
exe == path
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[tauri::command]
|
||||
async fn download(
|
||||
@@ -192,6 +204,14 @@ fn launch_game(app: AppHandle, name: String, executable: String, wine: bool) {
|
||||
.current_dir(&game_folder)
|
||||
.spawn()
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
Command::new(&game_path).current_dir(&game_folder).spawn()
|
||||
};
|
||||
|
||||
|
||||
14
yarn.lock
14
yarn.lock
@@ -356,10 +356,10 @@
|
||||
dependencies:
|
||||
"@fortawesome/fontawesome-common-types" "7.0.0"
|
||||
|
||||
"@fortawesome/react-fontawesome@0.2.2":
|
||||
version "0.2.2"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/react-fontawesome/-/react-fontawesome-0.2.2.tgz#68b058f9132b46c8599875f6a636dad231af78d4"
|
||||
integrity sha512-EnkrprPNqI6SXJl//m29hpaNzOp1bruISWaOiRtkMi/xSvHJlzc2j2JAYS7egxt/EbjSNV/k6Xy0AQI6vB2+1g==
|
||||
"@fortawesome/react-fontawesome@0.2.3":
|
||||
version "0.2.3"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/react-fontawesome/-/react-fontawesome-0.2.3.tgz#bde1bc0fd67693e140d5d21b2e4f6faea8aae657"
|
||||
integrity sha512-HlJco8RDY8NrzFVjy23b/7mNS4g9NegcrBG3n7jinwpc2x/AmSVk53IhWniLYM4szYLxRAFTAGwGn0EIlclDeQ==
|
||||
dependencies:
|
||||
prop-types "^15.8.1"
|
||||
|
||||
@@ -1077,9 +1077,9 @@ hasown@^2.0.2:
|
||||
function-bind "^1.1.2"
|
||||
|
||||
jiti@^2.4.2:
|
||||
version "2.4.2"
|
||||
resolved "https://registry.yarnpkg.com/jiti/-/jiti-2.4.2.tgz#d19b7732ebb6116b06e2038da74a55366faef560"
|
||||
integrity sha512-rg9zJN+G4n2nfJl5MW3BMygZX56zKPNVEYYqq7adpmMh4Jn2QNEwhvQlFy6jPVdcod7txZtKHWnyZiA3a0zP7A==
|
||||
version "2.5.0"
|
||||
resolved "https://registry.yarnpkg.com/jiti/-/jiti-2.5.0.tgz#6e0f6c7d7fc7581312050072775dcb9e005caf15"
|
||||
integrity sha512-NWDAhdnATItTnRhip9VTd8oXDjVcbhetRN6YzckApnXGxpGUooKMAaf0KVvlZG0+KlJMGkeLElVn4M1ReuxKUQ==
|
||||
|
||||
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
|
||||
version "4.0.0"
|
||||
|
||||
Reference in New Issue
Block a user