mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 11:07:04 +00:00
feat(menu): native File menu with New Book and Export
This commit is contained in:
1 parent
f44e38d7fe
commit
f4a4d63349
1 file changed
+26
@@ -3,11 +3,37 @@ mod library;
|
|||||||
mod pdf;
|
mod pdf;
|
||||||
mod project;
|
mod project;
|
||||||
|
|
||||||
|
use tauri::menu::{Menu, MenuItemBuilder, PredefinedMenuItem, SubmenuBuilder};
|
||||||
|
use tauri::{Emitter, Runtime};
|
||||||
|
|
||||||
|
fn build_menu<R: Runtime>(handle: &tauri::AppHandle<R>) -> tauri::Result<Menu<R>> {
|
||||||
|
let menu = Menu::default(handle)?;
|
||||||
|
let new_book = MenuItemBuilder::with_id("new-book", "New Book")
|
||||||
|
.accelerator("CmdOrCtrl+N")
|
||||||
|
.build(handle)?;
|
||||||
|
let export_pdf = MenuItemBuilder::with_id("export-pdf", "Export as PDF…").build(handle)?;
|
||||||
|
let export_epub = MenuItemBuilder::with_id("export-epub", "Export as EPUB…").build(handle)?;
|
||||||
|
let file_submenu = SubmenuBuilder::new(handle, "File")
|
||||||
|
.item(&new_book)
|
||||||
|
.item(&PredefinedMenuItem::separator(handle)?)
|
||||||
|
.item(&export_pdf)
|
||||||
|
.item(&export_epub)
|
||||||
|
.build()?;
|
||||||
|
menu.insert(&file_submenu, 1)?;
|
||||||
|
Ok(menu)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
|
.menu(|handle| build_menu(handle))
|
||||||
|
.on_menu_event(|app, event| {
|
||||||
|
if matches!(event.id().0.as_str(), "new-book" | "export-pdf" | "export-epub") {
|
||||||
|
app.emit("menu-action", event.id().0.as_str()).ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
epub::package_epub,
|
epub::package_epub,
|
||||||
pdf::compile_pdf,
|
pdf::compile_pdf,
|
||||||
|
|||||||
Reference in new issue
Block a user