mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
feat(ui): guard desktop-only actions with a clear browser-preview message
This commit is contained in:
1 parent
f8ddde5e91
commit
5e1582fc39
3 files changed
+20
-4
No files matched your search
+16
@@ -10,6 +10,10 @@ import { useBook } from "./store/useBook";
|
||||
import type { Book } from "./model/book";
|
||||
import { chooseSavePath, openBook, writeBook } from "./project";
|
||||
import { exportEpub, exportPdf } from "./export/exporters";
|
||||
import { isDesktop } from "./ipc";
|
||||
|
||||
const DESKTOP_ONLY =
|
||||
'This runs in the desktop app only — open the window from "pnpm tauri dev" (you are viewing the browser preview).';
|
||||
|
||||
function App() {
|
||||
const [dock, setDock] = useState(true);
|
||||
@@ -31,6 +35,10 @@ function App() {
|
||||
const chapter = chapters[idx];
|
||||
|
||||
const handleSave = useCallback(async () => {
|
||||
if (!isDesktop) {
|
||||
setNotice(DESKTOP_ONLY);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { book, path } = useBook.getState();
|
||||
const target = path ?? (await chooseSavePath(book));
|
||||
@@ -44,6 +52,10 @@ function App() {
|
||||
}, [markSaved]);
|
||||
|
||||
const handleOpen = useCallback(async () => {
|
||||
if (!isDesktop) {
|
||||
setNotice(DESKTOP_ONLY);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await openBook();
|
||||
if (result) replaceBook(result.book, result.path);
|
||||
@@ -54,6 +66,10 @@ function App() {
|
||||
|
||||
const runExport = async (label: string, fn: (book: Book) => Promise<void>) => {
|
||||
setExportOpen(false);
|
||||
if (!isDesktop) {
|
||||
setNotice(DESKTOP_ONLY);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await fn(useBook.getState().book);
|
||||
} catch (e) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { generateHTML } from "@tiptap/core";
|
||||
import { useBook } from "../store/useBook";
|
||||
import { editorExtensions } from "../editor/extensions";
|
||||
import { bookToPdfInputs } from "../export/typst";
|
||||
import { compilePdf } from "../ipc";
|
||||
import { compilePdf, isDesktop } from "../ipc";
|
||||
import { PdfPreview } from "./PdfPreview";
|
||||
|
||||
const TRIM_LABEL: Record<string, string> = {
|
||||
@@ -13,10 +13,8 @@ const TRIM_LABEL: Record<string, string> = {
|
||||
a5: "A5",
|
||||
};
|
||||
|
||||
const inTauri = typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
|
||||
|
||||
export function Dock() {
|
||||
return inTauri ? <PdfDock /> : <HtmlDock />;
|
||||
return isDesktop ? <PdfDock /> : <HtmlDock />;
|
||||
}
|
||||
|
||||
function PdfDock() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
export const isDesktop = typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
|
||||
|
||||
export interface ImageInput {
|
||||
path: string;
|
||||
data: string;
|
||||
|
||||
Reference in new issue
Block a user