fix devtools on release builds

This commit is contained in:
Josh Junon 2024-04-16 16:43:22 +02:00
parent ed7fd43874
commit fa06586cdf
No known key found for this signature in database
2 changed files with 24 additions and 16 deletions

View File

@ -115,6 +115,7 @@ jobs:
- check-tests - check-tests
features: features:
- '' - ''
- [devtools]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: ./.github/actions/check-crate - uses: ./.github/actions/check-crate

View File

@ -31,26 +31,30 @@ pub async fn menu_item_set_enabled(
} }
pub fn build(package_info: &PackageInfo) -> Menu { pub fn build(package_info: &PackageInfo) -> Menu {
#[allow(unused_mut)]
let mut menu = Menu::os_default(&package_info.name).add_submenu(Submenu::new( let mut menu = Menu::os_default(&package_info.name).add_submenu(Submenu::new(
"Project", "Project",
Menu::with_items([disabled_menu_item("project/settings", "Project Settings")]), Menu::with_items([disabled_menu_item("project/settings", "Project Settings")]),
)); ));
// Try to find the View menu and attach the dev tools item #[cfg(any(debug_assertions, feature = "devtools"))]
let view_menu = menu.items.iter_mut().find(|item| match item { {
MenuEntry::CustomItem(_) => false, // Try to find the View menu and attach the dev tools item
MenuEntry::Submenu(submenu) => submenu.title == "View", let view_menu = menu.items.iter_mut().find(|item| match item {
MenuEntry::NativeItem(_) => false, MenuEntry::CustomItem(_) => false,
}); MenuEntry::Submenu(submenu) => submenu.title == "View",
MenuEntry::NativeItem(_) => false,
});
let devtools = CustomMenuItem::new("view/devtools", "Developer Tools"); let devtools = CustomMenuItem::new("view/devtools", "Developer Tools");
if let Some(MenuEntry::Submenu(view_menu)) = view_menu { if let Some(MenuEntry::Submenu(view_menu)) = view_menu {
view_menu.inner.items.push(devtools.into()); view_menu.inner.items.push(devtools.into());
} else { } else {
menu = menu.add_submenu(Submenu::new( menu = menu.add_submenu(Submenu::new(
"Developer", "Developer",
Menu::with_items([devtools.into()]), Menu::with_items([devtools.into()]),
)); ));
}
} }
menu menu
@ -63,8 +67,11 @@ fn disabled_menu_item(id: &str, title: &str) -> MenuEntry {
} }
pub fn handle_event<R: Runtime>(event: &WindowMenuEvent<R>) { pub fn handle_event<R: Runtime>(event: &WindowMenuEvent<R>) {
if event.menu_item_id() == "view/devtools" { #[cfg(any(debug_assertions, feature = "devtools"))]
event.window().open_devtools(); {
if event.menu_item_id() == "view/devtools" {
event.window().open_devtools();
}
} }
emit( emit(
event.window(), event.window(),