Skip to content

Commit

Permalink
ci: fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Aug 30, 2023
1 parent 85112e7 commit 1bb0934
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
9 changes: 0 additions & 9 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 19 additions & 18 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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>,
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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"))]
Expand Down Expand Up @@ -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
Expand All @@ -2101,8 +2102,8 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
.insert(
id,
TrayContext {
tray: Arc::new(Mutex::new(Some(tray))),
listeners: Arc::new(Mutex::new(listeners)),
tray: Rc::new(Mutex::new(Some(tray))),
listeners: Rc::new(RefCell::new(listeners)),
items: Arc::new(Mutex::new(items)),

Check failure on line 2107 in core/tauri-runtime-wry/src/lib.rs

View workflow job for this annotation

GitHub Actions / all

usage of an `Arc` that is not `Send` or `Sync`

error: usage of an `Arc` that is not `Send` or `Sync` --> core/tauri-runtime-wry/src/lib.rs:2107:18 | 2107 | items: Arc::new(Mutex::new(items)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the trait `Send` is not implemented for `Mutex<HashMap<u16, CustomMenuItem>>` = note: the trait `Sync` is not implemented for `Mutex<HashMap<u16, CustomMenuItem>>` = note: required for `Arc<Mutex<HashMap<u16, CustomMenuItem>>>` to implement `Send` and `Sync` = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings`
},
);
Expand Down Expand Up @@ -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"))]
Expand All @@ -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>>,
Expand Down Expand Up @@ -2645,15 +2646,15 @@ 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)),
tray: Rc::new(Mutex::new(Some(tray))),
listeners: Rc::new(RefCell::new(listeners)),
items: Arc::new(Mutex::new(items)),

Check failure on line 2658 in core/tauri-runtime-wry/src/lib.rs

View workflow job for this annotation

GitHub Actions / all

usage of an `Arc` that is not `Send` or `Sync`

error: usage of an `Arc` that is not `Send` or `Sync` --> core/tauri-runtime-wry/src/lib.rs:2658:24 | 2658 | items: Arc::new(Mutex::new(items)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the trait `Send` is not implemented for `Mutex<HashMap<u16, CustomMenuItem>>` = note: the trait `Sync` is not implemented for `Mutex<HashMap<u16, CustomMenuItem>>` = note: required for `Arc<Mutex<HashMap<u16, CustomMenuItem>>>` to implement `Send` and `Sync` = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
},
);
Expand Down Expand Up @@ -2716,7 +2717,7 @@ fn handle_user_message<T: UserEvent>(
}
TrayMessage::Destroy(tx) => {
*tray_context.tray.lock().unwrap() = None;
tray_context.listeners.lock().unwrap().clear();
tray_context.listeners.borrow_mut().clear();
tray_context.items.lock().unwrap().clear();
tx.send(Ok(())).unwrap();
}
Expand Down Expand Up @@ -2847,7 +2848,7 @@ fn handle_event_loop<T: UserEvent>(
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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions core/tauri-runtime-wry/src/system_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ 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},
};

pub type GlobalSystemTrayEventHandler = Box<dyn Fn(TrayId, &SystemTrayEvent) + Send>;
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 SystemTrayEventListeners = Rc<RefCell<Vec<Rc<SystemTrayEventHandler>>>>;
pub type SystemTrayItems = Arc<Mutex<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,
}
Expand Down

0 comments on commit 1bb0934

Please sign in to comment.