mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
Typst compile warnings were discarded. Capture them via the Warned result and emit a pdf-warnings event (only from the export path, not the live preview) that App shows as a non-fatal toast; the export still succeeds. Also scan book text before reporting success and warn when it contains scripts the embedded Latin fonts cannot render (CJK, Arabic, Hebrew, Devanagari, Thai, emoji). Claude-Session: https://claude.ai/code/session_01RzTWrLiy4zGuw2hZSQGamk
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { useEffect } from "react";
|
|
import { listen } from "@tauri-apps/api/event";
|
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
|
import { Library } from "./components/Library";
|
|
import { EditorView } from "./components/EditorView";
|
|
import { useBook } from "./store/useBook";
|
|
import { isDesktop } from "./ipc";
|
|
import { createAndOpenBook, saveBook } from "./library";
|
|
import { runExport } from "./export/run";
|
|
import { checkForUpdates } from "./updater";
|
|
|
|
function App() {
|
|
const book = useBook((s) => s.book);
|
|
const openBook = useBook((s) => s.openBook);
|
|
|
|
useEffect(() => {
|
|
if (!isDesktop) return;
|
|
checkForUpdates(true);
|
|
const unlisten = listen<string>("menu-action", (event) => {
|
|
const state = useBook.getState();
|
|
if (event.payload === "new-book") createAndOpenBook(state.openBook, state.setNotice);
|
|
else if (event.payload === "export-pdf") runExport("pdf");
|
|
else if (event.payload === "export-epub") runExport("epub");
|
|
else if (event.payload === "check-updates") checkForUpdates(false);
|
|
});
|
|
const unlistenWarn = listen<string>("pdf-warnings", (event) => {
|
|
useBook.getState().setNotice(`PDF exported with warnings:\n${event.payload}`);
|
|
});
|
|
return () => {
|
|
unlisten.then((stop) => stop());
|
|
unlistenWarn.then((stop) => stop());
|
|
};
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!isDesktop) return;
|
|
const win = getCurrentWindow();
|
|
const unlisten = win.onCloseRequested(async (event) => {
|
|
const { book, dirty } = useBook.getState();
|
|
if (!book || !dirty) return;
|
|
event.preventDefault();
|
|
await saveBook(book).catch(() => {});
|
|
win.destroy();
|
|
});
|
|
return () => {
|
|
unlisten.then((stop) => stop());
|
|
};
|
|
}, []);
|
|
|
|
return book ? <EditorView /> : <Library onOpen={openBook} />;
|
|
}
|
|
|
|
export default App;
|