diff options
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r-- | src-tauri/src/main.rs | 87 |
1 files changed, 62 insertions, 25 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 50e439c8..3aa17459 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -10,15 +10,18 @@ use std::{ }; use app::{ - constants::{APP_USER_AGENT, MASTER_SERVER_URL, SERVER_BROWSER_ENDPOINT}, + constants::{APP_USER_AGENT, MASTER_SERVER_URL, REFRESH_DELAY, SERVER_BROWSER_ENDPOINT}, *, }; mod github; -use github::pull_requests::{apply_launcher_pr, apply_mods_pr, get_pull_requests_wrapper}; +use github::pull_requests::{ + apply_launcher_pr, apply_mods_pr, get_launcher_download_link, get_pull_requests_wrapper, +}; use github::release_notes::{ check_is_flightcore_outdated, get_newest_flightcore_version, get_northstar_release_notes, }; +use github::{compare_tags, get_list_of_tags}; mod repair_and_verify; use repair_and_verify::{ @@ -38,13 +41,20 @@ mod thunderstore; use thunderstore::query_thunderstore_packages_api; use tauri::{Manager, Runtime}; -use tauri_plugin_store::PluginBuilder; use tokio::time::sleep; #[derive(Default)] struct Counter(Arc<Mutex<i32>>); fn main() { + // Setup logger + let mut log_builder = pretty_env_logger::formatted_builder(); + log_builder.parse_filters("info"); + let logger = sentry_log::SentryLogger::with_dest(log_builder.build()); + + log::set_boxed_logger(Box::new(logger)).unwrap(); + log::set_max_level(log::LevelFilter::Info); + // Only enable Sentry crash logs on release #[cfg(not(debug_assertions))] let _guard = sentry::init(( @@ -57,7 +67,7 @@ fn main() { )); tauri::Builder::default() - .plugin(PluginBuilder::default().build()) + .plugin(tauri_plugin_store::Builder::default().build()) .setup(|app| { let app_handle = app.app_handle(); tauri::async_runtime::spawn(async move { @@ -86,6 +96,17 @@ fn main() { } }); + // Emit updated player and server count to GUI + let app_handle = app.app_handle(); + tauri::async_runtime::spawn(async move { + loop { + sleep(REFRESH_DELAY).await; + app_handle + .emit_all("northstar-statistics", get_server_player_count().await) + .unwrap(); + } + }); + Ok(()) }) .manage(Counter(Default::default())) @@ -100,6 +121,7 @@ fn main() { install_northstar_caller, update_northstar_caller, launch_northstar_caller, + launch_northstar_steam_caller, check_is_flightcore_outdated_caller, get_log_list, verify_game_files, @@ -117,9 +139,12 @@ fn main() { delete_thunderstore_mod, open_repair_window, query_thunderstore_packages_api, + get_list_of_tags, + compare_tags, get_pull_requests_wrapper, apply_launcher_pr, apply_mods_pr, + get_launcher_download_link, close_application, ]) .run(tauri::generate_context!()) @@ -142,7 +167,7 @@ fn force_panic() { #[tauri::command] /// Returns true if built in debug mode async fn is_debug_mode() -> bool { - return cfg!(debug_assertions); + cfg!(debug_assertions) } #[tauri::command] @@ -177,7 +202,7 @@ async fn get_flightcore_version_number() -> String { #[tauri::command] async fn get_northstar_version_number_caller(game_path: String) -> Result<String, String> { - match get_northstar_version_number(game_path) { + match get_northstar_version_number(&game_path) { Ok(version_number) => Ok(version_number), Err(err) => Err(err.to_string()), } @@ -209,10 +234,10 @@ async fn check_is_northstar_outdated( .expect("Couldn't find Northstar on thunderstore???"); // .ok_or_else(|| anyhow!("Couldn't find Northstar on thunderstore???"))?; - let version_number = match get_northstar_version_number(game_path) { + let version_number = match get_northstar_version_number(&game_path) { Ok(version_number) => version_number, Err(err) => { - println!("{}", err); + log::warn!("{}", err); // If we fail to get new version just assume we are up-to-date return Err(err.to_string()); } @@ -222,10 +247,10 @@ async fn check_is_northstar_outdated( let version_number = convert_release_candidate_number(version_number); if version_number != nmod.latest { - println!("Installed Northstar version outdated"); + log::info!("Installed Northstar version outdated"); Ok(true) } else { - println!("Installed Northstar version up-to-date"); + log::info!("Installed Northstar version up-to-date"); Ok(false) } } @@ -244,7 +269,7 @@ async fn verify_install_location(game_path: String) -> bool { match check_is_valid_game_path(&game_path) { Ok(()) => true, Err(err) => { - println!("{}", err); + log::warn!("{}", err); false } } @@ -259,15 +284,16 @@ async fn get_host_os_caller() -> String { #[tauri::command] /// Installs Northstar to the given path async fn install_northstar_caller( + window: tauri::Window, game_path: String, northstar_package_name: Option<String>, ) -> Result<bool, String> { - println!("Running"); - match install_northstar(&game_path, northstar_package_name).await { + log::info!("Running"); + match install_northstar(window, &game_path, northstar_package_name).await { Ok(_) => Ok(true), Err(err) => { - println!("{}", err); - Err(err.to_string()) + log::error!("{}", err); + Err(err) } } } @@ -275,17 +301,18 @@ async fn install_northstar_caller( #[tauri::command] /// Update Northstar install in the given path async fn update_northstar_caller( + window: tauri::Window, game_path: String, northstar_package_name: Option<String>, ) -> Result<bool, String> { - println!("Updating"); + log::info!("Updating Northstar"); // Simply re-run install with up-to-date version for upate - match install_northstar(&game_path, northstar_package_name).await { + match install_northstar(window, &game_path, northstar_package_name).await { Ok(_) => Ok(true), Err(err) => { - println!("{}", err); - Err(err.to_string()) + log::error!("{}", err); + Err(err) } } } @@ -296,7 +323,16 @@ async fn launch_northstar_caller( game_install: GameInstall, bypass_checks: Option<bool>, ) -> Result<String, String> { - launch_northstar(game_install, bypass_checks) + launch_northstar(&game_install, bypass_checks) +} + +#[tauri::command] +/// Launches Northstar +async fn launch_northstar_steam_caller( + game_install: GameInstall, + bypass_checks: Option<bool>, +) -> Result<String, String> { + launch_northstar_steam(&game_install, bypass_checks) } #[tauri::command] @@ -305,11 +341,11 @@ async fn install_mod_caller( game_install: GameInstall, thunderstore_mod_string: String, ) -> Result<(), String> { - fc_download_mod_and_install(game_install.clone(), thunderstore_mod_string).await?; - match clean_up_download_folder(game_install, false) { + fc_download_mod_and_install(&game_install, &thunderstore_mod_string).await?; + match clean_up_download_folder(&game_install, false) { Ok(()) => Ok(()), Err(err) => { - println!("Failed to delete download folder due to {}", err); + log::info!("Failed to delete download folder due to {}", err); // Failure to delete download folder is not an error in mod install // As such ignore. User can still force delete if need be Ok(()) @@ -323,7 +359,7 @@ async fn clean_up_download_folder_caller( game_install: GameInstall, force: bool, ) -> Result<(), String> { - match clean_up_download_folder(game_install, force) { + match clean_up_download_folder(&game_install, force) { Ok(()) => Ok(()), Err(err) => Err(err.to_string()), } @@ -353,7 +389,8 @@ async fn get_server_player_count() -> Result<(i32, usize), String> { // Sum up player count let total_player_count: i32 = ns_servers.iter().map(|server| server.player_count).sum(); - dbg!((total_player_count, server_count)); + log::info!("total_player_count: {}", total_player_count); + log::info!("server_count: {}", server_count); Ok((total_player_count, server_count)) } |