Skip to content

Commit

Permalink
feat: new runtime process model [#30]
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukaii committed Aug 13, 2023
1 parent 7d974bd commit e20243c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
8 changes: 7 additions & 1 deletion apps/electron-client/forge.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from "path";

import { MakerDeb } from "@electron-forge/maker-deb";
import { MakerRpm } from "@electron-forge/maker-rpm";
import { MakerSquirrel } from "@electron-forge/maker-squirrel";
Expand All @@ -9,7 +11,11 @@ import { mainConfig } from "./webpack.main.config";
import { rendererConfig } from "./webpack.renderer.config";

const config: ForgeConfig = {
packagerConfig: {},
packagerConfig: {
extraResource: [
path.join(__dirname, "node_modules/@blastlauncher/runtime/dist/run.cjs"),
]
},
rebuildConfig: {},
makers: [new MakerSquirrel({}), new MakerZIP({}, ["darwin"]), new MakerRpm({}), new MakerDeb({})],
plugins: [
Expand Down
36 changes: 28 additions & 8 deletions apps/electron-client/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
// import { utilityProcess } from 'electron'
import { ChildProcess, spawn } from "child_process";
import path from "path";

let runtimeProcess: any;
import { nrm } from "./nrm";

export const startRuntime = async () => {
// const modulePath = require.resolve('@blastlauncher/runtime/dist/run.js')
// runtimeProcess = utilityProcess.fork(modulePath)
}
let runtimeProcess: ChildProcess | undefined;

const getRuntimePath = (): string => {
if (process.env.NODE_ENV === "development") {
return require.resolve("@blastlauncher/runtime/dist/run.cjs");
} else {
return path.join(process.resourcesPath, "run.cjs");
}
};

export const startRuntime = async () => {
const modulePath = getRuntimePath();
const runtimePath = nrm.nodePath;

console.log("runtimePath", runtimePath);
console.log("modulePath", modulePath);

runtimeProcess = spawn(runtimePath, [modulePath], {
stdio: "ignore",
env: process.env,
});
};

export const stopRuntime = (): void => {
runtimeProcess?.kill()
}
runtimeProcess?.kill();
};

// TODO: more process management

0 comments on commit e20243c

Please sign in to comment.