mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
feat(menu): handle native menu actions in the app
This commit is contained in:
1 parent
f4a4d63349
commit
1d600ccc33
1 file changed
+18
+18
@@ -1,11 +1,29 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { Library } from "./components/Library";
|
import { Library } from "./components/Library";
|
||||||
import { EditorView } from "./components/EditorView";
|
import { EditorView } from "./components/EditorView";
|
||||||
import { useBook } from "./store/useBook";
|
import { useBook } from "./store/useBook";
|
||||||
|
import { isDesktop } from "./ipc";
|
||||||
|
import { newBook } from "./library";
|
||||||
|
import { exportEpub, exportPdf } from "./export/exporters";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const book = useBook((s) => s.book);
|
const book = useBook((s) => s.book);
|
||||||
const openBook = useBook((s) => s.openBook);
|
const openBook = useBook((s) => s.openBook);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isDesktop) return;
|
||||||
|
const unlisten = listen<string>("menu-action", (event) => {
|
||||||
|
const state = useBook.getState();
|
||||||
|
if (event.payload === "new-book") state.openBook(newBook());
|
||||||
|
else if (event.payload === "export-pdf" && state.book) exportPdf(state.book);
|
||||||
|
else if (event.payload === "export-epub" && state.book) exportEpub(state.book);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
unlisten.then((stop) => stop());
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return book ? <EditorView /> : <Library onOpen={openBook} />;
|
return book ? <EditorView /> : <Library onOpen={openBook} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user