2020-07-02 06:36:29 +03:00
|
|
|
// Modules to control application life and create native browser window
|
2020-07-10 06:20:05 +03:00
|
|
|
const { app, BrowserWindow } = require("electron");
|
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs-extra");
|
2020-07-02 06:36:29 +03:00
|
|
|
|
2020-08-01 21:25:24 +03:00
|
|
|
// NOTE(colin): use NEXTJS Production build
|
2020-08-03 00:09:55 +03:00
|
|
|
if (process.env.NODE_ENV == undefined) process.env.NODE_ENV = "production";
|
2020-08-01 21:25:24 +03:00
|
|
|
// NOTE(colin): allow API connection
|
2020-08-03 00:09:55 +03:00
|
|
|
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED == undefined)
|
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
|
2020-08-01 21:25:24 +03:00
|
|
|
|
2020-07-04 19:30:32 +03:00
|
|
|
function bootServer() {
|
2020-07-09 05:56:22 +03:00
|
|
|
// TODO(colin): Spin up server on a child process
|
|
|
|
// const { fork } = require('child_process');
|
|
|
|
// const ps = fork(path.join(__dirname, '../', 'index.js'));
|
2020-07-10 06:20:05 +03:00
|
|
|
require(path.join(__dirname, "../", "index.js"));
|
2020-08-03 06:46:22 +03:00
|
|
|
// console.log("server running");
|
2020-07-04 19:30:32 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 19:54:44 +03:00
|
|
|
function fileOverrides() {
|
|
|
|
fs.copy(
|
2020-07-10 06:20:05 +03:00
|
|
|
path.join(__dirname, "./google-protobuf.js"),
|
|
|
|
path.join(__dirname, "../node_modules/google-protbuf/google-protobuf.js"),
|
2020-07-07 19:54:44 +03:00
|
|
|
(err) => {
|
|
|
|
if (err) throw err;
|
2020-07-10 06:20:05 +03:00
|
|
|
console.log("google-protobuf.js was copied to node_modules folder");
|
2020-07-07 19:54:44 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2020-07-04 19:30:32 +03:00
|
|
|
// require(path.join(__dirname, "../nodedistribution/", "main.js"));
|
2020-07-02 06:36:29 +03:00
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
// Create the browser window.
|
|
|
|
const mainWindow = new BrowserWindow({
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
webPreferences: {
|
2020-07-10 06:20:05 +03:00
|
|
|
preload: path.join(__dirname, "preload.js"),
|
2020-07-03 18:32:36 +03:00
|
|
|
nodeIntegration: true,
|
2020-07-05 00:24:34 +03:00
|
|
|
experimentalFeatures: true,
|
2020-07-02 06:36:29 +03:00
|
|
|
},
|
|
|
|
});
|
2020-07-03 18:32:36 +03:00
|
|
|
// Open the DevTools.
|
|
|
|
mainWindow.webContents.openDevTools();
|
2020-07-02 06:36:29 +03:00
|
|
|
// and load the index.html of the app.
|
2020-07-16 08:48:51 +03:00
|
|
|
// TODO(jim):
|
|
|
|
// We shouldn't hardcode this port.
|
2020-08-07 02:06:54 +03:00
|
|
|
mainWindow.loadURL("http://localhost:1337/_");
|
2020-07-10 06:20:05 +03:00
|
|
|
console.log("window created");
|
2020-07-02 06:36:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method will be called when Electron has finished
|
|
|
|
// initialization and is ready to create browser windows.
|
|
|
|
// Some APIs can only be used after this event occurs.
|
|
|
|
app.whenReady().then(() => {
|
2020-07-07 19:54:44 +03:00
|
|
|
fileOverrides();
|
2020-07-04 19:30:32 +03:00
|
|
|
bootServer();
|
2020-07-02 06:36:29 +03:00
|
|
|
createWindow();
|
|
|
|
|
2020-09-15 07:14:11 +03:00
|
|
|
app.on("activate", function () {
|
2020-07-02 06:36:29 +03:00
|
|
|
// On macOS it's common to re-create a window in the app when the
|
|
|
|
// dock icon is clicked and there are no other windows open.
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Quit when all windows are closed, except on macOS. There, it's common
|
|
|
|
// for applications and their menu bar to stay active until the user quits
|
|
|
|
// explicitly with Cmd + Q.
|
2020-09-15 07:14:11 +03:00
|
|
|
app.on("window-all-closed", function () {
|
2020-07-10 06:20:05 +03:00
|
|
|
if (process.platform !== "darwin") app.quit();
|
2020-07-02 06:36:29 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// In this file you can include the rest of your app's specific main process
|
|
|
|
// code. You can also put them in separate files and require them here.
|