[desktop] Improve tauri traymenu
This commit is contained in:
191
desktop/tauri/src-tauri/Cargo.lock
generated
191
desktop/tauri/src-tauri/Cargo.lock
generated
@@ -225,6 +225,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"notify-rust",
|
"notify-rust",
|
||||||
|
"reqwest 0.12.4",
|
||||||
"rust-ini",
|
"rust-ini",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -1257,7 +1258,7 @@ dependencies = [
|
|||||||
"cocoa-foundation",
|
"cocoa-foundation",
|
||||||
"core-foundation",
|
"core-foundation",
|
||||||
"core-graphics",
|
"core-graphics",
|
||||||
"foreign-types",
|
"foreign-types 0.5.0",
|
||||||
"libc",
|
"libc",
|
||||||
"objc",
|
"objc",
|
||||||
]
|
]
|
||||||
@@ -1399,7 +1400,7 @@ dependencies = [
|
|||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"core-foundation",
|
"core-foundation",
|
||||||
"core-graphics-types",
|
"core-graphics-types",
|
||||||
"foreign-types",
|
"foreign-types 0.5.0",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2354,6 +2355,15 @@ dependencies = [
|
|||||||
"ttf-parser",
|
"ttf-parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foreign-types"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||||
|
dependencies = [
|
||||||
|
"foreign-types-shared 0.1.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types"
|
name = "foreign-types"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -2361,7 +2371,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
|
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"foreign-types-macros",
|
"foreign-types-macros",
|
||||||
"foreign-types-shared",
|
"foreign-types-shared 0.3.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2375,6 +2385,12 @@ dependencies = [
|
|||||||
"syn 2.0.65",
|
"syn 2.0.65",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foreign-types-shared"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types-shared"
|
name = "foreign-types-shared"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@@ -2935,6 +2951,25 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "h2"
|
||||||
|
version = "0.4.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab"
|
||||||
|
dependencies = [
|
||||||
|
"atomic-waker",
|
||||||
|
"bytes",
|
||||||
|
"fnv",
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
"http 1.1.0",
|
||||||
|
"indexmap 2.2.6",
|
||||||
|
"slab",
|
||||||
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "half"
|
name = "half"
|
||||||
version = "2.4.1"
|
version = "2.4.1"
|
||||||
@@ -3150,7 +3185,7 @@ dependencies = [
|
|||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"h2",
|
"h2 0.3.26",
|
||||||
"http 0.2.12",
|
"http 0.2.12",
|
||||||
"http-body 0.4.6",
|
"http-body 0.4.6",
|
||||||
"httparse",
|
"httparse",
|
||||||
@@ -3173,6 +3208,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"h2 0.4.5",
|
||||||
"http 1.1.0",
|
"http 1.1.0",
|
||||||
"http-body 1.0.0",
|
"http-body 1.0.0",
|
||||||
"httparse",
|
"httparse",
|
||||||
@@ -3184,6 +3220,22 @@ dependencies = [
|
|||||||
"want",
|
"want",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper-tls"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"http-body-util",
|
||||||
|
"hyper 1.3.1",
|
||||||
|
"hyper-util",
|
||||||
|
"native-tls",
|
||||||
|
"tokio",
|
||||||
|
"tokio-native-tls",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper-util"
|
name = "hyper-util"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
@@ -4139,6 +4191,24 @@ dependencies = [
|
|||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "native-tls"
|
||||||
|
version = "0.2.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"openssl",
|
||||||
|
"openssl-probe",
|
||||||
|
"openssl-sys",
|
||||||
|
"schannel",
|
||||||
|
"security-framework",
|
||||||
|
"security-framework-sys",
|
||||||
|
"tempfile",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ndk"
|
name = "ndk"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@@ -4603,6 +4673,50 @@ dependencies = [
|
|||||||
"pathdiff",
|
"pathdiff",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl"
|
||||||
|
version = "0.10.64"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.5.0",
|
||||||
|
"cfg-if",
|
||||||
|
"foreign-types 0.3.2",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"openssl-macros",
|
||||||
|
"openssl-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-macros"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.65",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-probe"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-sys"
|
||||||
|
version = "0.9.102"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ordered-float"
|
name = "ordered-float"
|
||||||
version = "2.10.1"
|
version = "2.10.1"
|
||||||
@@ -5531,7 +5645,7 @@ dependencies = [
|
|||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"h2",
|
"h2 0.3.26",
|
||||||
"http 0.2.12",
|
"http 0.2.12",
|
||||||
"http-body 0.4.6",
|
"http-body 0.4.6",
|
||||||
"hyper 0.14.28",
|
"hyper 0.14.28",
|
||||||
@@ -5564,25 +5678,32 @@ checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"encoding_rs",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"h2 0.4.5",
|
||||||
"http 1.1.0",
|
"http 1.1.0",
|
||||||
"http-body 1.0.0",
|
"http-body 1.0.0",
|
||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper 1.3.1",
|
"hyper 1.3.1",
|
||||||
|
"hyper-tls",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"ipnet",
|
"ipnet",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"mime",
|
"mime",
|
||||||
|
"native-tls",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"rustls-pemfile",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"sync_wrapper 0.1.2",
|
"sync_wrapper 0.1.2",
|
||||||
|
"system-configuration",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-native-tls",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"url",
|
"url",
|
||||||
@@ -5889,6 +6010,16 @@ dependencies = [
|
|||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-pemfile"
|
||||||
|
version = "2.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d"
|
||||||
|
dependencies = [
|
||||||
|
"base64 0.22.1",
|
||||||
|
"rustls-pki-types",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls-pki-types"
|
name = "rustls-pki-types"
|
||||||
version = "1.7.0"
|
version = "1.7.0"
|
||||||
@@ -5952,6 +6083,15 @@ dependencies = [
|
|||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "schannel"
|
||||||
|
version = "0.1.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schemars"
|
name = "schemars"
|
||||||
version = "0.8.20"
|
version = "0.8.20"
|
||||||
@@ -6021,6 +6161,29 @@ dependencies = [
|
|||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "security-framework"
|
||||||
|
version = "2.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.5.0",
|
||||||
|
"core-foundation",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"libc",
|
||||||
|
"security-framework-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "security-framework-sys"
|
||||||
|
version = "2.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7"
|
||||||
|
dependencies = [
|
||||||
|
"core-foundation-sys",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "selectors"
|
name = "selectors"
|
||||||
version = "0.22.0"
|
version = "0.22.0"
|
||||||
@@ -6407,7 +6570,7 @@ dependencies = [
|
|||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cfg_aliases 0.2.1",
|
"cfg_aliases 0.2.1",
|
||||||
"core-graphics",
|
"core-graphics",
|
||||||
"foreign-types",
|
"foreign-types 0.5.0",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"objc2",
|
"objc2",
|
||||||
@@ -7633,6 +7796,16 @@ dependencies = [
|
|||||||
"syn 2.0.65",
|
"syn 2.0.65",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-native-tls"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
|
||||||
|
dependencies = [
|
||||||
|
"native-tls",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-rustls"
|
name = "tokio-rustls"
|
||||||
version = "0.25.0"
|
version = "0.25.0"
|
||||||
@@ -8238,6 +8411,12 @@ dependencies = [
|
|||||||
"sval_serde",
|
"sval_serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vcpkg"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ http = "1.0.0"
|
|||||||
url = "2.5.0"
|
url = "2.5.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
log = "0.4.21"
|
log = "0.4.21"
|
||||||
|
reqwest = { version = "0.12" }
|
||||||
|
|
||||||
# Linux only
|
# Linux only
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ use serde;
|
|||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use tauri::{AppHandle, Manager, Runtime};
|
use tauri::{AppHandle, Manager, Runtime};
|
||||||
|
|
||||||
|
const PORTMASTER_BASE_URL: &'static str = "http://127.0.0.1:817/api/v1/";
|
||||||
|
|
||||||
pub trait Handler {
|
pub trait Handler {
|
||||||
fn on_connect(&mut self, cli: PortAPI) -> ();
|
fn on_connect(&mut self, cli: PortAPI) -> ();
|
||||||
fn on_disconnect(&mut self);
|
fn on_disconnect(&mut self);
|
||||||
@@ -203,6 +205,25 @@ impl<R: Runtime> PortmasterInterface<R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send Shutdown request to portmaster
|
||||||
|
pub fn trigger_shutdown(&self) {
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
match client
|
||||||
|
.post(format!("{}core/shutdown", PORTMASTER_BASE_URL))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(v) => {
|
||||||
|
debug!("shutdown request sent {:?}", v);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!("failed to send shutdown request {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//// Internal functions
|
//// Internal functions
|
||||||
fn start_notification_handler(&self) {
|
fn start_notification_handler(&self) {
|
||||||
if let Some(api) = self.get_api() {
|
if let Some(api) = self.get_api() {
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
use std::collections::HashMap;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
use std::{collections::HashMap, sync::atomic::Ordering};
|
||||||
|
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use tauri::{
|
use tauri::{
|
||||||
image::Image,
|
image::Image,
|
||||||
menu::{
|
menu::{MenuBuilder, MenuItem, MenuItemBuilder, PredefinedMenuItem, SubmenuBuilder},
|
||||||
CheckMenuItem, CheckMenuItemBuilder, MenuBuilder, MenuItemBuilder, PredefinedMenuItem,
|
|
||||||
SubmenuBuilder,
|
|
||||||
},
|
|
||||||
tray::{ClickType, TrayIcon, TrayIconBuilder},
|
tray::{ClickType, TrayIcon, TrayIconBuilder},
|
||||||
Wry,
|
Wry,
|
||||||
};
|
};
|
||||||
@@ -30,9 +28,12 @@ use tauri_plugin_dialog::DialogExt;
|
|||||||
|
|
||||||
pub type AppIcon = TrayIcon<Wry>;
|
pub type AppIcon = TrayIcon<Wry>;
|
||||||
|
|
||||||
|
static SPN_STATE: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
// Set once setup_tray_menu executed.
|
static ref SPN_STATUS: Mutex<Option<MenuItem<Wry>>> = Mutex::new(None);
|
||||||
static ref SPN_BUTTON: Mutex<Option<CheckMenuItem<Wry>>> = Mutex::new(None);
|
static ref SPN_BUTTON: Mutex<Option<MenuItem<Wry>>> = Mutex::new(None);
|
||||||
|
static ref GLOBAL_STATUS: Mutex<Option<MenuItem<Wry>>> = Mutex::new(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
const PM_TRAY_ICON_ID: &'static str = "pm_icon";
|
const PM_TRAY_ICON_ID: &'static str = "pm_icon";
|
||||||
@@ -50,16 +51,36 @@ pub fn setup_tray_menu(
|
|||||||
app: &mut tauri::App,
|
app: &mut tauri::App,
|
||||||
) -> core::result::Result<AppIcon, Box<dyn std::error::Error>> {
|
) -> core::result::Result<AppIcon, Box<dyn std::error::Error>> {
|
||||||
// Tray menu
|
// Tray menu
|
||||||
let close_btn = MenuItemBuilder::with_id("close", "Exit").build(app)?;
|
let open_btn = MenuItemBuilder::with_id("open", "Open App").build(app)?;
|
||||||
let open_btn = MenuItemBuilder::with_id("open", "Open").build(app)?;
|
let exit_ui_btn = MenuItemBuilder::with_id("exit_ui", "Exit UI").build(app)?;
|
||||||
|
let shutdown_btn = MenuItemBuilder::with_id("shutdown", "Shut Down Portmaster").build(app)?;
|
||||||
|
|
||||||
let spn = CheckMenuItemBuilder::with_id("spn", "Use SPN")
|
let global_status = MenuItemBuilder::with_id("global_status", "Status: Secured")
|
||||||
|
.enabled(false)
|
||||||
.build(app)
|
.build(app)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
{
|
||||||
|
let mut button_ref = GLOBAL_STATUS.lock()?;
|
||||||
|
*button_ref = Some(global_status.clone());
|
||||||
|
}
|
||||||
|
|
||||||
// Store the SPN button reference
|
// Setup SPN status
|
||||||
let mut button_ref = SPN_BUTTON.lock()?;
|
let spn_status = MenuItemBuilder::with_id("spn_status", "SPN: Disabled")
|
||||||
*button_ref = Some(spn.clone());
|
.enabled(false)
|
||||||
|
.build(app)
|
||||||
|
.unwrap();
|
||||||
|
{
|
||||||
|
let mut button_ref = SPN_STATUS.lock()?;
|
||||||
|
*button_ref = Some(spn_status.clone());
|
||||||
|
}
|
||||||
|
// Setup SPN button
|
||||||
|
let spn = MenuItemBuilder::with_id("spn_toggle", "Enable SPN")
|
||||||
|
.build(app)
|
||||||
|
.unwrap();
|
||||||
|
{
|
||||||
|
let mut button_ref = SPN_BUTTON.lock()?;
|
||||||
|
*button_ref = Some(spn.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let force_show_window = MenuItemBuilder::with_id("force-show", "Force Show UI").build(app)?;
|
let force_show_window = MenuItemBuilder::with_id("force-show", "Force Show UI").build(app)?;
|
||||||
let reload_btn = MenuItemBuilder::with_id("reload", "Reload User Interface").build(app)?;
|
let reload_btn = MenuItemBuilder::with_id("reload", "Reload User Interface").build(app)?;
|
||||||
@@ -67,15 +88,17 @@ pub fn setup_tray_menu(
|
|||||||
.items(&[&reload_btn, &force_show_window])
|
.items(&[&reload_btn, &force_show_window])
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
// Drop the reference now so we unlock immediately.
|
|
||||||
drop(button_ref);
|
|
||||||
|
|
||||||
let menu = MenuBuilder::new(app)
|
let menu = MenuBuilder::new(app)
|
||||||
.items(&[
|
.items(&[
|
||||||
|
&open_btn,
|
||||||
|
&PredefinedMenuItem::separator(app)?,
|
||||||
|
&global_status,
|
||||||
|
&PredefinedMenuItem::separator(app)?,
|
||||||
|
&spn_status,
|
||||||
&spn,
|
&spn,
|
||||||
&PredefinedMenuItem::separator(app)?,
|
&PredefinedMenuItem::separator(app)?,
|
||||||
&open_btn,
|
&exit_ui_btn,
|
||||||
&close_btn,
|
&shutdown_btn,
|
||||||
&developer_menu,
|
&developer_menu,
|
||||||
])
|
])
|
||||||
.build()?;
|
.build()?;
|
||||||
@@ -84,7 +107,7 @@ pub fn setup_tray_menu(
|
|||||||
.icon(Image::from_bytes(RED_ICON).unwrap())
|
.icon(Image::from_bytes(RED_ICON).unwrap())
|
||||||
.menu(&menu)
|
.menu(&menu)
|
||||||
.on_menu_event(move |app, event| match event.id().as_ref() {
|
.on_menu_event(move |app, event| match event.id().as_ref() {
|
||||||
"close" => {
|
"exit_ui" => {
|
||||||
let handle = app.clone();
|
let handle = app.clone();
|
||||||
app.dialog()
|
app.dialog()
|
||||||
.message("This does not stop the Portmaster system service")
|
.message("This does not stop the Portmaster system service")
|
||||||
@@ -119,15 +142,16 @@ pub fn setup_tray_menu(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
"spn" => {
|
"spn_toggle" => {
|
||||||
let btn = SPN_BUTTON.lock().unwrap();
|
if SPN_STATE.load(Ordering::Acquire) {
|
||||||
|
app.portmaster().set_spn_enabled(false);
|
||||||
if let Some(bt) = &*btn {
|
} else {
|
||||||
if let Ok(is_checked) = bt.is_checked() {
|
app.portmaster().set_spn_enabled(true);
|
||||||
app.portmaster().set_spn_enabled(is_checked);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"shutdown" => {
|
||||||
|
app.portmaster().trigger_shutdown();
|
||||||
|
}
|
||||||
other => {
|
other => {
|
||||||
error!("unknown menu event id: {}", other);
|
error!("unknown menu event id: {}", other);
|
||||||
}
|
}
|
||||||
@@ -147,19 +171,27 @@ pub fn update_icon(icon: AppIcon, subsystems: HashMap<String, Subsystem>, spn_st
|
|||||||
let failure = subsystems
|
let failure = subsystems
|
||||||
.values()
|
.values()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.failure_status)
|
.map(|s| &s.module_status)
|
||||||
.fold(
|
.fold((subsystem::FAILURE_NONE, "".to_string()), |mut acc, s| {
|
||||||
subsystem::FAILURE_NONE,
|
for m in s {
|
||||||
|acc, s| {
|
if m.failure_status > acc.0 {
|
||||||
if s > acc {
|
acc = (m.failure_status, m.failure_msg.clone())
|
||||||
s
|
|
||||||
} else {
|
|
||||||
acc
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
);
|
acc
|
||||||
|
});
|
||||||
|
|
||||||
let next_icon = match failure {
|
if failure.0 == subsystem::FAILURE_NONE {
|
||||||
|
if let Some(global_status) = &mut *(GLOBAL_STATUS.lock().unwrap()) {
|
||||||
|
_ = global_status.set_text("Status: Secured");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some(global_status) = &mut *(GLOBAL_STATUS.lock().unwrap()) {
|
||||||
|
_ = global_status.set_text(format!("Status: {}", failure.1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let next_icon = match failure.0 {
|
||||||
subsystem::FAILURE_WARNING => YELLOW_ICON,
|
subsystem::FAILURE_WARNING => YELLOW_ICON,
|
||||||
subsystem::FAILURE_ERROR => RED_ICON,
|
subsystem::FAILURE_ERROR => RED_ICON,
|
||||||
_ => match spn_status.as_str() {
|
_ => match spn_status.as_str() {
|
||||||
@@ -314,15 +346,7 @@ pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
|
|||||||
if let Some((_, payload)) = res {
|
if let Some((_, payload)) = res {
|
||||||
match payload.parse::<BooleanValue>() {
|
match payload.parse::<BooleanValue>() {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
let mut btn = SPN_BUTTON.lock().unwrap();
|
update_spn_ui_state(value.value.unwrap_or(false));
|
||||||
|
|
||||||
if let Some(btn) = &mut *btn {
|
|
||||||
if let Some(value) = value.value {
|
|
||||||
_ = btn.set_checked(value);
|
|
||||||
} else {
|
|
||||||
_ = btn.set_checked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Err(err) => match err {
|
Err(err) => match err {
|
||||||
ParseError::JSON(err) => {
|
ParseError::JSON(err) => {
|
||||||
@@ -338,9 +362,25 @@ pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(btn) = &mut *(SPN_BUTTON.lock().unwrap()) {
|
update_spn_ui_state(false);
|
||||||
_ = btn.set_checked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = icon.set_icon(Some(Image::from_bytes(RED_ICON).unwrap()));
|
_ = icon.set_icon(Some(Image::from_bytes(RED_ICON).unwrap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_spn_ui_state(enabled: bool) {
|
||||||
|
let mut spn_status = SPN_STATUS.lock().unwrap();
|
||||||
|
let Some(spn_status_ref) = &mut *spn_status else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let mut spn_btn = SPN_BUTTON.lock().unwrap();
|
||||||
|
let Some(spn_btn_ref) = &mut *spn_btn else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if enabled {
|
||||||
|
_ = spn_status_ref.set_text("SPN: Connected");
|
||||||
|
_ = spn_btn_ref.set_text("Disable SPN");
|
||||||
|
} else {
|
||||||
|
_ = spn_status_ref.set_text("SPN: Disabled");
|
||||||
|
_ = spn_btn_ref.set_text("Enable SPN");
|
||||||
|
}
|
||||||
|
SPN_STATE.store(enabled, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user