mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
Merge branch 'main' into patching
This commit is contained in:
@@ -23,9 +23,6 @@ mod metadata_patcher;
|
|||||||
static WATCH_GAME_PROCESS: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new(String::new()));
|
static WATCH_GAME_PROCESS: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new(String::new()));
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Start the game process watcher.
|
|
||||||
process_watcher();
|
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
enable_process_watcher,
|
enable_process_watcher,
|
||||||
@@ -63,16 +60,30 @@ fn main() {
|
|||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_watcher() {
|
#[tauri::command]
|
||||||
// Every 5 seconds, see if the game process is still running.
|
fn is_game_running() -> bool {
|
||||||
// If it is not, then we assume the game has closed and disable the proxy
|
// Grab the game process name
|
||||||
// to prevent any requests from being sent to the game.
|
let proc = WATCH_GAME_PROCESS.lock().unwrap().to_string();
|
||||||
|
|
||||||
// Start a thread so as to not block the main thread.
|
!proc.is_empty()
|
||||||
thread::spawn(|| {
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn enable_process_watcher(window: tauri::Window,process: String) {
|
||||||
|
*WATCH_GAME_PROCESS.lock().unwrap() = process;
|
||||||
|
|
||||||
|
window.listen("disable_process_watcher", |_e| {
|
||||||
|
*WATCH_GAME_PROCESS.lock().unwrap() = "".to_string();
|
||||||
|
});
|
||||||
|
|
||||||
|
println!("Starting process watcher...");
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
let mut system = System::new_all();
|
let mut system = System::new_all();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
thread::sleep(std::time::Duration::from_secs(5));
|
||||||
|
|
||||||
// Refresh system info
|
// Refresh system info
|
||||||
system.refresh_all();
|
system.refresh_all();
|
||||||
|
|
||||||
@@ -85,28 +96,18 @@ fn process_watcher() {
|
|||||||
|
|
||||||
// If the game process closes, disable the proxy.
|
// If the game process closes, disable the proxy.
|
||||||
if !exists {
|
if !exists {
|
||||||
|
println!("Game closed");
|
||||||
|
|
||||||
*WATCH_GAME_PROCESS.lock().unwrap() = "".to_string();
|
*WATCH_GAME_PROCESS.lock().unwrap() = "".to_string();
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread::sleep(std::time::Duration::from_secs(5));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn is_game_running() -> bool {
|
|
||||||
// Grab the game process name
|
|
||||||
let proc = WATCH_GAME_PROCESS.lock().unwrap().to_string();
|
|
||||||
|
|
||||||
!proc.is_empty()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn enable_process_watcher(process: String) {
|
|
||||||
*WATCH_GAME_PROCESS.lock().unwrap() = process;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn connect(port: u16, certificate_path: String) {
|
async fn connect(port: u16, certificate_path: String) {
|
||||||
// Log message to console.
|
// Log message to console.
|
||||||
|
|||||||
Reference in New Issue
Block a user