feat: improve NodeCG runtime installation and relaunch behavior

This commit is contained in:
2026-05-16 22:22:30 +02:00
parent 41e4e91c4b
commit 955a1f7116
10 changed files with 104 additions and 37 deletions
+14 -4
View File
@@ -28,6 +28,11 @@ type RuntimeProvisionerDeps = {
writeFileSync: (filePath: string, content: string) => unknown;
};
export type PreparedNodecgRuntime = {
runtimePath: string;
installed: boolean;
};
type RuntimeManifest = {
appVersion?: unknown;
bundleName?: unknown;
@@ -47,14 +52,16 @@ export function prepareUserNodecgRuntime({
bundleName,
log,
deps,
}: RuntimeProvisionerConfig): string {
}: RuntimeProvisionerConfig): PreparedNodecgRuntime {
const resolvedDeps = resolveDeps(deps);
const targetRuntimePath = path.join(userDataPath, "nodecg");
validateSourceRuntime(sourceRuntimePath, bundleName, resolvedDeps.existsSync);
resolvedDeps.mkdirSync(targetRuntimePath, { recursive: true });
if (shouldInstallRuntime(sourceRuntimePath, targetRuntimePath, appVersion, bundleName, resolvedDeps)) {
const installed = shouldInstallRuntime(sourceRuntimePath, targetRuntimePath, appVersion, bundleName, resolvedDeps);
if (installed) {
log(`Installing managed NodeCG runtime into ${targetRuntimePath}`);
installManagedRuntime(sourceRuntimePath, targetRuntimePath, appVersion, bundleName, resolvedDeps);
}
@@ -63,7 +70,7 @@ export function prepareUserNodecgRuntime({
resolvedDeps.mkdirSync(path.join(targetRuntimePath, writableDir), { recursive: true });
}
return targetRuntimePath;
return { runtimePath: targetRuntimePath, installed };
}
function resolveDeps(deps?: Partial<RuntimeProvisionerDeps>): RuntimeProvisionerDeps {
@@ -166,7 +173,10 @@ function installManagedRuntime(
);
}
function readJson(filePath: string, deps: Pick<RuntimeProvisionerDeps, "existsSync" | "readFileSync">): RuntimeManifest | null {
function readJson(
filePath: string,
deps: Pick<RuntimeProvisionerDeps, "existsSync" | "readFileSync">,
): RuntimeManifest | null {
if (!deps.existsSync(filePath)) {
return null;
}