diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-07-20 00:47:27 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-07-20 00:47:27 +0200 |
commit | 5f3dcdedbb0281cd52ec372c647f9b2ce4f860b7 (patch) | |
tree | 72e3ca3bfa8a536967c6b905704287ce2a1e4b2c /src-tauri/src/main.rs | |
parent | 6d0d813c9af9fb43e2732652c5ec14d914dcea42 (diff) | |
parent | 29837bfe678dad64f01d6f6be69d43d659f402ae (diff) | |
download | FlightCore-5f3dcdedbb0281cd52ec372c647f9b2ce4f860b7.tar.gz FlightCore-5f3dcdedbb0281cd52ec372c647f9b2ce4f860b7.zip |
Merge branch 'main' into feat/install-packages
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r-- | src-tauri/src/main.rs | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a584eea9..1067f5d3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,11 +9,6 @@ use std::{ time::Duration, }; -#[cfg(target_os = "windows")] -use std::ptr::null_mut; -#[cfg(target_os = "windows")] -use winapi::um::winuser::{MessageBoxW, MB_ICONERROR, MB_OK, MB_USERICON}; - use crate::constants::REFRESH_DELAY; mod development; @@ -26,6 +21,10 @@ mod util; use semver::Version; use serde::{Deserialize, Serialize}; +#[cfg(target_os = "windows")] +use tauri::api::dialog::blocking::MessageDialogBuilder; +#[cfg(target_os = "windows")] +use tauri::api::dialog::{MessageDialogButtons, MessageDialogKind}; use tauri::{Manager, Runtime}; use tokio::time::sleep; use ts_rs::TS; @@ -144,6 +143,9 @@ fn main() { mod_management::delete_northstar_mod, util::get_server_player_count, mod_management::delete_thunderstore_mod, + install_northstar_proton_wrapper, + uninstall_northstar_proton_wrapper, + get_local_northstar_proton_wrapper_version, open_repair_window, thunderstore::query_thunderstore_packages_api, github::get_list_of_tags, @@ -172,23 +174,16 @@ fn main() { #[cfg(target_os = "windows")] { log::error!("WebView2 not installed: {err}"); - // Display a message box to the user with a button to open the installation instructions - let title = "WebView2 not found" - .encode_utf16() - .chain(Some(0)) - .collect::<Vec<_>>(); - let message = "FlightCore requires WebView2 to run.\n\nClick OK to open installation instructions.".encode_utf16().chain(Some(0)).collect::<Vec<_>>(); - unsafe { - let result = MessageBoxW( - null_mut(), - message.as_ptr(), - title.as_ptr(), - MB_OK | MB_ICONERROR | MB_USERICON, - ); - if result == 1 { - // Open the installation instructions URL in the user's default web browser - open::that("https://github.com/R2NorthstarTools/FlightCore/blob/main/docs/TROUBLESHOOTING.md#flightcore-wont-launch").unwrap(); - } + let dialog = MessageDialogBuilder::new( + "WebView2 not found", + "FlightCore requires WebView2 to run.\n\nClick OK to open installation instructions." + ) + .kind(MessageDialogKind::Error) + .buttons(MessageDialogButtons::Ok); + + if dialog.show() { + // Open the installation instructions URL in the user's default web browser + open::that("https://github.com/R2NorthstarTools/FlightCore/blob/main/docs/TROUBLESHOOTING.md#flightcore-wont-launch").unwrap(); } } } @@ -525,3 +520,32 @@ pub fn check_is_valid_game_path(game_install_path: &str) -> Result<(), String> { fn get_host_os() -> String { env::consts::OS.to_string() } + +/// On Linux attempts to install NorthstarProton +/// On Windows simply returns an error message +#[tauri::command] +async fn install_northstar_proton_wrapper() -> Result<(), String> { + #[cfg(target_os = "linux")] + return linux::install_ns_proton().map_err(|err| err.to_string()); + + #[cfg(target_os = "windows")] + Err("Not supported on Windows".to_string()) +} + +#[tauri::command] +async fn uninstall_northstar_proton_wrapper() -> Result<(), String> { + #[cfg(target_os = "linux")] + return linux::uninstall_ns_proton(); + + #[cfg(target_os = "windows")] + Err("Not supported on Windows".to_string()) +} + +#[tauri::command] +async fn get_local_northstar_proton_wrapper_version() -> Result<String, String> { + #[cfg(target_os = "linux")] + return linux::get_local_ns_proton_version(); + + #[cfg(target_os = "windows")] + Err("Not supported on Windows".to_string()) +} |