Skip to content

Commit a3b5d44

Browse files
committed
fix: app creating infinite windows
1 parent 53b33f3 commit a3b5d44

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

.github/workflows/electron-build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ jobs:
3131
strategy:
3232
matrix:
3333
include:
34-
- os: windows-latest
35-
platform: win
36-
artifact: dist/*.exe
34+
# - os: windows-latest
35+
# platform: win
36+
# artifact: dist/*.exe
3737
- os: macos-latest
3838
platform: mac
3939
artifact: dist/*.dmg
40-
- os: ubuntu-latest
41-
platform: linux
42-
artifact: dist/*.AppImage
40+
# - os: ubuntu-latest
41+
# platform: linux
42+
# artifact: dist/*.AppImage
4343

4444
runs-on: ${{ matrix.os }}
4545

electron/main.cjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ const { spawn } = require("child_process");
44
const path = require("path");
55
const net = require("net");
66

7+
// Prevent multiple instances — second launch focuses the existing window instead
8+
if (!app.requestSingleInstanceLock()) {
9+
app.quit();
10+
process.exit(0);
11+
}
12+
713
const isPacked = app.isPackaged;
8-
const root = isPacked ? process.resourcesPath : path.join(__dirname, "..");
914

10-
// Deno binary: shipped via the `deno` npm package
15+
// __dirname resolves correctly in both dev and packaged (asar-off) mode:
16+
// dev: <project>/electron → root = <project>
17+
// packed: <app>/Resources/app/electron → root = <app>/Resources/app
18+
const root = path.join(__dirname, "..");
19+
20+
// Deno binary is an extraResource — lives outside the app folder in both modes
1121
const denoBin = isPacked
1222
? path.join(process.resourcesPath, "deno-bin", process.platform === "win32" ? "deno.exe" : "deno")
1323
: path.join(root, "node_modules", "deno", process.platform === "win32" ? "deno.exe" : "deno");
@@ -95,12 +105,19 @@ function createWindow() {
95105
win.on("closed", () => { win = null; });
96106
}
97107

108+
app.on("second-instance", () => {
109+
// A second instance tried to launch — focus the existing window instead
110+
if (win) {
111+
if (win.isMinimized()) win.restore();
112+
win.focus();
113+
}
114+
});
115+
98116
app.whenReady().then(async () => {
99117
startDeno();
100118
startNuxt();
101119

102120
try {
103-
// Wait for the Nuxt server to be ready before showing the window
104121
await waitForPort(NUXT_PORT);
105122
} catch (err) {
106123
console.error("Nuxt server did not start in time:", err.message);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"build": {
4646
"appId": "dev.locode.app",
4747
"productName": "LoCode",
48-
"asar": true,
48+
"asar": false,
4949
"files": [
5050
"electron/**/*",
5151
".output/**/*",

0 commit comments

Comments
 (0)