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

+16
View File
@@ -0,0 +1,16 @@
/**
* Prefixes of the IPC channels the window may use. The preload forwards only these.
*
* Dependency-free: the preload runs sandboxed and cannot load packages.
*/
/** Prefixes of renderer → main invoke channels. */
export const IPC_CHANNEL_PREFIXES = [
/** The launcher itself: version, folders. */
'app:',
/** The launcher's own settings. */
'settings:',
] as const;
/** Prefix of main → renderer event channels. */
export const IPC_EVENT_PREFIX = 'event:';
+42
View File
@@ -0,0 +1,42 @@
import { z } from 'zod';
import { SettingsPatchSchema, SettingsSchema } from '../schemas/settings.ts';
/**
* The IPC contract: every renderer → main call and every main → renderer event, with the
* schemas of what goes in and what comes out. The main process validates both sides when it
* registers a handler; the window derives its types from here. No channel name is written as
* a bare string anywhere else.
*/
export const ipcContract = {
'app:getInfo': {
input: z.void(),
output: z.object({
version: z.string(),
electron: z.string(),
/** The operating system's preferred language, as Electron reports it (e.g. "zh-CN"). */
systemLocale: z.string(),
userDataPath: z.string(),
}),
},
'settings:get': {
input: z.void(),
output: SettingsSchema,
},
'settings:update': {
input: SettingsPatchSchema,
output: SettingsSchema,
},
} as const;
export const ipcEvents = {
'event:settings-changed': SettingsSchema,
} as const;
export type IpcChannel = keyof typeof ipcContract;
export type IpcInput<C extends IpcChannel> = z.input<(typeof ipcContract)[C]['input']>;
export type IpcOutput<C extends IpcChannel> = z.output<(typeof ipcContract)[C]['output']>;
export type IpcParsedInput<C extends IpcChannel> = z.output<(typeof ipcContract)[C]['input']>;
export type IpcEventChannel = keyof typeof ipcEvents;
export type IpcEventPayload<C extends IpcEventChannel> = z.output<(typeof ipcEvents)[C]>;