Skip to content

Commit 85841da

Browse files
authored
Merge pull request #61 from js-mode/master
Fix main_process.js so that packaging function is wrapped in if statment
2 parents a408f81 + d8e6a24 commit 85841da

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

main_process.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// @ts-nocheck
2-
// Basic init
32
const { app, BrowserWindow, ipcMain, Menu, Dialog } = require('electron');
43
const createMenuBar = require('./backend/menuBar.js');
54
const { fork, exec } = require('child_process');
65
const path = require('path');
76
const fs = require('fs');
87

9-
// To avoid being garbage collected
108
let mainWindow;
119

1210
app.on('ready', () => {
@@ -15,34 +13,36 @@ app.on('ready', () => {
1513
//Adding Menu Bar
1614
const menu = Menu.buildFromTemplate(createMenuBar(mainWindow, ResetDir, OpenDir));
1715
Menu.setApplicationMenu(menu);
18-
const initialStartFlagFilePath = path.join(__dirname, 'electronUserData', 'initialStartup.txt');
19-
if (!fs.existsSync(initialStartFlagFilePath)) {
20-
let pathToExecutable;
21-
if (process.platform === 'darwin') {
22-
pathToExecutable = path.join(__dirname, '..', '..', 'MacOS', 'bundle-bee');
23-
} else if (process.platform === 'win32') {
24-
pathToExecutable = path.join(__dirname, '..', '..', 'MacOS', 'bundle-bee');
25-
}
26-
fs.writeFile(
27-
initialStartFlagFilePath,
28-
`command to run executable:
16+
if (process.env.NODE_ENV === 'packaging') {
17+
const initialStartFlagFilePath = path.join(__dirname, 'electronUserData', 'initialStartup.txt');
18+
if (!fs.existsSync(initialStartFlagFilePath)) {
19+
let pathToExecutable;
20+
if (process.platform === 'darwin') {
21+
pathToExecutable = path.join(__dirname, '..', '..', 'MacOS', 'bundle-bee');
22+
} else if (process.platform === 'win32') {
23+
pathToExecutable = path.join(__dirname, '..', '..', 'MacOS', 'bundle-bee');
24+
}
25+
fs.writeFile(
26+
initialStartFlagFilePath,
27+
`command to run executable:
2928
open ${pathToExecutable}
3029
dirname: ${__dirname}
3130
filename: ${__filename}
3231
initalstartflagfilepath: ${initialStartFlagFilePath}
3332
`
34-
);
35-
exec(`open ${pathToExecutable}`, err => {
33+
);
34+
exec(`open ${pathToExecutable}`, err => {
35+
app.exit(0);
36+
});
37+
} else {
38+
fs.unlink(initialStartFlagFilePath, err => {
39+
if (err) console.log(err);
40+
});
41+
}
42+
mainWindow.on('close', () => {
3643
app.exit(0);
3744
});
38-
} else {
39-
fs.unlink(initialStartFlagFilePath, err => {
40-
if (err) console.log(err);
41-
});
4245
}
43-
mainWindow.on('close', () => {
44-
app.exit(0);
45-
});
4646
});
4747

4848
ipcMain.on('ondragstart', (event, filePath) => {
@@ -178,4 +178,4 @@ function ResetDir() {
178178
app.exit(0);
179179
}
180180

181-
function OpenDir(build) {}
181+
function OpenDir(build) { }

0 commit comments

Comments
 (0)