diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 8adca05..a86bc7a 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -964,6 +964,8 @@ dependencies = [ "tauri-plugin-global-shortcut", "tauri-plugin-shell", "tauri-plugin-store", + "tracing", + "tracing-subscriber", "xcap", ] @@ -2523,6 +2525,15 @@ dependencies = [ "tendril", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matches" version = "0.1.10" @@ -2687,6 +2698,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi 0.3.9", +] + [[package]] name = "num-bigint" version = "0.4.6" @@ -3044,6 +3065,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "pango" version = "0.18.3" @@ -3700,8 +3727,17 @@ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -3712,9 +3748,15 @@ checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.5", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.5" @@ -4086,6 +4128,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shared_child" version = "1.0.1" @@ -4819,6 +4870,16 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + [[package]] name = "tiff" version = "0.9.1" @@ -5007,6 +5068,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -5181,6 +5272,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version-compare" version = "0.2.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index dd6518f..b89b582 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -38,6 +38,8 @@ strum = "0.26.3" image = "0.25.5" tauri-plugin-store = "2" xcap = "0.0.14" +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } +tracing = "0.1.40" [features] default = ["custom-protocol"] diff --git a/src-tauri/src/cmd/window.rs b/src-tauri/src/cmd/window.rs index 8d4c565..27aebc3 100644 --- a/src-tauri/src/cmd/window.rs +++ b/src-tauri/src/cmd/window.rs @@ -10,7 +10,6 @@ pub fn show_preview_window(app: AppHandle, path: String) -> Result Result<(), String> { - println!("hide_preview_window"); window::hide_preview_window(&app); Ok(()) } diff --git a/src-tauri/src/cmd/xcreenshot.rs b/src-tauri/src/cmd/xcreenshot.rs index 5f927f4..27e99ef 100644 --- a/src-tauri/src/cmd/xcreenshot.rs +++ b/src-tauri/src/cmd/xcreenshot.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use chrono::Local; +use tracing::info; use std::time::Instant; use xcap::{Monitor, Window}; @@ -44,7 +45,7 @@ fn window_capture(path: PathBuf) -> Result { continue; } - println!( + info!( "Window: {:?} {:?} {:?}", window.title(), (window.x(), window.y(), window.width(), window.height()), @@ -62,14 +63,14 @@ fn window_capture(path: PathBuf) -> Result { let output_path = path.join(&filename); - println!("保存图片: {}", &output_path.to_str().unwrap()); + info!("保存图片: {}", &output_path.to_str().unwrap()); image.save(output_path).unwrap(); i += 1; } - println!("运行耗时: {:?}", start.elapsed()); + info!("运行耗时: {:?}", start.elapsed()); Ok(filename) } @@ -94,7 +95,7 @@ fn monitor_capture(path: PathBuf) -> Result { image.save(output_path.to_str().unwrap()).unwrap(); } - println!("运行耗时: {:?}", start.elapsed()); + info!("运行耗时: {:?}", start.elapsed()); Ok(filename) } diff --git a/src-tauri/src/common.rs b/src-tauri/src/common.rs index 92cbb1d..a644a14 100644 --- a/src-tauri/src/common.rs +++ b/src-tauri/src/common.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use tauri::Manager; use tauri_plugin_store::StoreExt; +use tracing::info; pub fn get_images_dir(app_handle: &tauri::AppHandle, path: String) -> Result { let store = app_handle @@ -11,7 +12,7 @@ pub fn get_images_dir(app_handle: &tauri::AppHandle, path: String) -> Result let screenshot_path = screenshot_path @@ -27,7 +28,7 @@ pub fn get_images_dir(app_handle: &tauri::AppHandle, path: String) -> Result Result anyhow::Result<()> { - println!("Registering global shortcuts"); + info!("Registering global shortcuts"); let shortcuts = app.global_shortcut(); if let Err(error) = shortcuts.unregister_all() { - println!("Unable to unregister shortcuts {}", error.to_string()); + info!("Unable to unregister shortcuts {}", error.to_string()); } // capture_screen: ctrl + shift + A @@ -43,7 +44,7 @@ pub fn tauri_plugin_global_shortcut() -> TauriPlugin { if shortcut.id == Shortcut::from_str(DEFUALT_HOTKEY_A).unwrap().id { match event.state() { ShortcutState::Pressed => { - println!("Capture Screen Pressed!"); + info!("Capture Screen Pressed!"); let filename = tauri::async_runtime::block_on(platform::capture_screen( &app, "images".to_string(), @@ -56,7 +57,7 @@ pub fn tauri_plugin_global_shortcut() -> TauriPlugin { }); } ShortcutState::Released => { - println!("Capture Screen Released!"); + info!("Capture Screen Released!"); } } } else if shortcut.id == Shortcut::from_str(DEFUALT_HOTKEY_S).unwrap().id { @@ -74,7 +75,7 @@ pub fn tauri_plugin_global_shortcut() -> TauriPlugin { }); } ShortcutState::Released => { - println!("Capture Select Released!"); + info!("Capture Select Released!"); } } } else if shortcut.id == Shortcut::from_str(DEFUALT_HOTKEY_W).unwrap().id { @@ -92,7 +93,7 @@ pub fn tauri_plugin_global_shortcut() -> TauriPlugin { }); } ShortcutState::Released => { - println!("Capture Window Released!"); + info!("Capture Window Released!"); } } } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c3522e1..fceebf4 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,5 +1,5 @@ use serde_json::json; -use tauri::Manager; +use tauri::{ActivationPolicy, Manager}; use tauri_plugin_store::StoreExt; mod cmd; @@ -9,6 +9,7 @@ mod global_shortcut; mod menu; mod platform; mod window; +mod xcap_utils; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { @@ -20,6 +21,8 @@ pub fn run() { #[cfg(desktop)] let _ = global_shortcut::register_global_shortcut(app); + app.set_activation_policy(ActivationPolicy::Accessory); + menu::create_tray(app)?; let app_local_data = app diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 542bd63..d6bd012 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,12 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +use tracing::level_filters::LevelFilter; +use tracing_subscriber::{fmt::Layer, layer::SubscriberExt, util::SubscriberInitExt, Layer as _}; + fn main() { + let layer = Layer::new().with_filter(LevelFilter::INFO); + tracing_subscriber::registry().with(layer).init(); + ddu_lib::run() } diff --git a/src-tauri/src/menu.rs b/src-tauri/src/menu.rs index 26b2e08..03e1df5 100644 --- a/src-tauri/src/menu.rs +++ b/src-tauri/src/menu.rs @@ -6,6 +6,7 @@ use tauri::{ tray::{TrayIcon, TrayIconBuilder, TrayIconEvent}, AppHandle, Emitter, }; +use tracing::info; use crate::{platform, window}; @@ -148,7 +149,7 @@ pub fn get_app_menu(app: &AppHandle) -> Result, tauri::Error> { fn handle_tray_icon_events(_tray: &TrayIcon, event: TrayIconEvent) { if let TrayIconEvent::DoubleClick { .. } = event { - println!("Double click"); + info!("Double click"); } } @@ -161,7 +162,7 @@ fn handle_tray_menu_events(app: &AppHandle, event: MenuEvent) { match menu_id { MenuID::CAPTURE_SCREEN => { - println!("Capture Screen"); + info!("Capture Screen"); // 获取到 file na let filename = tauri::async_runtime::block_on(platform::capture_screen( &app, @@ -176,7 +177,7 @@ fn handle_tray_menu_events(app: &AppHandle, event: MenuEvent) { }); } MenuID::CAPTURE_SELECT => { - println!("Capture Select"); + info!("Capture Select"); let filename = tauri::async_runtime::block_on(platform::capture_select( &app, "images".to_string(), @@ -189,7 +190,7 @@ fn handle_tray_menu_events(app: &AppHandle, event: MenuEvent) { }); } MenuID::CAPTURE_WINDOW => { - println!("Capture Window"); + info!("Capture Window"); let filename = tauri::async_runtime::block_on(platform::capture_window( &app, "images".to_string(), @@ -202,22 +203,22 @@ fn handle_tray_menu_events(app: &AppHandle, event: MenuEvent) { }); } MenuID::SHOW_MAIN_WINDOW => { - println!("Show Home"); + info!("Show Home"); window::show_main_window(&app); } MenuID::SHOW_SETTING_WINDOW => { - println!("Setting Manager"); + info!("Setting Manager"); window::show_setting_window(&app); } MenuID::EXIT => { - println!("Exit"); + info!("Exit"); app.exit(0) } MenuID::HELP => { - println!("Help"); + info!("Help"); } MenuID::FEEDBACK => { - println!("Feedback"); + info!("Feedback"); } } } diff --git a/src-tauri/src/platform/mac/screenshot.rs b/src-tauri/src/platform/mac/screenshot.rs index 2dfd0c9..0847a93 100644 --- a/src-tauri/src/platform/mac/screenshot.rs +++ b/src-tauri/src/platform/mac/screenshot.rs @@ -5,6 +5,7 @@ use std::{ }; use chrono::Local; +use tracing::info; use crate::common::get_images_dir; @@ -13,7 +14,7 @@ pub async fn capture_screen(app_handle: &tauri::AppHandle, path: String) -> Resu let images_dir = get_images_dir(&app_handle, path)?; - println!("images_dir: {:?}", images_dir); + info!("images_dir: {:?}", images_dir); std::fs::create_dir_all(&images_dir).map_err(|e| e.to_string())?; let filename = format!("screenshot_{}.png", Local::now().format("%Y%m%d_%H%M%S")); @@ -25,7 +26,7 @@ pub async fn capture_screen(app_handle: &tauri::AppHandle, path: String) -> Resu .output() .map_err(|e| e.to_string())?; - println!("capture_screen 运行耗时: {:?}", start.elapsed()); + info!("capture_screen 运行耗时: {:?}", start.elapsed()); Ok(filename) } @@ -44,7 +45,7 @@ pub async fn capture_select(app_handle: &tauri::AppHandle, path: String) -> Resu .output() .map_err(|e| e.to_string())?; - println!("capture_select 运行耗时: {:?}", start.elapsed()); + info!("capture_select 运行耗时: {:?}", start.elapsed()); Ok(filename) } @@ -81,10 +82,10 @@ pub async fn capture_window(app_handle: &tauri::AppHandle, path: String) -> Resu .map_err(|e| e.to_string())?; if !output.status.success() { - println!("screencapture -wx 失败: {:?}", output.status); + info!("screencapture -wx 失败: {:?}", output.status); } - println!("capture_window 运行耗时: {:?}", start.elapsed()); + info!("capture_window 运行耗时: {:?}", start.elapsed()); Ok(filename) } diff --git a/src-tauri/src/window.rs b/src-tauri/src/window.rs index 5ee4065..842f34a 100644 --- a/src-tauri/src/window.rs +++ b/src-tauri/src/window.rs @@ -1,5 +1,6 @@ use tauri::{window::Color, TitleBarStyle, WebviewUrl, WebviewWindowBuilder}; use tauri::{AppHandle, Manager, Monitor, PhysicalPosition, WebviewWindow}; +use tracing::info; use crate::constants::{MAIN_WINDOW, PREVIEW_WINDOW, SETTING_WINDOW}; use crate::platform; @@ -38,7 +39,7 @@ pub fn center_position(window: &WebviewWindow) { let _ = window.set_position(tauri::Position::Physical(new_position)); } else { - println!("Unable to detect any monitors."); + info!("Unable to detect any monitors."); } } @@ -64,7 +65,7 @@ pub fn bottom_right_position(window: &WebviewWindow) { let _ = window.set_position(tauri::Position::Physical(new_position)); } else { - println!("Unable to detect any monitors."); + info!("Unable to detect any monitors."); } } @@ -76,6 +77,7 @@ pub fn get_main_window(app: &AppHandle) -> WebviewWindow { .title("ddu") .title_bar_style(TitleBarStyle::Transparent) .background_color(Color(10, 100, 100, 1)) + .skip_taskbar(true) .inner_size(800.0, 600.0); let window = win_builder.build().unwrap(); @@ -111,6 +113,7 @@ pub fn get_setting_window(app: &AppHandle) -> WebviewWindow { .minimizable(false) .maximizable(false) .resizable(false) + .skip_taskbar(true) .fullscreen(false) .inner_size(600.0, 400.0); @@ -148,6 +151,7 @@ pub fn get_preview_window(app: &AppHandle) -> WebviewWindow { .decorations(false) .transparent(true) .visible(true) + .skip_taskbar(true) .shadow(false) .resizable(false) .inner_size(240.0, 240.0); diff --git a/src-tauri/src/xcap_utils.rs b/src-tauri/src/xcap_utils.rs index 4456c7c..3c2be90 100644 --- a/src-tauri/src/xcap_utils.rs +++ b/src-tauri/src/xcap_utils.rs @@ -1,6 +1,7 @@ use std::time::Instant; use tauri::{window::Color, TitleBarStyle, WebviewUrl, WebviewWindowBuilder}; use tauri::{AppHandle, PhysicalPosition, WebviewWindow}; +use tracing::info; use xcap::Monitor; use xcap::Window; @@ -8,10 +9,10 @@ use xcap::Window; pub fn display_windows() { let start = Instant::now(); let windows = Window::all().unwrap(); - println!("Window::all() 运行耗时: {:?}", start.elapsed()); + info!("Window::all() 运行耗时: {:?}", start.elapsed()); for window in windows { - println!( + info!( "Window:\n id: {}\n title: {}\n app_name: {}\n monitor: {:?}\n position: {:?}\n size {:?}\n state {:?}\n", window.id(), window.title(), @@ -23,16 +24,16 @@ pub fn display_windows() { ); } - println!("运行耗时: {:?}", start.elapsed()); + info!("运行耗时: {:?}", start.elapsed()); } pub fn display_monitors() { let start = Instant::now(); let monitors = Monitor::all().unwrap(); - println!("Monitor::all() 运行耗时: {:?}", start.elapsed()); + info!("Monitor::all() 运行耗时: {:?}", start.elapsed()); for monitor in monitors { - println!( + info!( "Monitor:\n id: {}\n name: {}\n position: {:?}\n size: {:?}\n state:{:?}\n", monitor.id(), monitor.name(), @@ -49,12 +50,12 @@ pub fn display_monitors() { let monitor = Monitor::from_point(100, 100).unwrap(); - println!("Monitor::from_point(): {}", monitor.name()); - println!( + info!("Monitor::from_point(): {}", monitor.name()); + info!( "Monitor::from_point(100, 100) 运行耗时: {:?}", start.elapsed() ); - println!("运行耗时: {:?}", start.elapsed()); + info!("运行耗时: {:?}", start.elapsed()); } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5d3d13b..8b515e4 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -20,6 +20,7 @@ "minimizable": false, "maximizable": false, "fullscreen": false, + "skipTaskbar": true, "visible": false, "height": 400, "width": 600