[desktop/tauri] Add check if webview is installed

This commit is contained in:
Vladimir Stoilov 2024-05-31 10:35:52 +03:00
parent 31b99e7647
commit f07f4e6988
No known key found for this signature in database
GPG key ID: 2F190B67A43A81AF

View file

@ -1,6 +1,8 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::time::Duration;
use tauri::{AppHandle, Manager, RunEvent, WindowEvent};
use tauri_plugin_cli::CliExt;
@ -24,6 +26,8 @@ use window::{close_splash_window, create_main_window};
#[macro_use]
extern crate lazy_static;
const FALLBACK_TO_OLD_UI_EXIT_CODE: i32 = -3;
#[derive(Clone, serde::Serialize)]
struct Payload {
args: Vec<String>,
@ -82,7 +86,34 @@ impl portmaster::Handler for WsHandler {
}
}
fn show_webview_not_installed_dialog() -> i32 {
use rfd::MessageDialog;
let result = MessageDialog::new()
.set_title("Portmaster")
.set_description("Webkit is not installed. Please install it and run portmaster again")
.set_buttons(rfd::MessageButtons::OkCancelCustom(
"Go to install page".to_owned(),
"Use old UI".to_owned(),
))
.show();
println!("{:?}", result);
if let rfd::MessageDialogResult::Custom(result) = result {
if result.eq("Go to install page") {
_ = open::that("https://wiki.safing.io/en/Portmaster/Install/Webview");
std::thread::sleep(Duration::from_secs(2));
return 0;
}
}
return FALLBACK_TO_OLD_UI_EXIT_CODE;
}
fn main() {
if let Err(_) = tauri::webview_version() {
std::process::exit(show_webview_not_installed_dialog());
}
let app = tauri::Builder::default()
// Shell plugin for open_external support
.plugin(tauri_plugin_shell::init())