feat(tray-menu): for screenshot
This commit is contained in:
@@ -18,7 +18,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = ["macos-private-api"] }
|
||||
tauri = { version = "2", features = ["macos-private-api", "tray-icon"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
notify = "6.1.1"
|
||||
|
||||
@@ -18,15 +18,19 @@ use window::setup_window;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
|
||||
pub fn desktop() {
|
||||
use tauri::{
|
||||
menu::{Menu, MenuItem},
|
||||
tray::TrayIconBuilder,
|
||||
};
|
||||
|
||||
let watcher_state = new_shared_watcher_state();
|
||||
|
||||
let bruh = tauri::Builder::default()
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_log::Builder::new().build())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_store::Builder::new().build());
|
||||
|
||||
bruh.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_store::Builder::new().build())
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.manage(watcher_state)
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::handle_selected_folder,
|
||||
@@ -40,6 +44,28 @@ pub fn desktop() {
|
||||
])
|
||||
.setup(|app| {
|
||||
setup_window(app)?;
|
||||
|
||||
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
||||
let take_screenshot =
|
||||
MenuItem::with_id(app, "screenshot", "Screenshot", true, None::<&str>)?;
|
||||
|
||||
let menu = Menu::with_items(app, &[&quit_i, &take_screenshot])?;
|
||||
|
||||
TrayIconBuilder::new()
|
||||
.menu(&menu)
|
||||
.on_menu_event(|app, event| match event.id.as_ref() {
|
||||
"quit" => {
|
||||
app.exit(0);
|
||||
}
|
||||
"screenshot" => {
|
||||
let _ = screenshot::take_area_screenshot(app);
|
||||
}
|
||||
_ => {
|
||||
log::info!("{}", event.id().0)
|
||||
}
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
shortcut::enable_shortcut(app);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -51,7 +51,7 @@ fn screenshot(path: &PathBuf) -> Result<Output, String> {
|
||||
}
|
||||
|
||||
/// Takes a screenshot of a selected area and returns the image data as base64
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
pub fn take_area_screenshot<R: Runtime>(app: &AppHandle<R>) -> Result<String, String> {
|
||||
// Create a temporary file path
|
||||
let temp_dir = std::env::temp_dir();
|
||||
|
||||
Reference in New Issue
Block a user