From 9ced8a01f125f5fcb58581abd65a067270a2f58c Mon Sep 17 00:00:00 2001 From: Satinder Grewal Date: Mon, 5 Dec 2016 12:22:26 +1300 Subject: [PATCH] loading window base code added stub code added to first show loading window, frameless. when loading window closes, load easydex gui window --- main.js | 91 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 15 deletions(-) diff --git a/main.js b/main.js index 56a4a8b..caaa33d 100644 --- a/main.js +++ b/main.js @@ -60,29 +60,28 @@ mkdirp(iguanaDir, function (err) { let mainWindow +let loadingWindow -function createWindow () { + +function createLoadingWindow() { + mainWindow = null; // initialise window - mainWindow = new BrowserWindow({width: 1280, height: 800}) + loadingWindow = new BrowserWindow({width: 500, height: 300, frame: false}) // load our index.html (i.e. easyDEX GUI) - mainWindow.loadURL('http://localhost:17777/gui/EasyDEX-GUI/'); - /*mainWindow.loadURL(url.format({ - pathname: path.join(__dirname, 'EasyDEX-GUI/index.html'), - protocol: 'file:', - slashes: true - }))*/ + loadingWindow.loadURL('http://localhost:17777/'); // DEVTOOLS - only for dev purposes - ca333 - //mainWindow.webContents.openDevTools() + //loadingWindow.webContents.openDevTools() // if window closed we kill iguana proc - mainWindow.on('closed', function () { + loadingWindow.on('closed', function () { ig.kill(); // our app does not have multiwindow - so we dereference the window object instead of // putting them into an window_arr - mainWindow = null + loadingWindow = null + createWindow('open') }) //ca333 todo - add os detector to use correct binary - so we can use the same bundle on ALL OS platforms @@ -108,7 +107,7 @@ function createWindow () { }); } -app.on('ready', createWindow) +app.on('ready', createLoadingWindow) app.on('window-all-closed', function () { ig.kill(); @@ -120,8 +119,70 @@ app.on('window-all-closed', function () { } }) -app.on('activate', function () { - if (mainWindow === null) { - createWindow() +function createWindow (status) { + if ( status === 'open') { + // initialise window + mainWindow = new BrowserWindow({width: 1280, height: 800}) + + // load our index.html (i.e. easyDEX GUI) + mainWindow.loadURL('http://localhost:17777/gui/EasyDEX-GUI/'); + /*mainWindow.loadURL(url.format({ + pathname: path.join(__dirname, 'EasyDEX-GUI/index.html'), + protocol: 'file:', + slashes: true + }))*/ + + // DEVTOOLS - only for dev purposes - ca333 + //mainWindow.webContents.openDevTools() + + // if window closed we kill iguana proc + mainWindow.on('closed', function () { + ig.kill(); + // our app does not have multiwindow - so we dereference the window object instead of + // putting them into an window_arr + mainWindow = null + }) + + //ca333 todo - add os detector to use correct binary - so we can use the same bundle on ALL OS platforms + //if (os.platform() === 'win32') { + //ex(iguanaWin) //specify binary in startup + //} + if (os.platform() === 'linux') { + process.chdir(iguanaDir); + ig = spawn(iguanaLinux); + } + if (os.platform() === 'darwin') { + process.chdir(iguanaDir); + ig = spawn(iguanaOSX); + } + //}if (os.platform() === 'freeBSD') { + //ex(iguanaFreeBSD) + //} + //ca333 - could also specifiy via os.arch (x86, x64, etc. ) in startup and pass via param to main proc + + ig.stderr.on( 'error: ', data => { + console.log( `stderr: ${data}` ); + }); } +} + +app.on('ready', function() { + createLoadingWindow }) + +app.on('window-all-closed', function () { + ig.kill(); + // in osx apps stay active in menu bar until explictly closed or quitted by CMD Q + // so we do not kill the app --> for the case user clicks again on the iguana icon + // we open just a new window and respawn iguana proc + if (process.platform !== 'darwin') { + app.quit() + } +}) + +app.on('activate', function () { + if (loadingWindow === null) { + //createWindow() + createLoadingWindow(); + } +}) \ No newline at end of file