Skip to content

Commit

Permalink
fix: add target_os condition on context_menu
Browse files Browse the repository at this point in the history
  • Loading branch information
pewsheen committed Nov 18, 2024
1 parent 58298f6 commit 7826826
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use glutin::{
};
use glutin_winit::DisplayBuilder;
#[cfg(any(target_os = "macos", target_os = "windows"))]
use muda::{Menu, MenuEvent, MenuEventReceiver, MenuItem};
use muda::{Menu as MudaMenu, MenuEvent, MenuEventReceiver, MenuItem};
#[cfg(any(target_os = "macos", target_os = "windows"))]
use raw_window_handle::HasWindowHandle;
use script_traits::TraversalDirection;
Expand Down Expand Up @@ -520,15 +520,20 @@ impl Window {

/// Check if the window has such webview.
pub fn has_webview(&self, id: WebViewId) -> bool {
#[cfg(linux)]
if self
.context_menu
.as_ref()
.map_or(false, |w| w.webview().webview_id == id)
{
return true;
}

self.panel
.as_ref()
.map_or(false, |w| w.webview.webview_id == id)
|| self.webview.as_ref().map_or(false, |w| w.webview_id == id)
|| self.has_dialog_webview(id)
|| self
.context_menu
.as_ref()
.map_or(false, |w| w.webview().webview_id == id)
}

/// Remove the webview in this window by provided webview ID. If this is the panel, it will
Expand All @@ -538,6 +543,17 @@ impl Window {
id: WebViewId,
compositor: &mut IOCompositor,
) -> (Option<WebView>, bool) {
#[cfg(linux)]
if self
.context_menu
.as_ref()
.filter(|menu| menu.webview().webview_id == id)
.is_some()
{
let context_menu = self.context_menu.take().expect("Context menu should exist");
return (Some(context_menu.webview().clone()), false);
}

if self
.panel
.as_ref()
Expand All @@ -561,14 +577,6 @@ impl Window {
} else if let Some(index) = self.dialog_webviews.iter().position(|w| w.webview_id == id) {
let webview = self.dialog_webviews.remove(index);
(Some(webview), false)
} else if self
.context_menu
.as_ref()
.filter(|menu| menu.webview().webview_id == id)
.is_some()
{
let context_menu = self.context_menu.take().expect("Context menu should exist");
(Some(context_menu.webview().clone()), false)
} else {
(None, false)
}
Expand All @@ -586,9 +594,11 @@ impl Window {

self.dialog_webviews.iter().for_each(|w| order.push(w));

#[cfg(linux)]
if let Some(context_menu) = &self.context_menu {
order.push(context_menu.webview());
}

order
}

Expand Down Expand Up @@ -657,7 +667,7 @@ impl Window {
);
let reload = MenuItem::with_id("reload", "Reload", true, None);

let menu = Menu::new();
let menu = MudaMenu::new();
let _ = menu.append_items(&[&back, &forward, &reload]);

let context_menu = ContextMenu::new_with_menu(Menu(menu));
Expand Down

0 comments on commit 7826826

Please sign in to comment.