Skip to content

Build your personal knowledge base with Trilium Notes

feat(build-docs): produce documentation for Electron API

Elian Doran68a41771b57b
diff --git a/apps/build-docs/src/electron_api_entrypoint.ts b/apps/build-docs/src/electron_api_entrypoint.ts
new file mode 100644
index 0000000000..4665737515
--- /dev/null
+++ b/apps/build-docs/src/electron_api_entrypoint.ts
@@ -0,0 +1,33 @@
+/**
+ * The Electron API is the bridge between the renderer process and Electron's
+ * main process, exposed at runtime as the global `window.electronApi`.
+ *
+ * Unlike the Frontend and Backend Script APIs, this is **not** part of the
+ * `api` global available inside script notes. Instead, frontend script notes
+ * running in the Electron desktop app can reach it via `window.electronApi`
+ * directly. The API is only present in desktop builds — frontend scripts that
+ * use it will not work in the browser/server build or in the standalone
+ * (WASM) build.
+ *
+ * The runtime value is wired up by the preload script in
+ * `apps/desktop/src/preload.ts` via `contextBridge.exposeInMainWorld`. The
+ * interface below is the contract both the preload script
+ * (`satisfies ElectronApi`) and the client (`window.electronApi`) share.
+ *
+ * Entry point: {@link ElectronApi}
+ *
+ * @module Electron API
+ */
+
+export type {
+ ElectronApi,
+ ElectronClipboardApi,
+ ElectronContextMenuApi,
+ ElectronContextMenuParams,
+ ElectronNavigationApi,
+ ElectronPrintingApi,
+ ElectronShellApi,
+ ElectronSpellcheckApi,
+ ElectronTrayApi,
+ ElectronWindowApi
+} from "../../../packages/commons/src/lib/electron_api_interface.js";
diff --git a/apps/build-docs/src/script-api.ts b/apps/build-docs/src/script-api.ts
index 2c62477474..2f0759c0bd 100644
--- a/apps/build-docs/src/script-api.ts
+++ b/apps/build-docs/src/script-api.ts
@@ -7,7 +7,7 @@ export default function buildScriptApi({ baseDir, gitRootDir }: BuildContext) {
// Generate types
execSync(`pnpm typecheck`, { stdio: "inherit", cwd: gitRootDir });
- for (const config of [ "backend", "frontend" ]) {
+ for (const config of [ "backend", "frontend", "electron" ]) {
const outDir = join(baseDir, "script-api", config);
execSync(`pnpm typedoc --options typedoc.${config}.json --html "${outDir}"`, {
stdio: "inherit"
diff --git a/apps/build-docs/typedoc.electron.json b/apps/build-docs/typedoc.electron.json
new file mode 100644
index 0000000000..4f87d0081b
--- /dev/null
+++ b/apps/build-docs/typedoc.electron.json
@@ -0,0 +1,11 @@
+{
+ "$schema": "https://typedoc.org/schema.json",
+ "name": "Trilium Electron API",
+ "entryPoints": [
+ "src/electron_api_entrypoint.ts"
+ ],
+ "tsconfig": "tsconfig.app.json",
+ "plugin": [
+ "typedoc-plugin-missing-exports"
+ ]
+}