Skip to content

Commit

Permalink
fix: explicitly add the application name as a menu (#30)
Browse files Browse the repository at this point in the history
* fix: explicitly add the application name as a menu

* feat: add other application items
fix: constrain menu to macos only

* fix: remove quit on macos and switch to native quit
  • Loading branch information
ChachyDev authored Oct 29, 2023
1 parent df1084e commit 9013db7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
42 changes: 32 additions & 10 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::project::ProjectManager;
use env_logger::Env;
use log::info;
use std::sync::Arc;
use tauri::{CustomMenuItem, Menu, Submenu, Wry};
use tauri::{AboutMetadata, CustomMenuItem, Menu, MenuItem, Submenu, Wry};

#[tokio::main]
async fn main() {
Expand Down Expand Up @@ -46,24 +46,46 @@ async fn main() {
}

fn build_menu() -> Menu {
let application_menu = Submenu::new(
"typstudio",
Menu::new()
.add_native_item(MenuItem::About(String::from("typstudio"), AboutMetadata::new()))
.add_native_item(MenuItem::Separator)
.add_native_item(MenuItem::Hide)
.add_native_item(MenuItem::HideOthers)
.add_native_item(MenuItem::ShowAll)
.add_native_item(MenuItem::Separator)
.add_native_item(MenuItem::Quit),
);

let mut file_menu = Menu::new()
.add_item(CustomMenuItem::new("file_open_project", "Open Project"))
.add_submenu(Submenu::new(
"Export",
Menu::new().add_item(CustomMenuItem::new("file_export_pdf", "Export PDF")),
));

#[cfg(not(target_os = "macos"))]
{
file_menu = file_menu.add_native_item(MenuItem::Quit);
}

let file_submenu = Submenu::new(
"File",
Menu::new()
.add_item(CustomMenuItem::new("file_open_project", "Open Project"))
.add_submenu(Submenu::new(
"Export",
Menu::new().add_item(CustomMenuItem::new("file_export_pdf", "Export PDF")),
))
.add_item(CustomMenuItem::new("file_quit", "Quit")),
file_menu,
);
let edit_submenu = Submenu::new("Edit", Menu::new());
let view_submenu = Submenu::new(
"View",
Menu::new().add_item(CustomMenuItem::new("view_toggle_preview", "Toggle Preview")),
);

Menu::new()
.add_submenu(file_submenu)
let mut menu = Menu::new();
#[cfg(target_os = "macos")]
{
menu = menu.add_submenu(application_menu)
}
menu.add_submenu(file_submenu)
.add_submenu(edit_submenu)
.add_submenu(view_submenu)
}
3 changes: 0 additions & 3 deletions src-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ pub fn handle_menu_event<R: Runtime>(e: WindowMenuEvent<R>) {
}
}
}),
"file_quit" => {
e.window().app_handle().exit(0);
}
"view_toggle_preview" => {
view::toggle_preview_visibility(e.window());
}
Expand Down

0 comments on commit 9013db7

Please sign in to comment.