mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
committed by
GitHub
parent
1b00855af8
commit
a280ee90af
6
.changes/mac-cpu.md
Normal file
6
.changes/mac-cpu.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-runtime-wry": patch
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Fix macOS high CPU usage.
|
||||
@@ -131,7 +131,7 @@ unsafe impl Send for GlobalShortcutWrapper {}
|
||||
#[derive(Clone)]
|
||||
pub struct GlobalShortcutManagerHandle {
|
||||
context: EventLoopContext,
|
||||
shortcuts: HashMap<String, (AcceleratorId, GlobalShortcutWrapper)>,
|
||||
shortcuts: Arc<Mutex<HashMap<String, (AcceleratorId, GlobalShortcutWrapper)>>>,
|
||||
listeners: GlobalShortcutListeners,
|
||||
}
|
||||
|
||||
@@ -159,7 +159,11 @@ impl GlobalShortcutManager for GlobalShortcutManagerHandle {
|
||||
)?;
|
||||
|
||||
self.listeners.lock().unwrap().insert(id, Box::new(handler));
|
||||
self.shortcuts.insert(accelerator.into(), (id, shortcut));
|
||||
self
|
||||
.shortcuts
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(accelerator.into(), (id, shortcut));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -172,12 +176,12 @@ impl GlobalShortcutManager for GlobalShortcutManagerHandle {
|
||||
Message::GlobalShortcut(GlobalShortcutMessage::UnregisterAll(tx))
|
||||
)?;
|
||||
self.listeners.lock().unwrap().clear();
|
||||
self.shortcuts.clear();
|
||||
self.shortcuts.lock().unwrap().clear();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn unregister(&mut self, accelerator: &str) -> Result<()> {
|
||||
if let Some((accelerator_id, shortcut)) = self.shortcuts.remove(accelerator) {
|
||||
if let Some((accelerator_id, shortcut)) = self.shortcuts.lock().unwrap().remove(accelerator) {
|
||||
let (tx, rx) = channel();
|
||||
getter!(
|
||||
self,
|
||||
@@ -1373,14 +1377,14 @@ impl Runtime for Wry {
|
||||
EventLoopIterationContext {
|
||||
callback: &callback,
|
||||
webviews: webviews.lock().expect("poisoned webview collection"),
|
||||
window_event_listeners: window_event_listeners.clone(),
|
||||
window_event_listeners: &window_event_listeners,
|
||||
global_shortcut_manager: global_shortcut_manager.clone(),
|
||||
global_shortcut_manager_handle: global_shortcut_manager_handle.clone(),
|
||||
global_shortcut_manager_handle: &global_shortcut_manager_handle,
|
||||
clipboard_manager: clipboard_manager.clone(),
|
||||
#[cfg(feature = "menu")]
|
||||
menu_event_listeners: menu_event_listeners.clone(),
|
||||
menu_event_listeners: &menu_event_listeners,
|
||||
#[cfg(feature = "system-tray")]
|
||||
tray_context: tray_context.clone(),
|
||||
tray_context: &tray_context,
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -1409,14 +1413,14 @@ impl Runtime for Wry {
|
||||
EventLoopIterationContext {
|
||||
callback: &callback,
|
||||
webviews: webviews.lock().expect("poisoned webview collection"),
|
||||
window_event_listeners: window_event_listeners.clone(),
|
||||
window_event_listeners: &window_event_listeners,
|
||||
global_shortcut_manager: global_shortcut_manager.clone(),
|
||||
global_shortcut_manager_handle: global_shortcut_manager_handle.clone(),
|
||||
global_shortcut_manager_handle: &global_shortcut_manager_handle,
|
||||
clipboard_manager: clipboard_manager.clone(),
|
||||
#[cfg(feature = "menu")]
|
||||
menu_event_listeners: menu_event_listeners.clone(),
|
||||
menu_event_listeners: &menu_event_listeners,
|
||||
#[cfg(feature = "system-tray")]
|
||||
tray_context: tray_context.clone(),
|
||||
tray_context: &tray_context,
|
||||
},
|
||||
);
|
||||
})
|
||||
@@ -1426,14 +1430,14 @@ impl Runtime for Wry {
|
||||
struct EventLoopIterationContext<'a> {
|
||||
callback: &'a (dyn Fn(RunEvent) + 'static),
|
||||
webviews: MutexGuard<'a, HashMap<WindowId, WebviewWrapper>>,
|
||||
window_event_listeners: WindowEventListeners,
|
||||
window_event_listeners: &'a WindowEventListeners,
|
||||
global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
|
||||
global_shortcut_manager_handle: GlobalShortcutManagerHandle,
|
||||
global_shortcut_manager_handle: &'a GlobalShortcutManagerHandle,
|
||||
clipboard_manager: Arc<Mutex<Clipboard>>,
|
||||
#[cfg(feature = "menu")]
|
||||
menu_event_listeners: MenuEventListeners,
|
||||
menu_event_listeners: &'a MenuEventListeners,
|
||||
#[cfg(feature = "system-tray")]
|
||||
tray_context: TrayContext,
|
||||
tray_context: &'a TrayContext,
|
||||
}
|
||||
|
||||
fn handle_event_loop(
|
||||
|
||||
Reference in New Issue
Block a user