1
1
mirror of https://github.com/tauri-apps/tauri.git synced 2024-12-23 02:32:28 +03:00

ci: fix clippy lints ()

* ci: fix clippy lints

* more lints
This commit is contained in:
Amr Bashir 2023-08-31 13:53:15 +03:00 committed by GitHub
parent e152662687
commit 49beb67dab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 36 deletions
core
tauri-build/src
tauri-runtime-wry/src

View File

@ -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;

View File

@ -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<T: UserEvent> {
pub global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
#[cfg(feature = "clipboard")]
pub clipboard_manager: Arc<Mutex<Clipboard>>,
pub windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
pub windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_manager: SystemTrayManager,
}
@ -1671,7 +1672,7 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
#[derive(Clone)]
enum WindowHandle {
Webview {
inner: Arc<WebView>,
inner: Rc<WebView>,
context_store: WebContextStore,
// the key of the WebContext if it's not shared
context_key: Option<PathBuf>,
@ -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<T: UserEvent> Wry<T> {
#[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<T: UserEvent> Runtime<T> for Wry<T> {
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<T: UserEvent> Runtime<T> for Wry<T> {
.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<T: UserEvent> Runtime<T> for Wry<T> {
pub struct EventLoopIterationContext<'a, T: UserEvent> {
pub callback: &'a mut (dyn FnMut(RunEvent<T>) + 'static),
pub webview_id_map: WebviewIdStore,
pub windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
pub windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
#[cfg(all(desktop, feature = "global-shortcut"))]
pub global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
#[cfg(all(desktop, feature = "global-shortcut"))]
@ -2316,7 +2317,7 @@ pub struct EventLoopIterationContext<'a, T: UserEvent> {
}
struct UserMessageContext {
windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
webview_id_map: WebviewIdStore,
#[cfg(all(desktop, feature = "global-shortcut"))]
global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
@ -2645,16 +2646,16 @@ fn handle_user_message<T: UserEvent>(
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<T: UserEvent>(
} 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<T: UserEvent>(
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<T: UserEvent>(
}
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<T: UserEvent>(
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<T: UserEvent>(
};
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<T: UserEvent>(
fn on_close_requested<'a, T: UserEvent>(
callback: &'a mut (dyn FnMut(RunEvent<T>) + 'static),
window_id: WebviewId,
windows: Arc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>,
) {
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<RefCell<HashMap<WebviewId, WindowWrapper>>>) {
fn on_window_close(window_id: WebviewId, windows: Rc<RefCell<HashMap<WebviewId, WindowWrapper>>>) {
if let Some(window_wrapper) = windows.borrow_mut().get_mut(&window_id) {
window_wrapper.inner = None;
}
@ -3289,7 +3290,7 @@ fn create_webview<T: UserEvent>(
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

View File

@ -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<dyn Fn(TrayId, &SystemTrayEvent) + S
pub type GlobalSystemTrayEventListeners = Arc<Mutex<Vec<Arc<GlobalSystemTrayEventHandler>>>>;
pub type SystemTrayEventHandler = Box<dyn Fn(&SystemTrayEvent) + Send>;
pub type SystemTrayEventListeners = Arc<Mutex<Vec<Arc<SystemTrayEventHandler>>>>;
pub type SystemTrayItems = Arc<Mutex<HashMap<u16, WryCustomMenuItem>>>;
pub type SystemTrayEventListeners = Rc<RefCell<Vec<Rc<SystemTrayEventHandler>>>>;
pub type SystemTrayItems = Rc<RefCell<HashMap<u16, WryCustomMenuItem>>>;
#[derive(Clone, Default)]
pub struct TrayContext {
pub tray: Arc<Mutex<Option<WrySystemTray>>>,
pub tray: Rc<Mutex<Option<WrySystemTray>>>,
pub listeners: SystemTrayEventListeners,
pub items: SystemTrayItems,
}