Files
WT-Offline/apps/launcher/src/shared/ipc/contract.ts
T
N0VAN0M4LY 81c900a61d feat(launcher): redesign the main launcher window
The window is now a fixed 1120x720 frameless window with its own title
bar: page navigation, language, minimize and close. The layout follows
the game's launcher: a side panel, the main area over the background,
and a bottom bar with the state of the current task and the primary
action. The colours and type follow the game's website: dark blue-grey,
red actions, Roboto Condensed (bundled, OFL), cyan progress.

- Pages: home (requirements before installation, the current copy
  after), copies (copy details with folders to open, feature status
  grouped by inventory section), settings (language), about.
- The install wizard is a hook shared by the side panel (step list),
  the main area (current step) and the bottom bar (back, next, install,
  cancel, copy progress).
- The adaptation shown for a game version is the version itself when
  the patches were verified on it, otherwise the nearest verified one.
- Both language packs are rewritten in consistent product wording.
- New IPC: app:openFolder, install:listFeatures (patcher's new
  patchFeatures), window:minimize, window:close; app:getInfo reports the
  supported game versions.

Launching is not built yet; its button stays disabled.

Checked: launcher typecheck (main and renderer), electron-vite build,
root typecheck. Ran the window from a scratch user data folder over the
remote debugging port: every page and section in Chinese and English,
empty and installed state, the wizard's first step, both new IPC calls,
no console errors and no overflow.
2026-11-29 07:39:12 +08:00

111 lines
3.7 KiB
TypeScript

import { z } from 'zod';
import {
FolderSizeSchema,
GameFolderInspectionSchema,
InstallProgressSchema,
InstallRecordSchema,
InstallRequestSchema,
PatchCheckSchema,
PatchFeatureSchema,
TargetFolderInspectionSchema,
} from '../schemas/install.ts';
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(),
/** The game versions every patch was verified on. */
supportedGameVersions: z.array(z.string()),
}),
},
'app:openFolder': {
/** Opens a folder in the file manager; refused unless it exists. */
input: z.object({ path: z.string().min(1) }),
output: z.void(),
},
'dialog:pickFolder': {
/** The dialog title, already translated by the window. */
input: z.object({ title: z.string().optional() }),
/** The chosen folder, or null when the player cancelled. */
output: z.object({ path: z.string().nullable() }),
},
'install:inspectGameFolder': {
input: z.object({ path: z.string().min(1) }),
output: GameFolderInspectionSchema,
},
'install:inspectTargetFolder': {
input: z.object({ path: z.string().min(1), stockPath: z.string().min(1) }),
output: TargetFolderInspectionSchema,
},
'install:measureFolder': {
input: z.object({ path: z.string().min(1) }),
output: FolderSizeSchema,
},
'install:checkPatches': {
/** The game folder to install from, and the data folder whose store tuning the build uses. */
input: z.object({ gamePath: z.string().min(1), dataPath: z.string().min(1) }),
output: PatchCheckSchema,
},
'install:start': {
/** Runs until the installation is done; progress arrives as event:install-progress. */
input: InstallRequestSchema,
output: InstallRecordSchema,
},
'install:cancel': {
input: z.void(),
/** Whether an installation was running. */
output: z.object({ cancelled: z.boolean() }),
},
'install:getRecord': {
input: z.void(),
output: z.object({ record: InstallRecordSchema.nullable(), defaultDataPath: z.string() }),
},
'install:listFeatures': {
/** Every feature the patches cover; which of them a copy lacks is in its install record. */
input: z.void(),
output: z.array(PatchFeatureSchema),
},
'settings:get': {
input: z.void(),
output: SettingsSchema,
},
'settings:update': {
input: SettingsPatchSchema,
output: SettingsSchema,
},
'window:minimize': {
input: z.void(),
output: z.void(),
},
'window:close': {
input: z.void(),
output: z.void(),
},
} as const;
export const ipcEvents = {
'event:settings-changed': SettingsSchema,
'event:install-progress': InstallProgressSchema,
} 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]>;