aboutsummaryrefslogtreecommitdiff
path: root/src-tauri
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-05-01 03:06:10 +0200
committerGitHub <noreply@github.com>2023-05-01 03:06:10 +0200
commitd00c49812af54121867eb1835f9d25e44d16c109 (patch)
treea7eccc74159588fd5b3ca97867a75b0a594dc6a3 /src-tauri
parent06754cc2f63468a6a1945357918428fd9707cd91 (diff)
downloadFlightCore-d00c49812af54121867eb1835f9d25e44d16c109.tar.gz
FlightCore-d00c49812af54121867eb1835f9d25e44d16c109.zip
feat: Show error message if WebView2 not installed (#285)
* feat: Show error message if WebView2 not installed on Windows * fix: Add missing dependency * fix: Do not import lib on OS where not needed Don't need to import Windows lib on Linux * feat: Link to troubleshooting page directly * chore: Update comments * docs: Show error message in troubleshooting guide Show the "WebView2 not installed" error message in the troubleshooting guide * fix: Resolve clippy error * fix: Resolve clippy error (again)
Diffstat (limited to 'src-tauri')
-rw-r--r--src-tauri/Cargo.lock1
-rw-r--r--src-tauri/Cargo.toml2
-rw-r--r--src-tauri/src/main.rs44
3 files changed, 45 insertions, 2 deletions
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 5c0285da..960039ad 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -112,6 +112,7 @@ dependencies = [
"tauri-plugin-store",
"tokio",
"ts-rs",
+ "winapi",
"zip",
"zip-extract",
]
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 0f68a560..0f65d665 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -64,6 +64,8 @@ log = "0.4.17"
zip-extract = "0.1.2"
# open urls
open = "3.2.0"
+# Windows API stuff
+winapi = "0.3.9"
[features]
# by default Tauri runs in production mode
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 3aa17459..2e4b3370 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -9,6 +9,11 @@ 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 app::{
constants::{APP_USER_AGENT, MASTER_SERVER_URL, REFRESH_DELAY, SERVER_BROWSER_ENDPOINT},
*,
@@ -66,7 +71,7 @@ fn main() {
},
));
- tauri::Builder::default()
+ match tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let app_handle = app.app_handle();
@@ -148,7 +153,42 @@ fn main() {
close_application,
])
.run(tauri::generate_context!())
- .expect("error while running tauri application");
+ {
+ Ok(()) => (),
+ Err(err) => {
+ // Failed to launch system native web view
+
+ // Log error on Linux
+ #[cfg(not(target_os = "windows"))]
+ {
+ log::error!("{err}");
+ }
+
+ // On Windows we can show an error window using Windows API to show how to install WebView2
+ #[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();
+ }
+ }
+ }
+ }
+ };
}
#[tauri::command]