diff --git a/src/App.tsx b/src/App.tsx index fff6df6..f765f64 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,29 @@ +import { useEffect } from "react"; +import { listen } from "@tauri-apps/api/event"; import { Library } from "./components/Library"; import { EditorView } from "./components/EditorView"; import { useBook } from "./store/useBook"; +import { isDesktop } from "./ipc"; +import { newBook } from "./library"; +import { exportEpub, exportPdf } from "./export/exporters"; function App() { const book = useBook((s) => s.book); const openBook = useBook((s) => s.openBook); + useEffect(() => { + if (!isDesktop) return; + const unlisten = listen("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 ? : ; }