mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor(main): extract startup bootstrap dependency factory
This commit is contained in:
89
src/main.ts
89
src/main.ts
@@ -613,47 +613,7 @@ function resolveMediaPathForJimaku(mediaPath: string | null): string | null {
|
|||||||
: mediaPath;
|
: mediaPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const startupState = runStartupBootstrapRuntimeService({
|
const startupState = runStartupBootstrapRuntimeService(createStartupBootstrapRuntimeDeps());
|
||||||
argv: process.argv,
|
|
||||||
parseArgs: (argv) => parseArgs(argv),
|
|
||||||
setLogLevelEnv: (level) => {
|
|
||||||
process.env.SUBMINER_LOG_LEVEL = level;
|
|
||||||
},
|
|
||||||
enableVerboseLogging: () => {
|
|
||||||
process.env.SUBMINER_LOG_LEVEL = "debug";
|
|
||||||
},
|
|
||||||
forceX11Backend: (args) => {
|
|
||||||
forceX11Backend(args);
|
|
||||||
},
|
|
||||||
enforceUnsupportedWaylandMode: (args) => {
|
|
||||||
enforceUnsupportedWaylandMode(args);
|
|
||||||
},
|
|
||||||
getDefaultSocketPath: () => getDefaultSocketPath(),
|
|
||||||
defaultTexthookerPort: DEFAULT_TEXTHOOKER_PORT,
|
|
||||||
runGenerateConfigFlow: (args) => {
|
|
||||||
if (!args.generateConfig || shouldStartApp(args)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
generateDefaultConfigFile(args, {
|
|
||||||
configDir: CONFIG_DIR,
|
|
||||||
defaultConfig: DEFAULT_CONFIG,
|
|
||||||
generateTemplate: (config) => generateConfigTemplate(config as never),
|
|
||||||
})
|
|
||||||
.then((exitCode) => {
|
|
||||||
process.exitCode = exitCode;
|
|
||||||
app.quit();
|
|
||||||
})
|
|
||||||
.catch((error: Error) => {
|
|
||||||
console.error(`Failed to generate config: ${error.message}`);
|
|
||||||
process.exitCode = 1;
|
|
||||||
app.quit();
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
startAppLifecycle: (args) => {
|
|
||||||
startAppLifecycleService(args, createAppLifecycleDepsRuntimeService(createAppLifecycleRuntimeDeps()));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
appState.initialArgs = startupState.initialArgs;
|
appState.initialArgs = startupState.initialArgs;
|
||||||
appState.mpvSocketPath = startupState.mpvSocketPath;
|
appState.mpvSocketPath = startupState.mpvSocketPath;
|
||||||
@@ -770,6 +730,53 @@ function createAppLifecycleRuntimeDeps() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createStartupBootstrapRuntimeDeps() {
|
||||||
|
return {
|
||||||
|
argv: process.argv,
|
||||||
|
parseArgs: (argv) => parseArgs(argv),
|
||||||
|
setLogLevelEnv: (level) => {
|
||||||
|
process.env.SUBMINER_LOG_LEVEL = level;
|
||||||
|
},
|
||||||
|
enableVerboseLogging: () => {
|
||||||
|
process.env.SUBMINER_LOG_LEVEL = "debug";
|
||||||
|
},
|
||||||
|
forceX11Backend: (args) => {
|
||||||
|
forceX11Backend(args);
|
||||||
|
},
|
||||||
|
enforceUnsupportedWaylandMode: (args) => {
|
||||||
|
enforceUnsupportedWaylandMode(args);
|
||||||
|
},
|
||||||
|
getDefaultSocketPath: () => getDefaultSocketPath(),
|
||||||
|
defaultTexthookerPort: DEFAULT_TEXTHOOKER_PORT,
|
||||||
|
runGenerateConfigFlow: (args) => {
|
||||||
|
if (!args.generateConfig || shouldStartApp(args)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
generateDefaultConfigFile(args, {
|
||||||
|
configDir: CONFIG_DIR,
|
||||||
|
defaultConfig: DEFAULT_CONFIG,
|
||||||
|
generateTemplate: (config) => generateConfigTemplate(config as never),
|
||||||
|
})
|
||||||
|
.then((exitCode) => {
|
||||||
|
process.exitCode = exitCode;
|
||||||
|
app.quit();
|
||||||
|
})
|
||||||
|
.catch((error: Error) => {
|
||||||
|
console.error(`Failed to generate config: ${error.message}`);
|
||||||
|
process.exitCode = 1;
|
||||||
|
app.quit();
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
startAppLifecycle: (args) => {
|
||||||
|
startAppLifecycleService(
|
||||||
|
args,
|
||||||
|
createAppLifecycleDepsRuntimeService(createAppLifecycleRuntimeDeps()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function handleCliCommand(
|
function handleCliCommand(
|
||||||
args: CliArgs,
|
args: CliArgs,
|
||||||
source: CliCommandSource = "initial",
|
source: CliCommandSource = "initial",
|
||||||
|
|||||||
Reference in New Issue
Block a user