feat: update to alpha.11 (#555)

This commit is contained in:
Lucas Fernandes Nogueira
2023-08-14 14:51:20 -03:00
committed by GitHub
parent d5a7c77a8d
commit d74fc0a097
67 changed files with 628 additions and 538 deletions
+20 -31
View File
@@ -9,7 +9,7 @@
//!
//! # Cargo features
//!
//! - **system-tray**: Enables system-tray-relative positions.
//! - **tray-icon**: Enables tray-icon-relative positions.
//!
//! Note: This requires attaching the Tauri plugin, *even* when using the trait extension only.
@@ -27,38 +27,27 @@ use tauri::{
Result, Runtime,
};
#[cfg(feature = "system-tray")]
use tauri::{AppHandle, Manager, PhysicalPosition, PhysicalSize, SystemTrayEvent};
#[cfg(feature = "tray-icon")]
use tauri::{tray::TrayIconEvent, AppHandle, Manager, PhysicalPosition, PhysicalSize};
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
struct Tray(std::sync::Mutex<Option<(PhysicalPosition<f64>, PhysicalSize<f64>)>>);
#[cfg(feature = "system-tray")]
pub fn on_tray_event<R: Runtime>(app: &AppHandle<R>, event: &SystemTrayEvent) {
match event {
SystemTrayEvent::LeftClick { position, size, .. } => {
app.state::<Tray>()
.0
.lock()
.unwrap()
.replace((*position, *size));
}
SystemTrayEvent::RightClick { position, size, .. } => {
app.state::<Tray>()
.0
.lock()
.unwrap()
.replace((*position, *size));
}
SystemTrayEvent::DoubleClick { position, size, .. } => {
app.state::<Tray>()
.0
.lock()
.unwrap()
.replace((*position, *size));
}
_ => (),
}
#[cfg(feature = "tray-icon")]
pub fn on_tray_event<R: Runtime>(app: &AppHandle<R>, event: &TrayIconEvent) {
let position = PhysicalPosition {
x: event.x,
y: event.y,
};
let size = PhysicalSize {
width: event.icon_rect.right - event.icon_rect.left,
height: event.icon_rect.bottom - event.icon_rect.top,
};
app.state::<Tray>()
.0
.lock()
.unwrap()
.replace((position, size));
}
#[tauri::command]
@@ -72,7 +61,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![move_window]);
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
let plugin = plugin.setup(|app_handle, _api| {
app_handle.manage(Tray(std::sync::Mutex::new(None)));
Ok(())