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