feat(launcher): launch the game through the guarded lab

This commit is contained in:
N0VAN0M4LY committed 2026-11-29 15:02:39 +08:00
1 parent d633280e23
commit e41b73aaa3
25 files changed
+920 -23

No files matched your search

+12
View File
@@ -16,6 +16,18 @@ export const APP_ERROR_CODES = [
'settings_write_failed',
'logs_folder_open_failed',
'diagnostics_export_failed',
'launch_no_copy',
'launch_busy',
'launch_lab_required',
'launch_lab_missing',
'launch_lab_version',
'launch_lab_failed',
'launch_game_running',
'launch_copy_in_steam',
'launch_build_failed',
'launch_build_unavailable',
'launch_port_busy',
'launch_server_exited',
/** A folder the player chose does not exist or cannot be read (params: path). */
'folder_unreadable',
/** The chosen folder lacks the files of a War Thunder installation (params: path). */
+2
View File
@@ -12,6 +12,8 @@ export const IPC_CHANNEL_PREFIXES = [
'dialog:',
/** Installing the offline version: looking at the chosen folders, copying, patching. */
'install:',
/** Starting and stopping the active copy. */
'launch:',
/** The launcher's own settings. */
'settings:',
/** The launcher window itself (it draws its own title bar). */
+23
View File
@@ -10,6 +10,7 @@ import {
PatchFeatureSchema,
TargetFolderInspectionSchema,
} from '../schemas/install.ts';
import { LabInfoSchema, LaunchStateSchema } from '../schemas/launch.ts';
import { SettingsPatchSchema, SettingsSchema } from '../schemas/settings.ts';
/**
@@ -25,6 +26,7 @@ export const ipcContract = {
output: z.object({
version: z.string(),
electron: z.string(),
development: z.boolean(),
/** The operating system's preferred language, as Electron reports it (e.g. "zh-CN"). */
systemLocale: z.string(),
userDataPath: z.string(),
@@ -93,6 +95,26 @@ export const ipcContract = {
input: z.void(),
output: z.array(PatchFeatureSchema),
},
'launch:getState': {
input: z.void(),
output: LaunchStateSchema,
},
'launch:getLabInfo': {
input: z.void(),
output: LabInfoSchema.nullable(),
},
'launch:start': {
input: z.void(),
output: LaunchStateSchema,
},
'launch:stop': {
input: z.void(),
output: z.void(),
},
'launch:openServerStatus': {
input: z.void(),
output: z.void(),
},
'settings:get': {
input: z.void(),
output: SettingsSchema,
@@ -114,6 +136,7 @@ export const ipcContract = {
export const ipcEvents = {
'event:settings-changed': SettingsSchema,
'event:install-progress': InstallProgressSchema,
'event:launch-state': LaunchStateSchema,
} as const;
export type IpcChannel = keyof typeof ipcContract;
@@ -0,0 +1,22 @@
import { z } from 'zod';
import { APP_ERROR_CODES } from '../errors.ts';
export const LaunchStateSchema = z.object({
phase: z.enum([
'ready', 'checking', 'building', 'starting-server', 'starting-game', 'running',
'stopping', 'port-busy', 'version-changed', 'server-exited', 'failed',
]),
port: z.number().int().min(1).max(65535).optional(),
filesWritten: z.number().int().nonnegative().optional(),
filesTotal: z.number().int().nonnegative().optional(),
file: z.string().optional(),
actualVersion: z.string().nullable().optional(),
error: z.enum(APP_ERROR_CODES).optional(),
});
export type LaunchState = z.output<typeof LaunchStateSchema>;
export const LabInfoSchema = z.object({
copyPath: z.string(),
port: z.number().int().min(1).max(65535),
});
@@ -3,6 +3,9 @@ import { LANGUAGE_CHOICES } from '../languages.ts';
import { BACKGROUND_RANDOM, BackgroundChoiceSchema } from './background.ts';
const LanguageChoiceSchema = z.enum(LANGUAGE_CHOICES);
const WindowCloseSchema = z.enum(['quit', 'tray']);
const AfterGameStartsSchema = z.enum(['minimize', 'keep']);
const LabPathSchema = z.string().min(1).nullable();
/** The launcher's own settings (not the game's, not the local service's tuning). */
export const SettingsSchema = z.object({
@@ -11,6 +14,11 @@ export const SettingsSchema = z.object({
background: BackgroundChoiceSchema.default(BACKGROUND_RANDOM),
/** Fetch wallpapers from the game website's public gallery. */
officialWallpapers: z.boolean().default(true),
windowClose: WindowCloseSchema.default('quit'),
afterGameStarts: AfterGameStartsSchema.default('minimize'),
developerMode: z.boolean().default(true),
labStockPath: LabPathSchema.default(null),
labDataPath: LabPathSchema.default(null),
});
export type Settings = z.output<typeof SettingsSchema>;
@@ -20,6 +28,11 @@ export const SettingsPatchSchema = z.object({
language: LanguageChoiceSchema.optional(),
background: BackgroundChoiceSchema.optional(),
officialWallpapers: z.boolean().optional(),
windowClose: WindowCloseSchema.optional(),
afterGameStarts: AfterGameStartsSchema.optional(),
developerMode: z.boolean().optional(),
labStockPath: LabPathSchema.optional(),
labDataPath: LabPathSchema.optional(),
});
export type SettingsPatch = z.output<typeof SettingsPatchSchema>;