mirror of
https://github.com/safing/portmaster
synced 2025-04-25 13:29:10 +00:00
Tauri update to beta
This commit is contained in:
parent
f3ef67ddb1
commit
338abd6090
11 changed files with 8232 additions and 1263 deletions
desktop/tauri/src-tauri
4003
desktop/tauri/src-tauri/Cargo.lock
generated
4003
desktop/tauri/src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -12,21 +12,20 @@ rust-version = "1.60"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.0.0-alpha", features = [] }
|
||||
tauri-build = { version = "2.0.0-beta.12", features = [] }
|
||||
|
||||
[dependencies]
|
||||
# Tauri
|
||||
tauri = { version = "2.0.0-alpha", features = ["tray-icon", "icon-ico", "icon-png"] }
|
||||
tauri-plugin-shell = "2.0.0-alpha"
|
||||
tauri-plugin-dialog = "2.0.0-alpha"
|
||||
tauri-plugin-clipboard-manager = "2.0.0-alpha"
|
||||
tauri-plugin-os = "2.0.0-alpha"
|
||||
tauri-plugin-single-instance = "2.0.0-alpha"
|
||||
tauri-plugin-cli = "2.0.0-alpha"
|
||||
tauri-plugin-notification = "2.0.0-alpha"
|
||||
tauri = { version = "2.0.0-beta.12", features = ["tray-icon", "image-png"] }
|
||||
tauri-plugin-shell = "2.0.0-beta"
|
||||
tauri-plugin-dialog = "2.0.0-beta"
|
||||
tauri-plugin-clipboard-manager = "2.0.0-beta"
|
||||
tauri-plugin-os = "2.0.0-beta"
|
||||
tauri-plugin-single-instance = "2.0.0-beta"
|
||||
tauri-plugin-cli = "2.0.0-beta"
|
||||
tauri-plugin-notification = "2.0.0-beta"
|
||||
|
||||
# We still need the tauri-cli 1.5 for building
|
||||
tauri-cli = "1.5.11"
|
||||
tauri-cli = "2.0.0-beta.12"
|
||||
|
||||
# General
|
||||
serde_json = "1.0"
|
||||
|
|
17
desktop/tauri/src-tauri/capabilities/migrated.json
Normal file
17
desktop/tauri/src-tauri/capabilities/migrated.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"identifier": "migrated",
|
||||
"description": "permissions that were migrated from v1",
|
||||
"local": true,
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"path:default",
|
||||
"event:default",
|
||||
"window:default",
|
||||
"app:default",
|
||||
"resources:default",
|
||||
"menu:default",
|
||||
"tray:default"
|
||||
]
|
||||
}
|
1
desktop/tauri/src-tauri/gen/schemas/acl-manifests.json
Normal file
1
desktop/tauri/src-tauri/gen/schemas/acl-manifests.json
Normal file
File diff suppressed because one or more lines are too long
1
desktop/tauri/src-tauri/gen/schemas/capabilities.json
Normal file
1
desktop/tauri/src-tauri/gen/schemas/capabilities.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default"]}}
|
2637
desktop/tauri/src-tauri/gen/schemas/desktop-schema.json
Normal file
2637
desktop/tauri/src-tauri/gen/schemas/desktop-schema.json
Normal file
File diff suppressed because it is too large
Load diff
2637
desktop/tauri/src-tauri/gen/schemas/linux-schema.json
Normal file
2637
desktop/tauri/src-tauri/gen/schemas/linux-schema.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -16,7 +16,7 @@ mod portmaster;
|
|||
mod traymenu;
|
||||
mod window;
|
||||
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use log::{debug, error, info};
|
||||
use portmaster::PortmasterExt;
|
||||
use traymenu::setup_tray_menu;
|
||||
use window::{close_splash_window, create_main_window};
|
||||
|
@ -111,7 +111,7 @@ fn main() {
|
|||
// Setup the single-instance event listener that will create/focus the main window
|
||||
// or the splash-screen.
|
||||
let handle = app.handle().clone();
|
||||
app.listen_global("single-instance", move |_event| {
|
||||
app.listen("single-instance", move |_event| {
|
||||
let _ = window::open_window(&handle);
|
||||
});
|
||||
|
||||
|
@ -196,7 +196,7 @@ fn main() {
|
|||
);
|
||||
|
||||
api.prevent_close();
|
||||
if let Some(window) = handle.get_window(label.as_str()) {
|
||||
if let Some(window) = handle.get_webview_window(label.as_str()) {
|
||||
let _ = window.emit("exit-requested", "");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::sync::Mutex;
|
|||
|
||||
use log::{debug, error};
|
||||
use tauri::{
|
||||
image::Image,
|
||||
menu::{
|
||||
CheckMenuItem, CheckMenuItemBuilder, MenuBuilder, MenuItemBuilder, PredefinedMenuItem,
|
||||
SubmenuBuilder,
|
||||
},
|
||||
tray::{ClickType, TrayIcon, TrayIconBuilder},
|
||||
Icon, Manager, Wry,
|
||||
Manager, Wry,
|
||||
};
|
||||
use tauri_plugin_dialog::DialogExt;
|
||||
|
||||
use crate::{
|
||||
portapi::{
|
||||
|
@ -26,6 +26,7 @@ use crate::{
|
|||
portmaster::PortmasterExt,
|
||||
window::{create_main_window, may_navigate_to_ui, open_window},
|
||||
};
|
||||
use tauri_plugin_dialog::DialogExt;
|
||||
|
||||
pub type AppIcon = TrayIcon<Wry>;
|
||||
|
||||
|
@ -34,32 +35,32 @@ lazy_static! {
|
|||
static ref SPN_BUTTON: Mutex<Option<CheckMenuItem<Wry>>> = Mutex::new(None);
|
||||
}
|
||||
|
||||
const PM_TRAY_ICON_ID: &'static str = "pm_icon";
|
||||
|
||||
// Icons
|
||||
//
|
||||
const BLUE_ICON: &'static [u8] =
|
||||
include_bytes!("../../assets/icons/pm_light_blue_512.ico");
|
||||
const RED_ICON: &'static [u8] =
|
||||
include_bytes!("../../assets/icons/pm_light_red_512.ico");
|
||||
const YELLOW_ICON: &'static [u8] =
|
||||
include_bytes!("../../assets/icons/pm_light_yellow_512.ico");
|
||||
const GREEN_ICON: &'static [u8] =
|
||||
include_bytes!("../../assets/icons/pm_light_green_512.ico");
|
||||
const BLUE_ICON: &'static [u8] = include_bytes!("../../assets/icons/pm_light_blue_512.ico");
|
||||
const RED_ICON: &'static [u8] = include_bytes!("../../assets/icons/pm_light_red_512.ico");
|
||||
const YELLOW_ICON: &'static [u8] = include_bytes!("../../assets/icons/pm_light_yellow_512.ico");
|
||||
const GREEN_ICON: &'static [u8] = include_bytes!("../../assets/icons/pm_light_green_512.ico");
|
||||
|
||||
pub fn setup_tray_menu(
|
||||
app: &mut tauri::App,
|
||||
) -> core::result::Result<AppIcon, Box<dyn std::error::Error>> {
|
||||
// Tray menu
|
||||
let close_btn = MenuItemBuilder::with_id("close", "Exit").build(app);
|
||||
let open_btn = MenuItemBuilder::with_id("open", "Open").build(app);
|
||||
let close_btn = MenuItemBuilder::with_id("close", "Exit").build(app)?;
|
||||
let open_btn = MenuItemBuilder::with_id("open", "Open").build(app)?;
|
||||
|
||||
let spn = CheckMenuItemBuilder::with_id("spn", "Use SPN").build(app);
|
||||
let spn = CheckMenuItemBuilder::with_id("spn", "Use SPN")
|
||||
.build(app)
|
||||
.unwrap();
|
||||
|
||||
// Store the SPN button reference
|
||||
let mut button_ref = SPN_BUTTON.lock().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 reload_btn = MenuItemBuilder::with_id("reload", "Reload User Interface").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 developer_menu = SubmenuBuilder::new(app, "Developer")
|
||||
.items(&[&reload_btn, &force_show_window])
|
||||
.build()?;
|
||||
|
@ -70,15 +71,15 @@ pub fn setup_tray_menu(
|
|||
let menu = MenuBuilder::new(app)
|
||||
.items(&[
|
||||
&spn,
|
||||
&PredefinedMenuItem::separator(app),
|
||||
&PredefinedMenuItem::separator(app)?,
|
||||
&open_btn,
|
||||
&close_btn,
|
||||
&developer_menu,
|
||||
])
|
||||
.build()?;
|
||||
|
||||
let icon = TrayIconBuilder::new()
|
||||
.icon(Icon::Raw(RED_ICON.to_vec()))
|
||||
let icon = TrayIconBuilder::with_id(PM_TRAY_ICON_ID)
|
||||
.icon(Image::from_bytes(RED_ICON).unwrap())
|
||||
.menu(&menu)
|
||||
.on_menu_event(move |app, event| match event.id().as_ref() {
|
||||
"close" => {
|
||||
|
@ -136,7 +137,6 @@ pub fn setup_tray_menu(
|
|||
}
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
Ok(icon)
|
||||
}
|
||||
|
||||
|
@ -166,11 +166,11 @@ pub fn update_icon(icon: AppIcon, subsystems: HashMap<String, Subsystem>, spn_st
|
|||
},
|
||||
};
|
||||
|
||||
_ = icon.set_icon(Some(Icon::Raw(next_icon.to_vec())));
|
||||
_ = icon.set_icon(Some(Image::from_bytes(next_icon).unwrap()));
|
||||
}
|
||||
|
||||
pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
|
||||
let icon = match app.tray() {
|
||||
let icon = match app.tray_by_id(PM_TRAY_ICON_ID) {
|
||||
Some(icon) => icon,
|
||||
None => {
|
||||
error!("cancel try_handler: missing try icon");
|
||||
|
@ -226,7 +226,7 @@ pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
|
|||
}
|
||||
};
|
||||
|
||||
_ = icon.set_icon(Some(Icon::Raw(BLUE_ICON.to_vec())));
|
||||
_ = icon.set_icon(Some(Image::from_bytes(BLUE_ICON).unwrap()));
|
||||
|
||||
let mut subsystems: HashMap<String, Subsystem> = HashMap::new();
|
||||
let mut spn_status: String = "".to_string();
|
||||
|
@ -340,5 +340,5 @@ pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
|
|||
_ = btn.set_checked(false);
|
||||
}
|
||||
|
||||
_ = icon.set_icon(Some(Icon::Raw(RED_ICON.to_vec())));
|
||||
_ = icon.set_icon(Some(Image::from_bytes(RED_ICON).unwrap()));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use log::{debug, error};
|
||||
use tauri::{AppHandle, Manager, Result, UserAttentionType, Window, WindowBuilder, WindowUrl};
|
||||
use tauri::{
|
||||
AppHandle, Manager, Result, UserAttentionType, WebviewUrl, WebviewWindow, WebviewWindowBuilder,
|
||||
};
|
||||
|
||||
use crate::portmaster::PortmasterExt;
|
||||
|
||||
|
@ -11,15 +13,15 @@ use crate::portmaster::PortmasterExt;
|
|||
/// if ::websocket::is_portapi_reachable returns true.
|
||||
///
|
||||
/// Either the existing or the newly created window is returned.
|
||||
pub fn create_main_window(app: &AppHandle) -> Result<Window> {
|
||||
let mut window = if let Some(window) = app.get_window("main") {
|
||||
pub fn create_main_window(app: &AppHandle) -> Result<WebviewWindow> {
|
||||
let mut window = if let Some(window) = app.get_webview_window("main") {
|
||||
debug!("[tauri] main window already created");
|
||||
|
||||
window
|
||||
} else {
|
||||
debug!("[tauri] creating main window");
|
||||
|
||||
let res = WindowBuilder::new(app, "main", WindowUrl::App("index.html".into()))
|
||||
let res = WebviewWindowBuilder::new(app, "main", WebviewUrl::App("index.html".into()))
|
||||
.visible(false)
|
||||
.build();
|
||||
|
||||
|
@ -54,12 +56,12 @@ pub fn create_main_window(app: &AppHandle) -> Result<Window> {
|
|||
Ok(window)
|
||||
}
|
||||
|
||||
pub fn create_splash_window(app: &AppHandle) -> Result<Window> {
|
||||
if let Some(window) = app.get_window("splash") {
|
||||
pub fn create_splash_window(app: &AppHandle) -> Result<WebviewWindow> {
|
||||
if let Some(window) = app.get_webview_window("splash") {
|
||||
let _ = window.show();
|
||||
Ok(window)
|
||||
} else {
|
||||
let window = WindowBuilder::new(app, "splash", WindowUrl::App("index.html".into()))
|
||||
let window = WebviewWindowBuilder::new(app, "splash", WebviewUrl::App("index.html".into()))
|
||||
.center()
|
||||
.closable(false)
|
||||
.focused(true)
|
||||
|
@ -76,7 +78,7 @@ pub fn create_splash_window(app: &AppHandle) -> Result<Window> {
|
|||
}
|
||||
|
||||
pub fn close_splash_window(app: &AppHandle) -> Result<()> {
|
||||
if let Some(window) = app.get_window("splash") {
|
||||
if let Some(window) = app.get_webview_window("splash") {
|
||||
return window.close();
|
||||
}
|
||||
return Err(tauri::Error::WindowNotFound);
|
||||
|
@ -94,9 +96,9 @@ pub fn close_splash_window(app: &AppHandle) -> Result<()> {
|
|||
///
|
||||
/// If the Portmaster API is unreachable and there's no main window yet, we show the
|
||||
/// splash-screen window.
|
||||
pub fn open_window(app: &AppHandle) -> Result<Window> {
|
||||
pub fn open_window(app: &AppHandle) -> Result<WebviewWindow> {
|
||||
if app.portmaster().is_reachable() {
|
||||
match app.get_window("main") {
|
||||
match app.get_webview_window("main") {
|
||||
Some(win) => {
|
||||
app.portmaster().show_window();
|
||||
|
||||
|
@ -122,7 +124,7 @@ pub fn open_window(app: &AppHandle) -> Result<Window> {
|
|||
/// In #[cfg(debug_assertions)] the TAURI_PM_URL environment variable will be used
|
||||
/// if set.
|
||||
/// Otherwise or in release builds, it will be navigated to http://127.0.0.1:817.
|
||||
pub fn may_navigate_to_ui(win: &mut Window, force: bool) {
|
||||
pub fn may_navigate_to_ui(win: &mut WebviewWindow, force: bool) {
|
||||
if !win.app_handle().portmaster().is_reachable() && !force {
|
||||
error!("[tauri] portmaster API is not reachable, not navigating");
|
||||
|
||||
|
@ -148,6 +150,9 @@ pub fn may_navigate_to_ui(win: &mut Window, force: bool) {
|
|||
#[cfg(not(debug_assertions))]
|
||||
win.navigate("http://localhost:817".parse().unwrap());
|
||||
} else {
|
||||
error!("not navigating to user interface: current url: {}", win.url().as_str());
|
||||
error!(
|
||||
"not navigating to user interface: current url: {}",
|
||||
win.url().as_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,8 @@
|
|||
"cwd": "../../angular",
|
||||
"wait": false
|
||||
},
|
||||
"devPath": "http://localhost:4100",
|
||||
"distDir": "../../angular/dist/tauri-builtin",
|
||||
"withGlobalTauri": true
|
||||
},
|
||||
"package": {
|
||||
"productName": "Portmaster",
|
||||
"version": "0.1.0"
|
||||
"frontendDist": "../../angular/dist/tauri-builtin",
|
||||
"devUrl": "http://localhost:4100"
|
||||
},
|
||||
"plugins": {
|
||||
"cli": {
|
||||
|
@ -38,79 +33,19 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"tauri": {
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"category": "Utility",
|
||||
"copyright": "Safing Limited Inc",
|
||||
"deb": {
|
||||
"depends": [
|
||||
"libayatana-appindicator3"
|
||||
],
|
||||
"desktopTemplate": "../../../packaging/linux/portmaster.desktop",
|
||||
"files": {
|
||||
"/usr/lib/systemd/system/portmaster.service": "../../../packaging/linux/portmaster.service",
|
||||
"/etc/xdg/autostart/portmaster.desktop": "../../../packaging/linux/portmaster-autostart.desktop",
|
||||
"/var/": "../../../packaging/linux/var",
|
||||
"../control/postinst": "../../../packaging/linux/debian/postinst",
|
||||
"../control/postrm": "../../../packaging/linux/debian/postrm"
|
||||
}
|
||||
},
|
||||
"externalBin": [
|
||||
"binaries/portmaster-start",
|
||||
"binaries/portmaster-core"
|
||||
],
|
||||
"icon": [
|
||||
"../assets/icons/pm_dark_512.png",
|
||||
"../assets/icons/pm_dark_512.ico",
|
||||
"../assets/icons/pm_light_512.png",
|
||||
"../assets/icons/pm_light_512.ico"
|
||||
],
|
||||
"identifier": "io.safing.portmaster",
|
||||
"longDescription": "",
|
||||
"macOS": {
|
||||
"entitlements": null,
|
||||
"exceptionDomain": "",
|
||||
"frameworks": [],
|
||||
"providerShortName": null,
|
||||
"signingIdentity": null
|
||||
},
|
||||
"resources": [],
|
||||
"shortDescription": "",
|
||||
"targets": [
|
||||
"deb",
|
||||
"appimage",
|
||||
"nsis",
|
||||
"msi",
|
||||
"app"
|
||||
],
|
||||
"windows": {
|
||||
"certificateThumbprint": null,
|
||||
"digestAlgorithm": "sha256",
|
||||
"timestampUrl": ""
|
||||
}
|
||||
},
|
||||
"security": {
|
||||
"csp": null,
|
||||
"dangerousRemoteDomainIpcAccess": [
|
||||
{
|
||||
"windows": [
|
||||
"main",
|
||||
"prompt"
|
||||
],
|
||||
"plugins": [
|
||||
"shell",
|
||||
"os",
|
||||
"clipboard-manager",
|
||||
"event",
|
||||
"window",
|
||||
"cli",
|
||||
"portmaster"
|
||||
],
|
||||
"domain": "localhost"
|
||||
}
|
||||
]
|
||||
},
|
||||
"productName": "Portmaster",
|
||||
"version": "0.1.0",
|
||||
"identifier": "io.safing.portmaster",
|
||||
"app": {
|
||||
"withGlobalTauri": true,
|
||||
"windows": []
|
||||
},
|
||||
"bundle": {
|
||||
"icon": [
|
||||
"../assets/icons/pm_dark_512.png",
|
||||
"../assets/icons/pm_dark_512.ico",
|
||||
"../assets/icons/pm_light_512.png",
|
||||
"../assets/icons/pm_light_512.ico"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue