NarraLeaf
NarraLeaf DesktopMain

Main

Electron 主进程运行时、配置、窗口、用户事件、hooks 与存储

Main 模块是 NarraLeaf 的 Electron 主进程接口。它负责创建应用宿主、启动主窗口、连接渲染器事件桥、管理应用数据路径,并暴露存档与 JSON 存储 helpers

import { AppConfig } from "narraleaf";

const app = new AppConfig().create();

app.onReady(() => {
    void app.launchApp();
});

入口

同一套稳定接口可以从 narraleafnarraleaf/main 导入

import {
    App,
    AppConfig,
    AppWindow,
    assertSafeStorageKey,
} from "narraleaf";

指南

面向用户的导出

  • App:Electron 应用宿主
  • AppConfig:用于创建 App 的链式配置 builder
  • AppWindowapp.launchApp() 返回的 BrowserWindow 包装器
  • StoreProvider:自定义存档后端类型
  • assertSafeStorageKeyMAX_STORAGE_KEY_LENGTH:用于校验存档 id 和 JSON store name 的 helpers

Main Events

应用级 renderer-to-main 调用应在主进程通过 AppWindow.handleUserEvent() 注册 handler,再在渲染器使用 requestMain()invokeMainEvent() 调用

底层契约类型

包中也导出了 IPCEventTypeNamespaceIPCEventsRequestStatus 等底层 IPC 契约类型。它们描述 NarraLeaf 内置 preload bridge 和默认 handlers。大多数应用功能不需要直接导入这些类型

本页目录