diff --git a/README.md b/README.md index abdd5ea..30b47b3 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ Package this feature once with `pnpm tauri build --bundles app`, then open `src-tauri/target/release/bundle/macos/Leaflet.app` or copy it into Applications. An older installed version must be replaced once to gain the rebuild control. -Click **Rebuild app** at the bottom of the sidebar, or use **Cmd+K → Rebuild app**. +Use **Leaflet → Rebuild app…**, the hammer icon at the bottom of the sidebar, +or **Cmd+K → Rebuild app**. Choose the Leaflet workspace with the native folder picker, then click **Rebuild & restart**. The folder is remembered by the native app. Rebuilds only use this selection; a webview cannot submit a different build path. The build uses the current diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 365c2d4..76cec29 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -3,7 +3,9 @@ mod watch; use serde::Serialize; use std::{fs, path::PathBuf}; -use tauri::Manager; +#[cfg(target_os = "macos")] +use tauri::menu::{Menu, MenuItem, PredefinedMenuItem}; +use tauri::{Emitter, Manager}; #[derive(Serialize)] struct Entry { @@ -115,6 +117,46 @@ pub fn run() { .manage(rebuild::RebuildState::default()) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_opener::init()) + .setup(|app| { + #[cfg(target_os = "macos")] + { + let menu = Menu::default(app.handle())?; + let mut added_rebuild_item = false; + for item in menu.items()? { + if let Some(submenu) = item.as_submenu() { + if submenu.text()? == app.package_info().name { + let rebuild = MenuItem::with_id( + app, + "rebuild", + "Rebuild app…", + true, + None::<&str>, + )?; + // The default Leaflet menu starts with About and a separator. + submenu.insert_items( + &[&rebuild, &PredefinedMenuItem::separator(app)?], + 2, + )?; + added_rebuild_item = true; + break; + } + } + } + if !added_rebuild_item { + eprintln!("Could not add Rebuild app to the Leaflet menu: submenu not found"); + } + app.set_menu(menu)?; + } + Ok(()) + }) + .on_menu_event(|app, event| { + if event.id().as_ref() == "rebuild" { + if let Some(window) = app.get_webview_window("main") { + let _ = window.set_focus(); + let _ = window.emit("open-rebuild", ()); + } + } + }) .invoke_handler(tauri::generate_handler![ load_archive, watch::watch_archive, diff --git a/src/App.tsx b/src/App.tsx index 92449b1..44c80fe 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,6 +23,7 @@ import { X, } from 'lucide-react'; import { getCurrentWindow } from '@tauri-apps/api/window'; +import { listen } from '@tauri-apps/api/event'; import { chooseArchive, desktop, @@ -149,6 +150,13 @@ export default function App() { useEffect(() => { void load(readPreference('root', '')); }, [load]); + useEffect(() => { + if (!desktop) return; + const unlisten = listen('open-rebuild', () => setRebuildOpen(true)); + return () => { + void unlisten.then((stop) => stop()); + }; + }, []); useEffect(() => { if (!desktop || !rootKey || busy) return; setSyncError(null); @@ -433,12 +441,6 @@ export default function App() { })}
- {desktop && ( - - )} + )}