Skip to content

Commit

Permalink
Finally fix the mac menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Marekkon5 committed Nov 22, 2023
1 parent be6805c commit af45e8e
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions crates/onetagger/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,51 +42,41 @@ pub fn start_webview() -> Result<(), Error> {
window.set_inner_size(Size::Physical(PhysicalSize::new(1280, 720)));
let mut context = WebContext::new(Some(Settings::get_folder()?.join("webview")));
let p = proxy.clone();
let mut webview = WebViewBuilder::new(window)?
.with_url("http://127.0.0.1:36913")?
.with_devtools(Settings::load().map(|s| s.devtools()).unwrap_or(false))
.with_ipc_handler(move |_window, message| {
let proxy = &p;
if message == "devtools" {
proxy.send_event(CustomWindowEvent::DevTools).ok();
}
})
.with_web_context(&mut context);


// Register menu for MacOS shortcuts to work
#[cfg(target_os = "macos")]
{
let _menu = {
use muda::{Menu, Submenu, PredefinedMenuItem};
let menu = Menu::new();

let app_submenu = Submenu::new("App", true);
menu.append(&app_submenu).ok();

app_submenu.append_items(&[
&PredefinedMenuItem::about(None, None),
&PredefinedMenuItem::separator(),
&PredefinedMenuItem::hide(None),
&PredefinedMenuItem::hide_others(None),
&PredefinedMenuItem::show_all(None),
&PredefinedMenuItem::separator(),
&PredefinedMenuItem::quit(None),
]).ok();

let edit_submenu = Submenu::new("&Edit", true);
edit_submenu.append_items(&[
let submenu = Submenu::new("Edit", true);
submenu.append_items(&[
&PredefinedMenuItem::undo(None),
&PredefinedMenuItem::redo(None),
&PredefinedMenuItem::separator(),
&PredefinedMenuItem::cut(None),
&PredefinedMenuItem::copy(None),
&PredefinedMenuItem::paste(None),
&PredefinedMenuItem::select_all(None),
]).ok();
])?;

menu.append(&edit_submenu).ok();
menu.append(&submenu)?;
menu.init_for_nsapp();
}
debug!("Added menu");

menu
};

let mut webview = WebViewBuilder::new(window)?
.with_url("http://127.0.0.1:36913")?
.with_devtools(Settings::load().map(|s| s.devtools()).unwrap_or(false))
.with_ipc_handler(move |_window, message| {
let proxy = &p;
if message == "devtools" {
proxy.send_event(CustomWindowEvent::DevTools).ok();
}
})
.with_web_context(&mut context);

// Windows webview2 does NOT support custom DnD, janky workaround
if cfg!(target_os = "windows") {
Expand Down

0 comments on commit af45e8e

Please sign in to comment.