diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 2901f5d29b66..f5326c071636 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -406,15 +406,6 @@ pub fn try_build(attributes: Attributes) -> Result<()> { res.set_manifest(include_str!("window-app-manifest.xml")); } - if let Some(sdk_dir) = &attributes.windows_attributes.sdk_dir { - if let Some(sdk_dir_str) = sdk_dir.to_str() { - res.set_toolkit_path(sdk_dir_str); - } else { - return Err(anyhow!( - "sdk_dir path is not valid; only UTF-8 characters are allowed" - )); - } - } if let Some(version_str) = &config.package.version { if let Ok(v) = Version::parse(version_str) { let version = v.major << 48 | v.minor << 32 | v.patch << 16; diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index e26f8f8f1957..83eff15eaa3d 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -5,6 +5,7 @@ //! The [`wry`] Tauri [`Runtime`]. use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle}; +use std::rc::Rc; use tauri_runtime::{ http::{header::CONTENT_TYPE, Request as HttpRequest, RequestParts, Response as HttpResponse}, menu::{AboutMetadata, CustomMenuItem, Menu, MenuEntry, MenuHash, MenuId, MenuItem, MenuUpdate}, @@ -251,7 +252,7 @@ pub struct DispatcherMainThreadContext { pub global_shortcut_manager: Arc>, #[cfg(feature = "clipboard")] pub clipboard_manager: Arc>, - pub windows: Arc>>, + pub windows: Rc>>, #[cfg(all(desktop, feature = "system-tray"))] system_tray_manager: SystemTrayManager, } @@ -1671,7 +1672,7 @@ impl Dispatch for WryDispatcher { #[derive(Clone)] enum WindowHandle { Webview { - inner: Arc, + inner: Rc, context_store: WebContextStore, // the key of the WebContext if it's not shared context_key: Option, @@ -1687,7 +1688,7 @@ impl Drop for WindowHandle { context_key, } = self { - if Arc::get_mut(inner).is_some() { + if Rc::get_mut(inner).is_some() { context_store.lock().unwrap().remove(context_key); } } @@ -1941,7 +1942,7 @@ impl Wry { #[cfg(feature = "clipboard")] let clipboard_manager = Arc::new(Mutex::new(Clipboard::new())); - let windows = Arc::new(RefCell::new(HashMap::default())); + let windows = Rc::new(RefCell::new(HashMap::default())); let webview_id_map = WebviewIdStore::default(); #[cfg(all(desktop, feature = "system-tray"))] @@ -2088,7 +2089,7 @@ impl Runtime for Wry { let id = system_tray.id; let mut listeners = Vec::new(); if let Some(l) = system_tray.on_event.take() { - listeners.push(Arc::new(l)); + listeners.push(Rc::new(l)); } let (tray, items) = create_tray(WryTrayId(id), system_tray, &self.event_loop)?; self @@ -2101,9 +2102,9 @@ impl Runtime for Wry { .insert( id, TrayContext { - tray: Arc::new(Mutex::new(Some(tray))), - listeners: Arc::new(Mutex::new(listeners)), - items: Arc::new(Mutex::new(items)), + tray: Rc::new(Mutex::new(Some(tray))), + listeners: Rc::new(RefCell::new(listeners)), + items: Rc::new(RefCell::new(items)), }, ); @@ -2304,7 +2305,7 @@ impl Runtime for Wry { pub struct EventLoopIterationContext<'a, T: UserEvent> { pub callback: &'a mut (dyn FnMut(RunEvent) + 'static), pub webview_id_map: WebviewIdStore, - pub windows: Arc>>, + pub windows: Rc>>, #[cfg(all(desktop, feature = "global-shortcut"))] pub global_shortcut_manager: Arc>, #[cfg(all(desktop, feature = "global-shortcut"))] @@ -2316,7 +2317,7 @@ pub struct EventLoopIterationContext<'a, T: UserEvent> { } struct UserMessageContext { - windows: Arc>>, + windows: Rc>>, webview_id_map: WebviewIdStore, #[cfg(all(desktop, feature = "global-shortcut"))] global_shortcut_manager: Arc>, @@ -2645,16 +2646,16 @@ fn handle_user_message( if let TrayMessage::Create(mut tray, tx) = tray_message { let mut listeners = Vec::new(); if let Some(l) = tray.on_event.take() { - listeners.push(Arc::new(l)); + listeners.push(Rc::new(l)); } match create_tray(WryTrayId(tray_id), tray, event_loop) { Ok((tray, items)) => { trays.insert( tray_id, TrayContext { - tray: Arc::new(Mutex::new(Some(tray))), - listeners: Arc::new(Mutex::new(listeners)), - items: Arc::new(Mutex::new(items)), + tray: Rc::new(Mutex::new(Some(tray))), + listeners: Rc::new(RefCell::new(listeners)), + items: Rc::new(RefCell::new(items)), }, ); @@ -2668,7 +2669,7 @@ fn handle_user_message( } else if let Some(tray_context) = trays.get(&tray_id) { match tray_message { TrayMessage::UpdateItem(menu_id, update) => { - let mut tray = tray_context.items.as_ref().lock().unwrap(); + let mut tray = tray_context.items.as_ref().borrow_mut(); let item = tray.get_mut(&menu_id).expect("menu item not found"); match update { MenuUpdate::SetEnabled(enabled) => item.set_enabled(enabled), @@ -2684,7 +2685,7 @@ fn handle_user_message( if let Some(tray) = &mut *tray_context.tray.lock().unwrap() { let mut items = HashMap::new(); tray.set_menu(&to_wry_context_menu(&mut items, menu)); - *tray_context.items.lock().unwrap() = items; + *tray_context.items.borrow_mut() = items; } } TrayMessage::UpdateIcon(icon) => { @@ -2716,8 +2717,8 @@ fn handle_user_message( } TrayMessage::Destroy(tx) => { *tray_context.tray.lock().unwrap() = None; - tray_context.listeners.lock().unwrap().clear(); - tray_context.items.lock().unwrap().clear(); + tray_context.listeners.borrow_mut().clear(); + tray_context.items.borrow_mut().clear(); tx.send(Ok(())).unwrap(); } } @@ -2843,11 +2844,11 @@ fn handle_event_loop( let (mut listeners, mut tray_id) = (None, 0); for (id, tray_context) in trays_iter { let has_menu = { - let items = tray_context.items.lock().unwrap(); + let items = tray_context.items.borrow(); items.contains_key(&menu_id.0) }; if has_menu { - listeners.replace(tray_context.listeners.lock().unwrap().clone()); + listeners.replace(tray_context.listeners.borrow().clone()); tray_id = *id; break; } @@ -2886,7 +2887,7 @@ fn handle_event_loop( }; let trays = system_tray_manager.trays.lock().unwrap(); if let Some(tray_context) = trays.get(&id.0) { - let listeners = tray_context.listeners.lock().unwrap(); + let listeners = tray_context.listeners.borrow(); let iter = listeners.iter(); for handler in iter { handler(&event); @@ -3016,7 +3017,7 @@ fn handle_event_loop( fn on_close_requested<'a, T: UserEvent>( callback: &'a mut (dyn FnMut(RunEvent) + 'static), window_id: WebviewId, - windows: Arc>>, + windows: Rc>>, ) { let (tx, rx) = channel(); let windows_ref = windows.borrow(); @@ -3044,7 +3045,7 @@ fn on_close_requested<'a, T: UserEvent>( } } -fn on_window_close(window_id: WebviewId, windows: Arc>>) { +fn on_window_close(window_id: WebviewId, windows: Rc>>) { if let Some(window_wrapper) = windows.borrow_mut().get_mut(&window_id) { window_wrapper.inner = None; } @@ -3289,7 +3290,7 @@ fn create_webview( Ok(WindowWrapper { label, inner: Some(WindowHandle::Webview { - inner: Arc::new(webview), + inner: Rc::new(webview), context_store: web_context_store.clone(), context_key: if automation_enabled { None diff --git a/core/tauri-runtime-wry/src/system_tray.rs b/core/tauri-runtime-wry/src/system_tray.rs index 594e13cc4908..eab2e7b06a7c 100644 --- a/core/tauri-runtime-wry/src/system_tray.rs +++ b/core/tauri-runtime-wry/src/system_tray.rs @@ -32,8 +32,10 @@ use crate::{send_user_message, Context, Error, Message, Result, TrayId, TrayMess use tauri_runtime::{menu::MenuHash, SystemTray, UserEvent}; use std::{ + cell::RefCell, collections::HashMap, fmt, + rc::Rc, sync::{Arc, Mutex}, }; @@ -41,12 +43,12 @@ pub type GlobalSystemTrayEventHandler = Box>>>; pub type SystemTrayEventHandler = Box; -pub type SystemTrayEventListeners = Arc>>>; -pub type SystemTrayItems = Arc>>; +pub type SystemTrayEventListeners = Rc>>>; +pub type SystemTrayItems = Rc>>; #[derive(Clone, Default)] pub struct TrayContext { - pub tray: Arc>>, + pub tray: Rc>>, pub listeners: SystemTrayEventListeners, pub items: SystemTrayItems, }