From 21f182660835e33c5ac3a1993e07fdf9c142190a Mon Sep 17 00:00:00 2001
From: pbca26 <pbca26@gmail.com>
Date: Sat, 14 Apr 2018 21:11:04 +0300
Subject: [PATCH] load gui content from file instead of a remote url

---
 main.js | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/main.js b/main.js
index f77ceaf..01a5ba4 100644
--- a/main.js
+++ b/main.js
@@ -25,6 +25,8 @@ if (osPlatform === 'linux') {
 	process.env.ELECTRON_RUN_AS_NODE = true;
 }
 
+process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
+
 // GUI APP settings and starting gui on address http://120.0.0.1:17777
 let shepherd = require('./routes/shepherd');
 let guiapp = express();
@@ -124,8 +126,7 @@ process.once('loaded', () => {
 });
 
 // silent errors
-if (!appConfig.debug ||
-		!appConfig.dev) {
+if (!appConfig.dev) {
 	process.on('uncaughtException', (err) => {
 	  shepherd.log(`${(new Date).toUTCString()} uncaughtException: ${err.message}`);
 	  shepherd.log(err.stack);
@@ -185,7 +186,7 @@ function createAppCloseWindow() {
 
 	appCloseWindow.setResizable(false);
 
-	appCloseWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/startup/app-closing.html`);
+	appCloseWindow.loadURL(appConfig.dev ? `http://${appConfig.host}:${appConfig.agamaPort}/gui/startup/app-closing.html` : `file://${__dirname}/gui/startup/app-closing.html`);
 
   appCloseWindow.webContents.on('did-finish-load', () => {
     setTimeout(() => {
@@ -232,7 +233,7 @@ function createWindow(status, hideLoadingWindow) {
 					shepherd.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
 					shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
 					// start sockets.io
-					io.set('origins', appConfig.dev ? 'http://127.0.0.1:3000' : `http://127.0.0.1:${appConfig.agamaPort}`); // set origin
+					io.set('origins', appConfig.dev ? 'http://127.0.0.1:3000' : null); // set origin
 				});
 
 				// initialise window
@@ -246,7 +247,7 @@ function createWindow(status, hideLoadingWindow) {
 				if (appConfig.dev) {
 					mainWindow.loadURL('http://127.0.0.1:3000');
 				} else {
-					mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/EasyDEX-GUI/react/build`);
+					mainWindow.loadURL(`file://${__dirname}/gui/EasyDEX-GUI/react/build/index.html`);
 				}
 
 				shepherd.setIO(io); // pass sockets object to shepherd router
@@ -316,7 +317,7 @@ function createWindow(status, hideLoadingWindow) {
 					shepherd.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
 					shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
 				});
-				mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort + 1}/gui/startup/agama-instance-error.html`);
+				mainWindow.loadURL(appConfig.dev ? `http://${appConfig.host}:${appConfig.agamaPort + 1}/gui/startup/agama-instance-error.html` : `file://${__dirname}/gui/startup/agama-instance-error.html`);
 				shepherd.log('another agama app is already running');
 			}