Skip to content

Commit

Permalink
fix gtk api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jul 20, 2023
1 parent d71a11c commit 1a75a13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
8 changes: 4 additions & 4 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ macro_rules! shared_app_impl {
target_os = "openbsd"
))]
{
let _ = menu.init_for_gtk_windows(window.gtk_window().unwrap());
let _ = menu.init_for_gtk_window(&window.gtk_window().unwrap());
}
window_menu.replace((true, menu.clone()));
}
Expand Down Expand Up @@ -574,7 +574,7 @@ macro_rules! shared_app_impl {
target_os = "openbsd"
))]
{
let _ = menu.remove_for_gtk_windows(window.gtk_window()?);
let _ = menu.remove_for_gtk_window(&window.gtk_window()?);
}
*window.menu_lock() = None;
}
Expand Down Expand Up @@ -613,7 +613,7 @@ macro_rules! shared_app_impl {
target_os = "openbsd"
))]
{
let _ = menu.hide_for_gtk_windows(window.gtk_window()?);
let _ = menu.hide_for_gtk_window(&window.gtk_window()?);
}
}
}
Expand All @@ -639,7 +639,7 @@ macro_rules! shared_app_impl {
target_os = "openbsd"
))]
{
let _ = menu.show_for_gtk_windows(window.gtk_window()?);
let _ = menu.show_for_gtk_window(&window.gtk_window()?);
}
}
}
Expand Down
15 changes: 4 additions & 11 deletions core/tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ pub struct InnerWindowManager<R: Runtime> {
///
/// This should be mainly used to acceess [`Menu::haccel`]
/// to setup the accelerator handling in the event loop
#[cfg(windows)]

This comment has been minimized.

Copy link
@amrbashir

amrbashir Jul 20, 2023

Member

@lucasfernog this stash is only meant to be used on Windows, it doesn't have any usage on other platforms

pub menus: Arc<Mutex<HashMap<u32, Menu>>>,
/// The menu set to all windows.
pub(crate) menu: Arc<Mutex<Option<Menu>>>,
Expand Down Expand Up @@ -343,7 +342,6 @@ impl<R: Runtime> WindowManager<R> {
package_info: context.package_info,
pattern: context.pattern,
uri_scheme_protocols,
#[cfg(windows)]
menus: Default::default(),
menu: Arc::new(Mutex::new(menu)),
menu_event_listeners: Arc::new(Mutex::new(menu_event_listeners)),
Expand Down Expand Up @@ -377,7 +375,6 @@ impl<R: Runtime> WindowManager<R> {
}

/// Menus stash.
#[cfg(windows)]
pub(crate) fn menus_stash_lock(&self) -> MutexGuard<'_, HashMap<u32, Menu>> {
self.inner.menus.lock().expect("poisoned window manager")
}
Expand All @@ -392,18 +389,14 @@ impl<R: Runtime> WindowManager<R> {

/// Menus stash.
pub(crate) fn insert_menu_into_stash(&self, menu: &Menu) {
#[cfg(windows)]
self.menus_stash_lock().insert(menu.id(), menu.clone());
}

pub(crate) fn remove_menu_from_stash_by_id(&self, id: Option<u32>) {
#[cfg(windows)]
{
if let Some(id) = id {
let is_used_by_a_window = self.windows_lock().values().any(|w| w.is_menu_in_use(id));
if !(self.is_menu_in_use(id) || is_used_by_a_window) {
self.menus_stash_lock().remove(&id);
}
if let Some(id) = id {
let is_used_by_a_window = self.windows_lock().values().any(|w| w.is_menu_in_use(id));
if !(self.is_menu_in_use(id) || is_used_by_a_window) {
self.menus_stash_lock().remove(&id);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ impl<R: Runtime> Window<R> {
target_os = "openbsd"
))]
{
let _ = menu.init_for_gtk_windows(self.gtk_window().unwrap());
let _ = menu.init_for_gtk_window(&self.gtk_window().unwrap());
}

self.menu_lock().replace((false, menu.clone()));
Expand All @@ -1115,7 +1115,7 @@ impl<R: Runtime> Window<R> {
target_os = "openbsd"
))]
{
let _ = menu.remove_for_gtk_windows(self.gtk_window()?);
let _ = menu.remove_for_gtk_window(&self.gtk_window()?);
}
}

Expand Down Expand Up @@ -1146,7 +1146,7 @@ impl<R: Runtime> Window<R> {
target_os = "openbsd"
))]
{
let _ = menu.hide_for_gtk_windows(self.gtk_window()?);
let _ = menu.hide_for_gtk_window(&self.gtk_window()?);
}
}

Expand All @@ -1169,7 +1169,7 @@ impl<R: Runtime> Window<R> {
target_os = "openbsd"
))]
{
let _ = menu.show_for_gtk_windows(self.gtk_window()?);
let _ = menu.show_for_gtk_window(&self.gtk_window()?);
}
}

Expand All @@ -1192,7 +1192,7 @@ impl<R: Runtime> Window<R> {
target_os = "openbsd"
))]
{
return Ok(menu.is_visible_on_gtk_windows(self.gtk_window()?));
return Ok(menu.is_visible_on_gtk_window(&self.gtk_window()?));
}
}

Expand Down

0 comments on commit 1a75a13

Please sign in to comment.