migrate to tauri2 (#159)

migrate gui to tauri2
This commit is contained in:
Sijie.Sun
2024-07-08 23:18:10 +08:00
committed by GitHub
parent 537f6ecf78
commit 4938e3ed2b
71 changed files with 3214 additions and 2277 deletions
+9 -7
View File
@@ -1,6 +1,6 @@
[package]
name = "easytier-gui"
version = "0.0.0"
version = "1.2.0"
description = "EasyTier GUI"
authors = ["you"]
edition = "2021"
@@ -8,14 +8,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1", features = [] }
tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies]
tauri = { version = "1", features = [ "clipboard-all", "path-all",
"process-exit",
"system-tray",
"shell-open",
] }
tauri = { version = "2.0.0-beta", features = [ "tray-icon", "image-png", "image-ico"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
@@ -33,6 +30,11 @@ gethostname = "0.4.3"
auto-launch = "0.5.0"
dunce = "1.0.4"
tauri-plugin-shell = "2.0.0-beta.8"
tauri-plugin-process = "2.0.0-beta.7"
tauri-plugin-clipboard-manager = "2.1.0-beta.5"
tauri-plugin-positioner = { version = "2.0.0-beta", features = ["tray-icon"] }
[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
@@ -0,0 +1,41 @@
{
"identifier": "migrated",
"description": "permissions that were migrated from v1",
"local": true,
"windows": [
"main"
],
"permissions": [
"path:default",
"event:default",
"window:default",
"window:allow-is-visible",
"window:allow-show",
"window:allow-hide",
"window:allow-set-focus",
"app:default",
"resources:default",
"menu:default",
"tray:default",
"shell:allow-open",
"process:allow-exit",
"clipboard-manager:allow-read-text",
"clipboard-manager:allow-write-text",
"shell:default",
"process:default",
"clipboard-manager:default",
"tray:default",
"tray:allow-new",
"tray:allow-set-menu",
"tray:allow-set-title",
"tray:allow-remove-by-id",
"tray:allow-get-by-id",
"tray:allow-set-icon",
"tray:allow-set-icon-as-template",
"tray:allow-set-show-menu-on-left-click",
"tray:allow-set-tooltip"
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

+34 -42
View File
@@ -16,10 +16,7 @@ use easytier::{
};
use serde::{Deserialize, Serialize};
use tauri::{
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
Window,
};
use tauri::Manager as _;
#[derive(Deserialize, Serialize, PartialEq, Debug)]
enum NetworkingMethod {
@@ -34,6 +31,8 @@ impl Default for NetworkingMethod {
}
}
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
#[derive(Deserialize, Serialize, Debug, Default)]
struct NetworkConfig {
instance_id: String,
@@ -234,12 +233,14 @@ fn set_logging_level(level: String) -> Result<(), String> {
Ok(())
}
fn toggle_window_visibility(window: &Window) {
if window.is_visible().unwrap() {
window.hide().unwrap();
} else {
window.show().unwrap();
window.set_focus().unwrap();
fn toggle_window_visibility<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
if let Some(window) = app.get_webview_window("main") {
if window.is_visible().unwrap_or_default() {
let _ = window.hide();
} else {
let _ = window.show();
let _ = window.set_focus();
}
}
}
@@ -319,16 +320,13 @@ fn main() {
process::exit(0);
}
let quit = CustomMenuItem::new("quit".to_string(), "退出 Quit");
let hide = CustomMenuItem::new("hide".to_string(), "显示 Show / 隐藏 Hide");
let tray_menu = SystemTrayMenu::new()
.add_item(quit)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(hide);
tauri::Builder::default()
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_shell::init())
.setup(|app| {
let Some(log_dir) = app.path_resolver().app_log_dir() else {
// for logging config
let Ok(log_dir) = app.path().app_log_dir() else {
return Ok(());
};
let config = TomlConfigLoader::default();
@@ -342,6 +340,22 @@ fn main() {
};
unsafe { LOGGER_LEVEL_SENDER.replace(logger_reinit) };
// for tray icon, menu need to be built in js
let _tray_menu = TrayIconBuilder::with_id("main")
.menu_on_left_click(false)
.on_tray_icon_event(|tray, event| {
if let TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event
{
let app = tray.app_handle();
toggle_window_visibility(app);
}
})
.build(app)?;
Ok(())
})
.invoke_handler(tauri::generate_handler![
@@ -353,31 +367,9 @@ fn main() {
set_auto_launch_status,
set_logging_level
])
.system_tray(SystemTray::new().with_menu(tray_menu))
.on_system_tray_event(|app, event| match event {
SystemTrayEvent::DoubleClick {
position: _,
size: _,
..
} => {
let window = app.get_window("main").unwrap();
toggle_window_visibility(&window);
}
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"quit" => {
std::process::exit(0);
}
"hide" => {
let window = app.get_window("main").unwrap();
toggle_window_visibility(&window);
}
_ => {}
},
_ => {}
})
.on_window_event(|event| match event.event() {
.on_window_event(|win, event| match event {
tauri::WindowEvent::CloseRequested { api, .. } => {
event.window().hide().unwrap();
let _ = win.hide();
api.prevent_close();
}
_ => {}
+22 -39
View File
@@ -2,31 +2,29 @@
"build": {
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm build",
"devPath": "http://localhost:1420",
"distDir": "../dist"
"frontendDist": "../dist",
"devUrl": "http://localhost:1420"
},
"package": {
"productName": "easytier-gui",
"version": "0.0.0"
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/icon.png",
"icons/icon.rgba",
"icons/icon.icns",
"icons/icon.ico"
],
"createUpdaterArtifacts": false
},
"tauri": {
"allowlist": {
"all": false,
"shell": {
"all": false,
"open": ".*"
},
"process": {
"exit": true
},
"path": {
"all": true
},
"clipboard": {
"all": true,
"writeText": true,
"readText": true
}
"productName": "easytier-gui",
"version": "1.2.0",
"identifier": "com.kkrainbow.easyiter-client",
"plugins": {},
"app": {
"trayIcon": {
"iconPath": "icons/icon.ico",
"menuOnLeftClick": true,
"iconAsTemplate": true
},
"windows": [
{
@@ -37,21 +35,6 @@
],
"security": {
"csp": null
},
"systemTray": {
"iconPath": "icons/icon.ico",
"iconAsTemplate": true
},
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.kkrainbow.easyiter-client",
"icon": [
"icons/icon.png",
"icons/icon.rgba",
"icons/icon.icns",
"icons/icon.ico"
]
}
}
}
}
+9 -11
View File
@@ -1,15 +1,13 @@
{
"tauri": {
"bundle": {
"externalBin": [],
"resources": [
"./wintun.dll",
"./Packet.dll"
],
"windows": {
"webviewInstallMode": {
"type": "embedBootstrapper"
}
"bundle": {
"externalBin": [],
"resources": [
"./wintun.dll",
"./Packet.dll"
],
"windows": {
"webviewInstallMode": {
"type": "embedBootstrapper"
}
}
}