feat(launcher): add the launcher application skeleton

The installer and launcher is an Electron app in apps/launcher: main
process, a sandboxed preload that only forwards allowed channels, and a
React window translated into Chinese and English.

Every renderer -> main call is declared once in the IPC contract
(shared/ipc/contract.ts) with zod schemas for its input and output; the
main side validates both when it registers a handler. The main process
throws error codes only, and the window translates them. The launcher's
own settings (for now the window language) are kept in the user data
folder and written through a temporary file and a rename. Development
runs can point the user data folder elsewhere with
WTO_LAUNCHER_USER_DATA.

The workspace packages (@wto/patcher, @wto/server) stay external to the
bundle: they ship as TypeScript sources and will run in utility
processes, where Electron's Node strips the types and they find their
web pages, tuning and keys next to their sources as they do today.

The root typecheck leaves out the launcher, which has its own tsconfig
files for the main process and the window.

Checked with the launcher typecheck, electron-vite build, the root
typecheck, and a start on a scratch user data folder.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 03:22:38 +08:00
1 parent 930ea07630
commit 70d59d7bf7
30 files changed
+3484 -1

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
/**
* Error codes shared by the main process and the window.
*
* The main process never produces text meant for the player. It throws an AppError carrying a
* code and optional parameters; the code crosses IPC inside Error.message (Electron passes only
* the message of a rejected invoke), and the window shows the translation of `errors.<code>`.
* The underlying exception goes to the main process log.
*
* Dependency-free so the sandboxed preload could import it.
*/
export const APP_ERROR_CODES = [
/** A bug of ours: a handler returned something its contract does not allow. */
'internal_error',
/** The launcher's own settings file could not be written. */
'settings_write_failed',
] as const;
export type AppErrorCode = (typeof APP_ERROR_CODES)[number];
export type AppErrorParams = Readonly<Record<string, string | number>>;
const MARKER = 'wto-app-error:';
export class AppError extends Error {
readonly code: AppErrorCode;
readonly params: AppErrorParams;
constructor(code: AppErrorCode, params: AppErrorParams = {}) {
super(MARKER + JSON.stringify({ code, params }));
this.name = 'AppError';
this.code = code;
this.params = params;
}
}
/** The code and parameters an AppError put into a message, or null for any other error. */
export function parseAppError(message: string): { code: AppErrorCode; params: AppErrorParams } | null {
const start = message.indexOf(MARKER);
if (start === -1) return null;
try {
const value = JSON.parse(message.slice(start + MARKER.length)) as { code?: unknown; params?: unknown };
if (!(APP_ERROR_CODES as readonly unknown[]).includes(value.code)) return null;
const params = value.params && typeof value.params === 'object' ? (value.params as AppErrorParams) : {};
return { code: value.code as AppErrorCode, params };
} catch {
return null;
}
}