diff options
author | Jan <sentrycraft123@gmail.com> | 2023-07-19 02:06:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-19 02:06:38 +0200 |
commit | 8e733e5127463073aa90c566afdb5c242af64aa0 (patch) | |
tree | 045e63a1343602a37b16bc15a2cefdde5c81243f | |
parent | 2153cb606e3c811c9ab36c4a10132f7166a51054 (diff) | |
download | FlightCore-8e733e5127463073aa90c566afdb5c242af64aa0.tar.gz FlightCore-8e733e5127463073aa90c566afdb5c242af64aa0.zip |
feat: Replace MessageBoxW invocation with Tauri dialog (#418)
-rw-r--r-- | src-tauri/Cargo.toml | 2 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 36 |
2 files changed, 15 insertions, 23 deletions
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 63ff51f7..443a997b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -23,7 +23,7 @@ tauri-build = { version = "1.4", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.4", features = ["api-all", "updater"] } +tauri = { version = "1.4", features = ["api-all", "dialog", "updater"] } tokio = { version = "1", features = ["full"] } # Sentry (crash) logging sentry = "0.30" diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a295f322..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; @@ -175,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(); } } } |