diff --git a/Cargo.lock b/Cargo.lock index f3a23d0..e629393 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,6 +146,26 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arboard" +version = "3.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2041f1943049c7978768d84e6d0fd95de98b76d6c4727b09e78ec253d29fa58" +dependencies = [ + "clipboard-win", + "core-graphics 0.23.2", + "image", + "log", + "objc", + "objc-foundation", + "objc_id", + "parking_lot", + "thiserror", + "windows-sys 0.48.0", + "wl-clipboard-rs", + "x11rb", +] + [[package]] name = "async-event" version = "0.1.0" @@ -619,6 +639,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chacha20" version = "0.9.1" @@ -721,6 +747,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "clipboard-win" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d517d4b86184dbb111d3556a10f1c8a04da7428d2987bf1081602bf11c3aa9ee" +dependencies = [ + "error-code", +] + [[package]] name = "cobs" version = "0.2.3" @@ -737,8 +772,8 @@ dependencies = [ "block", "cocoa-foundation", "core-foundation", - "core-graphics", - "foreign-types", + "core-graphics 0.22.3", + "foreign-types 0.3.2", "libc", "objc", ] @@ -816,7 +851,20 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types", + "foreign-types 0.3.2", + "libc", +] + +[[package]] +name = "core-graphics" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-graphics-types", + "foreign-types 0.5.0", "libc", ] @@ -1137,6 +1185,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive-new" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.65", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -1218,6 +1277,21 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" +[[package]] +name = "dlib" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" +dependencies = [ + "libloading 0.7.4", +] + +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + [[package]] name = "dtoa" version = "1.0.9" @@ -1460,6 +1534,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "error-code" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0474425d51df81997e2f90a21591180b38eccf27292d755f3e30750225c175b" + [[package]] name = "fastrand" version = "2.1.0" @@ -1531,7 +1611,28 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared", + "foreign-types-shared 0.1.1", +] + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared 0.3.1", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.65", ] [[package]] @@ -1540,6 +1641,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2308,6 +2415,8 @@ dependencies = [ "byteorder", "color_quant", "num-traits", + "png", + "tiff", ] [[package]] @@ -2495,6 +2604,12 @@ dependencies = [ "libc", ] +[[package]] +name = "jpeg-decoder" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" + [[package]] name = "js-sys" version = "0.3.69" @@ -2746,6 +2861,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.3" @@ -2935,6 +3056,18 @@ dependencies = [ "memoffset", ] +[[package]] +name = "nix" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "no-std-net" version = "0.6.0" @@ -2947,6 +3080,16 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3041,6 +3184,17 @@ dependencies = [ "objc_exception", ] +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -3098,7 +3252,7 @@ checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ "bitflags 2.5.0", "cfg-if", - "foreign-types", + "foreign-types 0.3.2", "libc", "once_cell", "openssl-macros", @@ -3153,6 +3307,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "os_pipe" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57119c3b893986491ec9aa85056780d3a0f3cf4da7cc09dd3650dbd6c6738fb9" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "overload" version = "0.1.1" @@ -4813,7 +4977,7 @@ dependencies = [ "cc", "cocoa", "core-foundation", - "core-graphics", + "core-graphics 0.22.3", "crossbeam-channel", "dirs-next", "dispatch", @@ -5047,6 +5211,7 @@ version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef2af45aeb15b1cadb4ca91248423f4438a0864b836298cecb436892afbfdff4" dependencies = [ + "arboard", "cocoa", "gtk", "percent-encoding", @@ -5170,6 +5335,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tiff" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "time" version = "0.3.36" @@ -5588,6 +5764,20 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "tree_magic_mini" +version = "3.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469a727cac55b41448315cc10427c069c618ac59bb6a4480283fcd811749bdc2" +dependencies = [ + "fnv", + "home", + "memchr", + "nom", + "once_cell", + "petgraph", +] + [[package]] name = "try-lock" version = "0.2.5" @@ -5882,6 +6072,79 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "wayland-backend" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40" +dependencies = [ + "cc", + "downcast-rs", + "rustix", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" +dependencies = [ + "bitflags 2.5.0", + "rustix", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" +dependencies = [ + "bitflags 2.5.0", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +dependencies = [ + "bitflags 2.5.0", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b3a62929287001986fb58c789dce9b67604a397c15c611ad9f747300b6c283" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + [[package]] name = "web-sys" version = "0.3.69" @@ -5986,6 +6249,12 @@ dependencies = [ "windows-metadata", ] +[[package]] +name = "weezl" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" + [[package]] name = "which" version = "4.4.2" @@ -6407,6 +6676,26 @@ dependencies = [ "windows 0.51.1", ] +[[package]] +name = "wl-clipboard-rs" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b41773911497b18ca8553c3daaf8ec9fe9819caf93d451d3055f69de028adb" +dependencies = [ + "derive-new", + "libc", + "log", + "nix 0.28.0", + "os_pipe", + "tempfile", + "thiserror", + "tree_magic_mini", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-wlr", +] + [[package]] name = "wry" version = "0.24.10" @@ -6416,7 +6705,7 @@ dependencies = [ "base64 0.13.1", "block", "cocoa", - "core-graphics", + "core-graphics 0.22.3", "crossbeam-channel", "dunce", "gdk", @@ -6466,6 +6755,23 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "x11rb" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f25ead8c7e4cba123243a6367da5d3990e0d3affa708ea19dce96356bd9f1a" +dependencies = [ + "gethostname", + "rustix", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e63e71c4b8bd9ffec2c963173a4dc4cbde9ee96961d4fcb4429db9929b606c34" + [[package]] name = "x25519-dalek" version = "2.0.1" diff --git a/easytier-gui/locales/cn.yml b/easytier-gui/locales/cn.yml index bc1a664..efbcbdb 100644 --- a/easytier-gui/locales/cn.yml +++ b/easytier-gui/locales/cn.yml @@ -32,6 +32,14 @@ retain_network_instance: 保留网络实例 collect_network_infos: 收集网络信息 settings: 设置 exchange_language: Switch to English +logging: 日志 +logging_level_info: 信息 +logging_level_debug: 调试 +logging_level_warn: 警告 +logging_level_trace: 跟踪 +logging_level_off: 关闭 +logging_open_dir: 打开日志目录 +logging_copy_dir: 复制日志路径 disable_auto_launch: 关闭开机自启 enable_auto_launch: 开启开机自启 exit: 退出 diff --git a/easytier-gui/locales/en.yml b/easytier-gui/locales/en.yml index 8b122c0..b6fb959 100644 --- a/easytier-gui/locales/en.yml +++ b/easytier-gui/locales/en.yml @@ -32,6 +32,14 @@ retain_network_instance: Retain Network Instance collect_network_infos: Collect Network Infos settings: Settings exchange_language: 切换中文 +logging: Logging +logging_level_info: Info +logging_level_debug: Debug +logging_level_warn: Warn +logging_level_trace: Trace +logging_level_off: Off +logging_open_dir: Open Log Directory +logging_copy_dir: Copy Log Path disable_auto_launch: Disable Launch on Reboot enable_auto_launch: Enable Launch on Reboot exit: Exit diff --git a/easytier-gui/src-tauri/Cargo.toml b/easytier-gui/src-tauri/Cargo.toml index a03b397..61e65f3 100644 --- a/easytier-gui/src-tauri/Cargo.toml +++ b/easytier-gui/src-tauri/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" tauri-build = { version = "1", features = [] } [dependencies] -tauri = { version = "1", features = [ +tauri = { version = "1", features = [ "clipboard-all", "path-all", "process-exit", "system-tray", "shell-open", diff --git a/easytier-gui/src-tauri/src/main.rs b/easytier-gui/src-tauri/src/main.rs index 2967f8d..54dec8b 100644 --- a/easytier-gui/src-tauri/src/main.rs +++ b/easytier-gui/src-tauri/src/main.rs @@ -8,9 +8,11 @@ use auto_launch::AutoLaunchBuilder; use dashmap::DashMap; use easytier::{ common::config::{ - ConfigLoader, NetworkIdentity, PeerConfig, TomlConfigLoader, VpnPortalConfig, + ConfigLoader, FileLoggerConfig, NetworkIdentity, PeerConfig, TomlConfigLoader, + VpnPortalConfig, }, launcher::{NetworkInstance, NetworkInstanceRunningInfo}, + utils::{self, NewFilterSender}, }; use serde::{Deserialize, Serialize}; @@ -165,6 +167,9 @@ impl NetworkConfig { static INSTANCE_MAP: once_cell::sync::Lazy> = once_cell::sync::Lazy::new(DashMap::new); +static mut LOGGER_LEVEL_SENDER: once_cell::sync::Lazy> = + once_cell::sync::Lazy::new(Default::default); + // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command #[tauri::command] fn parse_network_config(cfg: NetworkConfig) -> Result { @@ -222,6 +227,13 @@ fn set_auto_launch_status(app_handle: tauri::AppHandle, enable: bool) -> Result< Ok(init_launch(&app_handle, enable).map_err(|e| e.to_string())?) } +#[tauri::command] +fn set_logging_level(level: String) -> Result<(), String> { + let sender = unsafe { LOGGER_LEVEL_SENDER.as_ref().unwrap() }; + sender.send(level).map_err(|e| e.to_string())?; + Ok(()) +} + fn toggle_window_visibility(window: &Window) { if window.is_visible().unwrap() { window.hide().unwrap(); @@ -306,6 +318,7 @@ fn main() { if !check_sudo() { 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() @@ -314,13 +327,31 @@ fn main() { .add_item(hide); tauri::Builder::default() + .setup(|app| { + let Some(log_dir) = app.path_resolver().app_log_dir() else { + return Ok(()); + }; + let config = TomlConfigLoader::default(); + config.set_file_logger_config(FileLoggerConfig { + dir: Some(log_dir.to_string_lossy().to_string()), + level: None, + file: None, + }); + let Ok(Some(logger_reinit)) = utils::init_logger(config, true) else { + return Ok(()); + }; + unsafe { LOGGER_LEVEL_SENDER.replace(logger_reinit) }; + + Ok(()) + }) .invoke_handler(tauri::generate_handler![ parse_network_config, run_network_instance, retain_network_instance, collect_network_infos, get_os_hostname, - set_auto_launch_status + set_auto_launch_status, + set_logging_level ]) .system_tray(SystemTray::new().with_menu(tray_menu)) .on_system_tray_event(|app, event| match event { diff --git a/easytier-gui/src-tauri/tauri.conf.json b/easytier-gui/src-tauri/tauri.conf.json index 56771aa..c173b17 100644 --- a/easytier-gui/src-tauri/tauri.conf.json +++ b/easytier-gui/src-tauri/tauri.conf.json @@ -14,10 +14,18 @@ "all": false, "shell": { "all": false, - "open": true + "open": ".*" }, "process": { "exit": true + }, + "path": { + "all": true + }, + "clipboard": { + "all": true, + "writeText": true, + "readText": true } }, "windows": [ diff --git a/easytier-gui/src/auto-imports.d.ts b/easytier-gui/src/auto-imports.d.ts index f864211..bf31969 100644 --- a/easytier-gui/src/auto-imports.d.ts +++ b/easytier-gui/src/auto-imports.d.ts @@ -60,6 +60,7 @@ declare global { const runNetworkInstance: typeof import('./composables/network')['runNetworkInstance'] const setActivePinia: typeof import('pinia')['setActivePinia'] const setAutoLaunchStatus: typeof import('./composables/network')['setAutoLaunchStatus'] + const setLoggingLevel: typeof import('./composables/network')['setLoggingLevel'] const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix'] const shallowReactive: typeof import('vue')['shallowReactive'] const shallowReadonly: typeof import('vue')['shallowReadonly'] @@ -151,6 +152,7 @@ declare module 'vue' { readonly runNetworkInstance: UnwrapRef readonly setActivePinia: UnwrapRef readonly setAutoLaunchStatus: UnwrapRef + readonly setLoggingLevel: UnwrapRef readonly setMapStoreSuffix: UnwrapRef readonly shallowReactive: UnwrapRef readonly shallowReadonly: UnwrapRef @@ -235,6 +237,7 @@ declare module '@vue/runtime-core' { readonly runNetworkInstance: UnwrapRef readonly setActivePinia: UnwrapRef readonly setAutoLaunchStatus: UnwrapRef + readonly setLoggingLevel: UnwrapRef readonly setMapStoreSuffix: UnwrapRef readonly shallowReactive: UnwrapRef readonly shallowReadonly: UnwrapRef diff --git a/easytier-gui/src/composables/network.ts b/easytier-gui/src/composables/network.ts index bc4ba6d..2c2cd51 100644 --- a/easytier-gui/src/composables/network.ts +++ b/easytier-gui/src/composables/network.ts @@ -24,3 +24,7 @@ export async function getOsHostname() { export async function setAutoLaunchStatus(enable: boolean) { return await invoke('set_auto_launch_status', { enable }) } + +export async function setLoggingLevel(level: string) { + return await invoke('set_logging_level', { level }) +} diff --git a/easytier-gui/src/pages/index.vue b/easytier-gui/src/pages/index.vue index c78ca04..e50c90b 100644 --- a/easytier-gui/src/pages/index.vue +++ b/easytier-gui/src/pages/index.vue @@ -12,6 +12,11 @@ import type { NetworkConfig } from '~/types/network' import { loadLanguageAsync } from '~/modules/i18n' import { getAutoLaunchStatusAsync as getAutoLaunchStatus, loadAutoLaunchStatusAsync } from '~/modules/auto_launch' import { loadRunningInstanceIdsFromLocalStorage } from '~/stores/network' +import { setLoggingLevel } from '~/composables/network' +import TieredMenu from 'primevue/tieredmenu' +import { open } from '@tauri-apps/api/shell' +import { appLogDir } from '@tauri-apps/api/path' +import { writeText } from '@tauri-apps/api/clipboard' const { t, locale } = useI18n() const visible = ref(false) @@ -114,33 +119,66 @@ const activeStep = computed(() => { return networkStore.networkInstanceIds.includes(networkStore.curNetworkId) ? 1 : 0 }) +let current_log_level = 'off' + const setting_menu = ref() const setting_menu_items = ref([ { - label: () => t('settings'), - items: [ - { - label: () => t('exchange_language'), - icon: 'pi pi-language', + label: () => t('exchange_language'), + icon: 'pi pi-language', + command: async () => { + await loadLanguageAsync((locale.value === 'en' ? 'cn' : 'en')) + }, + }, + { + label: () => getAutoLaunchStatus() ? t('disable_auto_launch') : t('enable_auto_launch'), + icon: 'pi pi-desktop', + command: async () => { + await loadAutoLaunchStatusAsync(!getAutoLaunchStatus()) + }, + }, + { + label: () => t('logging'), + icon: 'pi pi-file', + items: (function () { + const levels = ['off', 'warn', 'info', 'debug', 'trace'] + let items = [] + for (let level of levels) { + items.push({ + label: () => t("logging_level_" + level) + (current_log_level === level ? ' ✓' : ''), + command: async () => { + current_log_level = level + await setLoggingLevel(level) + }, + }) + } + items.push({ + separator: true, + }) + items.push({ + label: () => t('logging_open_dir'), + icon: 'pi pi-folder-open', command: async () => { - await loadLanguageAsync((locale.value === 'en' ? 'cn' : 'en')) + console.log("open log dir", await appLogDir()) + await open(await appLogDir()) }, - }, - { - label: () => getAutoLaunchStatus() ? t('disable_auto_launch') : t('enable_auto_launch'), - icon: 'pi pi-desktop', + }) + items.push({ + label: () => t('logging_copy_dir'), + icon: 'pi pi-tablet', command: async () => { - await loadAutoLaunchStatusAsync(!getAutoLaunchStatus()) + await writeText(await appLogDir()) }, - }, - { - label: () => t('exit'), - icon: 'pi pi-power-off', - command: async () => { - await exit(1) - }, - }, - ], + }) + return items + })() + }, + { + label: () => t('exit'), + icon: 'pi pi-power-off', + command: async () => { + await exit(1) + }, }, ]) @@ -231,7 +269,7 @@ function isRunning(id: string) { diff --git a/easytier/src/utils.rs b/easytier/src/utils.rs index 78fd572..cce5952 100644 --- a/easytier/src/utils.rs +++ b/easytier/src/utils.rs @@ -1,6 +1,5 @@ use anyhow::Context; use serde::{Deserialize, Serialize}; -use tokio::sync::mpsc; use tracing::level_filters::LevelFilter; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer}; @@ -136,7 +135,7 @@ pub fn float_to_str(f: f64, precision: usize) -> String { format!("{:.1$}", f, precision) } -pub type NewFilterSender = mpsc::UnboundedSender; +pub type NewFilterSender = std::sync::mpsc::Sender; pub fn init_logger( config: impl ConfigLoader, @@ -163,14 +162,14 @@ pub fn init_logger( tracing_subscriber::reload::Layer::new(file_filter); if need_reload { - let (sender, mut recver) = mpsc::unbounded_channel(); + let (sender, recver) = std::sync::mpsc::channel(); ret_sender = Some(sender); - tokio::spawn(async move { + std::thread::spawn(move || { println!("Start log filter reloader"); - while let Some(lf) = recver.recv().await { + while let Ok(lf) = recver.recv() { let e = file_filter_reloader.modify(|f| { if let Ok(nf) = EnvFilter::builder() - .with_default_directive(lf.into()) + .with_default_directive(lf.parse::().unwrap().into()) .from_env() .with_context(|| "failed to create file filter") { @@ -240,7 +239,6 @@ pub fn utf8_or_gbk_to_string(s: &[u8]) -> String { } } - #[cfg(test)] mod tests { use crate::common::config::{self}; @@ -252,7 +250,7 @@ mod tests { let config = config::TomlConfigLoader::default(); let s = init_logger(&config, true).unwrap(); tracing::debug!("test not display debug"); - s.unwrap().send(LevelFilter::DEBUG).unwrap(); + s.unwrap().send(LevelFilter::DEBUG.to_string()).unwrap(); tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; tracing::debug!("test display debug"); }