mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-03 11:37:03 +00:00
changes
This commit is contained in:
1 parent
78fff9b6f4
commit
7cc36e3e40
37 files changed
+55361
-103
No files matched your search
+51
-10
@@ -2,8 +2,9 @@ mod epub;
|
||||
mod library;
|
||||
mod pdf;
|
||||
mod project;
|
||||
mod proofing;
|
||||
|
||||
use tauri::menu::{Menu, MenuItemBuilder, PredefinedMenuItem, SubmenuBuilder};
|
||||
use tauri::menu::{Menu, MenuItemBuilder, MenuItemKind, PredefinedMenuItem, SubmenuBuilder};
|
||||
use tauri::{Emitter, Runtime};
|
||||
|
||||
fn build_menu<R: Runtime>(handle: &tauri::AppHandle<R>) -> tauri::Result<Menu<R>> {
|
||||
@@ -13,13 +14,45 @@ fn build_menu<R: Runtime>(handle: &tauri::AppHandle<R>) -> tauri::Result<Menu<R>
|
||||
.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)?;
|
||||
let check_updates =
|
||||
MenuItemBuilder::with_id("check-updates", "Check for Updates…").build(handle)?;
|
||||
|
||||
let file_submenu = menu
|
||||
.items()?
|
||||
.into_iter()
|
||||
.find_map(|item| match item {
|
||||
MenuItemKind::Submenu(submenu)
|
||||
if submenu.text().map(|t| t == "File").unwrap_or(false) =>
|
||||
{
|
||||
Some(submenu)
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
|
||||
match file_submenu {
|
||||
Some(submenu) => {
|
||||
submenu.prepend_items(&[
|
||||
&new_book,
|
||||
&PredefinedMenuItem::separator(handle)?,
|
||||
&export_pdf,
|
||||
&export_epub,
|
||||
&PredefinedMenuItem::separator(handle)?,
|
||||
&check_updates,
|
||||
&PredefinedMenuItem::separator(handle)?,
|
||||
])?;
|
||||
}
|
||||
None => {
|
||||
let submenu = SubmenuBuilder::new(handle, "File")
|
||||
.item(&new_book)
|
||||
.item(&PredefinedMenuItem::separator(handle)?)
|
||||
.item(&export_pdf)
|
||||
.item(&export_epub)
|
||||
.item(&PredefinedMenuItem::separator(handle)?)
|
||||
.item(&check_updates)
|
||||
.build()?;
|
||||
menu.insert(&submenu, 1)?;
|
||||
}
|
||||
}
|
||||
Ok(menu)
|
||||
}
|
||||
|
||||
@@ -28,9 +61,15 @@ pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.manage(proofing::new_state())
|
||||
.menu(|handle| build_menu(handle))
|
||||
.on_menu_event(|app, event| {
|
||||
if matches!(event.id().0.as_str(), "new-book" | "export-pdf" | "export-epub") {
|
||||
if matches!(
|
||||
event.id().0.as_str(),
|
||||
"new-book" | "export-pdf" | "export-epub" | "check-updates"
|
||||
) {
|
||||
app.emit("menu-action", event.id().0.as_str()).ok();
|
||||
}
|
||||
})
|
||||
@@ -44,7 +83,9 @@ pub fn run() {
|
||||
library::list_books,
|
||||
library::load_book,
|
||||
library::save_book,
|
||||
library::delete_book
|
||||
library::delete_book,
|
||||
proofing::proof_text,
|
||||
proofing::remember_word
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running margin");
|
||||
|
||||
Reference in new issue
Block a user