feat: update to alpha.11 (#555)

This commit is contained in:
Lucas Fernandes Nogueira
2023-08-14 10:51:20 -07:00
committed by GitHub
parent d5a7c77a8d
commit d74fc0a097
67 changed files with 629 additions and 539 deletions
+1 -1
View File
@@ -19,4 +19,4 @@ thiserror = { workspace = true }
serde_repr = "0.1"
[features]
system-tray = [ "tauri/system-tray" ]
tray-icon = [ "tauri/tray-icon" ]
+1 -1
View File
@@ -28,6 +28,6 @@
"tslib": "2.6.0"
},
"dependencies": {
"@tauri-apps/api": "2.0.0-alpha.5"
"@tauri-apps/api": "2.0.0-alpha.6"
}
}
+15 -15
View File
@@ -3,10 +3,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
use crate::Tray;
use serde_repr::Deserialize_repr;
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
use tauri::Manager;
use tauri::{PhysicalPosition, PhysicalSize, Result, Runtime, Window};
@@ -23,17 +23,17 @@ pub enum Position {
LeftCenter,
RightCenter,
Center,
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayLeft,
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayBottomLeft,
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayRight,
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayBottomRight,
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayCenter,
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayBottomCenter,
}
@@ -59,7 +59,7 @@ impl<R: Runtime> WindowExt for Window<R> {
width: self.outer_size()?.width as i32,
height: self.outer_size()?.height as i32,
};
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
let (tray_position, tray_size) = self
.state::<Tray>()
.0
@@ -107,7 +107,7 @@ impl<R: Runtime> WindowExt for Window<R> {
x: screen_position.x + ((screen_size.width / 2) - (window_size.width / 2)),
y: screen_position.y + (screen_size.height / 2) - (window_size.height / 2),
},
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayLeft => {
if let Some((tray_x, tray_y)) = tray_position {
PhysicalPosition {
@@ -118,7 +118,7 @@ impl<R: Runtime> WindowExt for Window<R> {
panic!("tray position not set");
}
}
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayBottomLeft => {
if let Some((tray_x, tray_y)) = tray_position {
PhysicalPosition {
@@ -129,7 +129,7 @@ impl<R: Runtime> WindowExt for Window<R> {
panic!("Tray position not set");
}
}
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayRight => {
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size)
{
@@ -141,7 +141,7 @@ impl<R: Runtime> WindowExt for Window<R> {
panic!("Tray position not set");
}
}
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayBottomRight => {
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size)
{
@@ -153,7 +153,7 @@ impl<R: Runtime> WindowExt for Window<R> {
panic!("Tray position not set");
}
}
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayCenter => {
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size)
{
@@ -165,7 +165,7 @@ impl<R: Runtime> WindowExt for Window<R> {
panic!("Tray position not set");
}
}
#[cfg(feature = "system-tray")]
#[cfg(feature = "tray-icon")]
TrayBottomCenter => {
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size)
{
+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(())