Skip to content

Commit b6c4882

Browse files
committed
Successfully start the server even with ASAR bundling
1 parent 8f3de5a commit b6c4882

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build:src": "tsc",
1010
"start": "node setup-local.js && npm run start:app",
1111
"start:dev": "node setup-dev.js && cross-env APP_URL='http://local.httptoolkit.tech:8080' npm run start:app",
12-
"start:app": "tsc-watch --onSuccess 'electron ./dist/index.js'",
12+
"start:app": "tsc-watch --onSuccess 'electron .'",
1313
"package": "electron-forge package",
1414
"make": "electron-forge make",
1515
"publish": "electron-forge publish"

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ if (!semver.parse(BUNDLED_SERVER_VERSION)) {
4747
throw new Error("Package.json must specify an exact server version");
4848
}
4949

50+
const APP_PATH = app.getAppPath();
51+
const RESOURCES_PATH = APP_PATH.endsWith('app.asar')
52+
? path.dirname(APP_PATH) // If we're bundled, resources are above the bundle
53+
: APP_PATH; // Otherwise everything is in the root of the app
54+
5055
// Keep a global reference of the window object, if you don't, the window will
5156
// be closed automatically when the JavaScript object is garbage collected.
5257
let windows: Electron.BrowserWindow[] = [];
@@ -309,7 +314,7 @@ if (!amMainInstance) {
309314

310315
async function startServer(retries = 2) {
311316
const binName = isWindows ? 'httptoolkit-server.cmd' : 'httptoolkit-server';
312-
const serverBinPath = path.join(__dirname, '..', 'httptoolkit-server', 'bin', binName);
317+
const serverBinPath = path.join(RESOURCES_PATH, 'httptoolkit-server', 'bin', binName);
313318
const serverBinCommand = isWindows ? `"${serverBinPath}"` : serverBinPath;
314319

315320
server = spawn(serverBinCommand, ['start'], {

0 commit comments

Comments
 (0)