feat(macos): trigger Apple Intelligence writing tools from the editor

This commit is contained in:
pj committed 2026-08-10 18:37:23 +05:30
1 parent fe39274ed7
commit 9e310a34bb
5 files changed
+108 -2

No files matched your search

+10 -1
View File
@@ -23,11 +23,16 @@ import { WIDTH_OPTIONS } from "../width";
import { bodyNumber, chapterKind, partNumber, partRoman } from "../model/book";
import { saveBook } from "../library";
import { useEscapeLayer } from "../escape";
import { isDesktop } from "../ipc";
import { isDesktop, runWritingTool } from "../ipc";
import { useCompact } from "../useMedia";
import { issueSignature, rememberWord, runProof } from "../proofing";
import { runExport } from "../export/run";
const WRITING_TOOLS: Record<string, "Proofread" | "Rewrite"> = {
KeyF: "Proofread",
KeyR: "Rewrite",
};
export function EditorView() {
const book = useBook((s) => s.book);
const activeChapterId = useBook((s) => s.activeChapterId);
@@ -172,6 +177,10 @@ export function EditorView() {
e.preventDefault();
e.stopPropagation();
switchChapter(e.shiftKey ? -1 : 1);
} else if (e.shiftKey && e.altKey && !e.metaKey && !e.ctrlKey && WRITING_TOOLS[e.code]) {
e.preventDefault();
e.stopPropagation();
runWritingTool(WRITING_TOOLS[e.code]).catch(() => {});
}
};
window.addEventListener("keydown", onKey, true);
+5
View File
@@ -2,6 +2,11 @@ import { invoke } from "@tauri-apps/api/core";
export const isDesktop = typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
export async function runWritingTool(tool: "Proofread" | "Rewrite"): Promise<void> {
if (!isDesktop) return;
await invoke("run_writing_tool", { tool });
}
export interface ImageInput {
path: string;
data: string;