From f07f4e698802ff9936f0581cb21c0eb14943d318 Mon Sep 17 00:00:00 2001 From: Vladimir Stoilov Date: Fri, 31 May 2024 10:35:52 +0300 Subject: [PATCH] [desktop/tauri] Add check if webview is installed --- desktop/tauri/src-tauri/src/main.rs | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/desktop/tauri/src-tauri/src/main.rs b/desktop/tauri/src-tauri/src/main.rs index fc9b8540..5c11e2e9 100644 --- a/desktop/tauri/src-tauri/src/main.rs +++ b/desktop/tauri/src-tauri/src/main.rs @@ -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, @@ -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())