فهرست منبع

fix(core): linting errors

Lucas Nogueira 3 سال پیش
والد
کامیت
73860840a6

+ 26 - 20
core/tauri-runtime-wry/src/lib.rs

@@ -2446,15 +2446,15 @@ fn handle_user_message<T: UserEvent>(
       }
       WebviewMessage::WebviewEvent(event) => {
         if let Some(event) = WindowEventWrapper::from(&event).0 {
-          for handler in window_event_listeners
+          let shared_listeners = window_event_listeners
             .lock()
             .unwrap()
             .get(&id)
             .unwrap()
-            .lock()
-            .unwrap()
-            .values()
-          {
+            .clone();
+          let listeners = shared_listeners.lock().unwrap();
+          let handlers = listeners.values();
+          for handler in handlers {
             handler(&event);
           }
         }
@@ -2642,7 +2642,9 @@ fn handle_event_loop<T: UserEvent>(
         let listeners = menu_event_listeners.lock().unwrap();
         listeners.get(&window_id).cloned().unwrap_or_default()
       };
-      for handler in window_menu_event_listeners.lock().unwrap().values() {
+      let listeners = window_menu_event_listeners.lock().unwrap();
+      let handlers = listeners.values();
+      for handler in handlers {
         handler(&event);
       }
     }
@@ -2676,7 +2678,9 @@ fn handle_event_loop<T: UserEvent>(
         // default to left click
         _ => SystemTrayEvent::LeftClick { position, size },
       };
-      for handler in tray_context.listeners.lock().unwrap().values() {
+      let listeners = tray_context.listeners.lock().unwrap();
+      let handlers = listeners.values();
+      for handler in handlers {
         handler(&event);
       }
     }
@@ -2714,15 +2718,15 @@ fn handle_event_loop<T: UserEvent>(
               label,
               event: event.clone(),
             });
-            for handler in window_event_listeners
+            let shared_listeners = window_event_listeners
               .lock()
               .unwrap()
               .get(&window_id)
               .unwrap()
-              .lock()
-              .unwrap()
-              .values()
-            {
+              .clone();
+            let listeners = shared_listeners.lock().unwrap();
+            let handlers = listeners.values();
+            for handler in handlers {
               handler(&event);
             }
           }
@@ -2813,15 +2817,15 @@ fn on_close_requested<'a, T: UserEvent>(
   if let Some(w) = windows_guard.get(&window_id) {
     let label = w.label.clone();
     drop(windows_guard);
-    for handler in window_event_listeners
+    let shared_listeners = window_event_listeners
       .lock()
       .unwrap()
       .get(&window_id)
       .unwrap()
-      .lock()
-      .unwrap()
-      .values()
-    {
+      .clone();
+    let listeners = shared_listeners.lock().unwrap();
+    let handlers = listeners.values();
+    for handler in handlers {
       handler(&WindowEvent::CloseRequested {
         signal_tx: tx.clone(),
       });
@@ -2974,7 +2978,7 @@ fn create_webview<T: UserEvent>(
   let mut web_context = web_context.lock().expect("poisoned WebContext store");
   let is_first_context = web_context.is_empty();
   let automation_enabled = std::env::var("TAURI_AUTOMATION").as_deref() == Ok("true");
-  let web_context = match web_context.entry(
+  let entry = web_context.entry(
     // force a unique WebContext when automation is false;
     // the context must be stored on the HashMap because it must outlive the WebView on macOS
     if automation_enabled {
@@ -2983,7 +2987,8 @@ fn create_webview<T: UserEvent>(
       // random unique key
       Some(Uuid::new_v4().as_hyphenated().to_string().into())
     },
-  ) {
+  );
+  let web_context = match entry {
     Occupied(occupied) => occupied.into_mut(),
     Vacant(vacant) => {
       let mut web_context = WebContext::new(webview_attributes.data_directory);
@@ -3088,7 +3093,8 @@ fn create_file_drop_handler<T: UserEvent>(
     if let Some(window_listeners) = listeners.get(&webview_id_map.get(&window.id())) {
       let listeners_map = window_listeners.lock().unwrap();
       let has_listener = !listeners_map.is_empty();
-      for listener in listeners_map.values() {
+      let handlers = listeners_map.values();
+      for listener in handlers {
         listener(&window_event);
       }
       // block the default OS action on file drop if we had a listener

+ 11 - 2
core/tauri/src/api/cli.rs

@@ -151,10 +151,12 @@ fn get_matches_internal(config: &CliConfig, matches: &ArgMatches) -> Matches {
 fn map_matches(config: &CliConfig, matches: &ArgMatches, cli_matches: &mut Matches) {
   if let Some(args) = config.args() {
     for arg in args {
+      #[allow(deprecated)]
       let occurrences = matches.occurrences_of(arg.name.clone());
       let value = if occurrences == 0 || !arg.takes_value {
         Value::Bool(occurrences > 0)
       } else if arg.multiple {
+        #[allow(deprecated)]
         matches
           .values_of(arg.name.clone())
           .map(|v| {
@@ -166,6 +168,7 @@ fn map_matches(config: &CliConfig, matches: &ArgMatches, cli_matches: &mut Match
           })
           .unwrap_or(Value::Null)
       } else {
+        #[allow(deprecated)]
         matches
           .value_of(arg.name.clone())
           .map(|v| Value::String(v.to_string()))
@@ -238,9 +241,15 @@ fn get_arg<'a>(arg_name: &'a str, arg: &'a CliArg) -> Arg<'a> {
   clap_arg = bind_string_arg!(arg, clap_arg, long_description, long_help);
   clap_arg = clap_arg.takes_value(arg.takes_value);
   clap_arg = clap_arg.multiple_values(arg.multiple);
-  clap_arg = clap_arg.multiple_occurrences(arg.multiple_occurrences);
+  #[allow(deprecated)]
+  {
+    clap_arg = clap_arg.multiple_occurrences(arg.multiple_occurrences);
+  }
   clap_arg = bind_value_arg!(arg, clap_arg, number_of_values);
-  clap_arg = bind_string_slice_arg!(arg, clap_arg, possible_values);
+  #[allow(deprecated)]
+  {
+    clap_arg = bind_string_slice_arg!(arg, clap_arg, possible_values);
+  }
   clap_arg = bind_value_arg!(arg, clap_arg, min_values);
   clap_arg = bind_value_arg!(arg, clap_arg, max_values);
   clap_arg = clap_arg.required(arg.required);

+ 3 - 1
core/tauri/src/api/process/command.rs

@@ -36,7 +36,9 @@ fn commands() -> &'static ChildStore {
 /// Kills all child processes created with [`Command`].
 /// By default it's called before the [`crate::App`] exits.
 pub fn kill_children() {
-  for child in commands().lock().unwrap().values() {
+  let commands = commands().lock().unwrap();
+  let children = commands.values();
+  for child in children {
     let _ = child.kill();
   }
 }

+ 3 - 1
core/tauri/src/app/tray.rs

@@ -119,7 +119,9 @@ impl<R: Runtime> Clone for SystemTrayMenuItemHandle<R> {
 impl<R: Runtime> SystemTrayHandle<R> {
   /// Gets a handle to the menu item that has the specified `id`.
   pub fn get_item(&self, id: MenuIdRef<'_>) -> SystemTrayMenuItemHandle<R> {
-    for (raw, item_id) in self.ids.lock().unwrap().iter() {
+    let ids = self.ids.lock().unwrap();
+    let iter = ids.iter();
+    for (raw, item_id) in iter {
       if item_id == id {
         return SystemTrayMenuItemHandle {
           id: *raw,

+ 5 - 3
core/tauri/src/manager.rs

@@ -969,7 +969,7 @@ impl<R: Runtime> WindowManager<R> {
   }
 
   fn event_initialization_script(&self) -> String {
-    return format!(
+    format!(
       "
       Object.defineProperty(window, '{function}', {{
         value: function (eventData) {{
@@ -987,7 +987,7 @@ impl<R: Runtime> WindowManager<R> {
     ",
       function = self.event_emit_function_name(),
       listeners = self.event_listeners_object_name()
-    );
+    )
   }
 }
 
@@ -1315,7 +1315,9 @@ fn on_window_event<R: Runtime>(
     WindowEvent::Destroyed => {
       window.emit(WINDOW_DESTROYED_EVENT, ())?;
       let label = window.label();
-      for window in manager.inner.windows.lock().unwrap().values() {
+      let windows_map = manager.inner.windows.lock().unwrap();
+      let windows = windows_map.values();
+      for window in windows {
         window.eval(&format!(
           r#"window.__TAURI_METADATA__.__windows = window.__TAURI_METADATA__.__windows.filter(w => w.label !== "{}");"#,
           label

+ 3 - 1
core/tauri/src/scope/fs.rs

@@ -127,7 +127,9 @@ impl Scope {
   }
 
   fn trigger(&self, event: Event) {
-    for listener in self.event_listeners.lock().unwrap().values() {
+    let listeners = self.event_listeners.lock().unwrap();
+    let handlers = listeners.values();
+    for listener in handlers {
       listener(&event);
     }
   }

+ 2 - 1
core/tauri/src/window.rs

@@ -1186,7 +1186,8 @@ impl<R: Runtime> Window<R> {
   pub(crate) fn unregister_js_listener(&self, id: u64) {
     let mut empty = None;
     let mut js_listeners = self.window.js_event_listeners.lock().unwrap();
-    for (key, ids) in js_listeners.iter_mut() {
+    let iter = js_listeners.iter_mut();
+    for (key, ids) in iter {
       if ids.contains(&id) {
         ids.remove(&id);
         if ids.is_empty() {

+ 3 - 1
core/tauri/src/window/menu.rs

@@ -67,7 +67,9 @@ impl<R: Runtime> Clone for MenuItemHandle<R> {
 impl<R: Runtime> MenuHandle<R> {
   /// Gets a handle to the menu item that has the specified `id`.
   pub fn get_item(&self, id: MenuIdRef<'_>) -> MenuItemHandle<R> {
-    for (raw, item_id) in self.ids.lock().unwrap().iter() {
+    let ids = self.ids.lock().unwrap();
+    let iter = ids.iter();
+    for (raw, item_id) in iter {
       if item_id == id {
         return MenuItemHandle {
           id: *raw,