import type { MainLogger } from './logger.js'; import type { SidecarSupervisor } from './sidecar.js'; import type { CrashDiagnosticsApi } from './crash-reports.js'; export { createMainLogger, type DiagnosticReportOptions, type MainLogFields, type MainLogger, type MainLoggerOptions, } from './logger.js'; export { type CrashDiagnosticsApi, type CrashReport, type CrashReportDomain, type CrashReportSummary, } from './crash-reports.js'; export { createSidecarSupervisor, type SidecarEvent, type SidecarHandle, type SidecarRestartPolicy, type SidecarSpawnOptions, type SidecarSupervisor, type SidecarSupervisorOptions, type SidecarWorkingDirectory, } from './sidecar.js'; /** Runtime information passed to the application's long-lived Node main process. */ export interface MainContext { appId: string; productName: string; version: string; isPackaged: boolean; platform: NodeJS.Platform; arch: string; projectRoot: string; resourcesPath: string; /** * Primary cold-start launch arguments and working directory, captured by the * native launcher when the application process started. * * In packaged builds `argv` is the bounded argument list passed to the app * executable (everything after `argv[0]`) and `cwd` is the * launcher's working directory — use it for arbitrary flags such as * `--no-sample-data`. Registered deep-link URLs and file paths are ALSO * delivered, normalized and validated, through `openRequested`; this field * is the raw list and must be treated as untrusted input. * * In development `argv` is empty for a plain `murasaki dev`; running * `murasaki dev -- ` forwards the bounded arguments after the * standalone `--` delimiter (dev's own CLI flags before it never leak), and * `cwd` is the project root. Both modes retain at most 64 intact arguments, * 8 KiB per argument and 16 KiB for the encoded argv array. */ launch: { argv: string[]; cwd: string; }; paths: { data: string; cache: string; logs: string; temp: string; }; /** Structured rotating log plus an opt-in diagnostic report generator. */ log: MainLogger; /** Local crash report capture (Node, native, and prod renderer domains). Murasaki never transmits these. */ diagnostics: CrashDiagnosticsApi; /** Supervises executable resources without a shell and stops them with the app. */ sidecars: SidecarSupervisor; /** Aborted after `beforeQuit`, or when the total quit-hook deadline expires. */ signal: AbortSignal; } export type QuitReason = 'window-close' | 'app-quit' | 'signal' | 'restart' | 'dev-reload' | 'startup-failure'; export interface QuitContext extends MainContext { reason: QuitReason; } export interface SecondInstanceEvent { /** Arguments passed to the second launcher, including deep-link URLs/files. */ argv: string[]; cwd: string; } export type OpenTarget = { kind: 'url'; url: string; scheme: string; } | { kind: 'file'; path: string; }; export interface OpenRequestEvent { /** How this activation reached the primary application instance. */ activation: 'cold-start' | 'second-instance' | 'os-event'; /** Native delivery mechanism, useful for diagnostics. */ transport: 'argv' | 'open-url' | 'open-file'; /** Normalized registered URLs/files. Treat every value as untrusted input. */ targets: OpenTarget[]; /** Working directory for argv-based activations. */ cwd?: string; } export interface MainDefinition { /** Runs once after the Node main process is ready, before the renderer is shown. */ ready?(context: MainContext): void | Promise; /** Runs in the primary instance when another launch is redirected to it. */ secondInstance?(context: MainContext, event: SecondInstanceEvent): void | Promise; /** Receives registered URL schemes and files after `ready()` has completed. */ openRequested?(context: MainContext, event: OpenRequestEvent): void | Promise; /** Return `false` to cancel a normal quit request. Ignored for forced shutdown. */ beforeQuit?(context: QuitContext): boolean | void | Promise; /** Flush databases, sockets, workers, and other owned resources. */ shutdown?(context: QuitContext): void | Promise; } export interface MainEvent { channel: string; value: T; } /** Serializable state for a window declared in `murasaki.config.*`. */ export interface MainWindowState { label: string; /** Monotonic native instance generation for this label. */ generation: number; primary: boolean; visible: boolean; focused: boolean; minimized: boolean; maximized: boolean; } export type MainWindowLifecycleType = 'created' | 'shown' | 'hidden' | 'focused' | 'blurred' | 'closed'; /** Native window lifecycle notification delivered to the Node Main process. */ export interface MainWindowLifecycleEvent { type: MainWindowLifecycleType; label: string; /** Generation of the native window instance that emitted this event. */ generation: number; primary: boolean; /** `null` after the native window has been destroyed. */ state: MainWindowState | null; } /** * Imperative control for windows declared in `murasaki.config.*`. * * The transport is native-host-only and authenticated with the per-launch * runtime token; renderer pages cannot call this API or forge lifecycle events. */ export declare const windows: { list(): Promise; get(label: string): Promise; /** Creates a configured, currently dormant secondary window. */ create(label: string): Promise; show(label: string): Promise; hide(label: string): Promise; focus(label: string): Promise; /** Destroys a live secondary window. The primary window cannot be destroyed. */ destroy(label: string): Promise; subscribe(listener: (event: MainWindowLifecycleEvent) => void): () => void; }; type MainEventListener = (event: MainEvent) => void; /** Publishes a typed application event from Node Main to subscribed renderers. */ export declare function emitMainEvent(channel: string, value: T): void; /** @internal Framework transport subscription; applications should emit only. */ export declare function subscribeMainEvents(listener: MainEventListener): () => void; /** * Declares the application's long-lived Node main process lifecycle. * * @example * ```ts * // src/main.ts * import { defineMain } from 'murasaki/main' * * export default defineMain({ * async ready({ paths, signal }) { * // Open databases, start WebSocket/TCP servers, workers, etc. * }, * async shutdown() { * // Flush and close owned resources. * }, * }) * ``` */ export declare function defineMain(definition: MainDefinition): MainDefinition; //# sourceMappingURL=index.d.ts.map