mirror of https://github.com/lukechilds/Agama.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.4 KiB
125 lines
3.4 KiB
//main proc for EasyDEX GUI
|
|
//this app spawns iguana in background in nontech-mode
|
|
|
|
const electron = require('electron')
|
|
const app = electron.app
|
|
const BrowserWindow = electron.BrowserWindow
|
|
|
|
var fs = require('fs');
|
|
var mkdirp = require('mkdirp');
|
|
|
|
// GUI APP settings and starting gui on address http://120.0.0.1:77777
|
|
var express = require('express')
|
|
var guiapp = express()
|
|
|
|
guiapp.use('/gui', express.static('gui'))
|
|
|
|
guiapp.get('/', function (req, res) {
|
|
res.send('Hello World!')
|
|
})
|
|
|
|
var rungui = guiapp.listen(77777, function () {
|
|
console.log('Example guiapp listening on port 77777!')
|
|
})
|
|
// END GUI App Settings
|
|
|
|
const path = require('path')
|
|
const url = require('url')
|
|
const os = require('os')
|
|
//require('./assets/js/iguana.js'); //below code shall be separated into asset js for public version
|
|
const spawn = require('child_process').spawn;
|
|
const exec = require('child_process').exec;
|
|
var iguanaOSX = path.join(__dirname, '/assets/iguana/iguana');
|
|
var iguanaLinux = path.join(__dirname, '/assets/iguana/iguanaLinux');
|
|
var iguanaWin = path.join(__dirname, '/assets/iguana/iguana');
|
|
|
|
if (os.platform() === 'darwin') {
|
|
var iguanaDir = process.env.HOME + '/Library/Application Support/iguana'
|
|
}
|
|
if (os.platform() === 'linux') {
|
|
var iguanaDir = process.env.HOME + '.iguana'
|
|
}
|
|
if (os.platform() === 'win32') {
|
|
var iguanaDir = process.env.APPDATA + '/iguana'
|
|
}
|
|
|
|
console.log(iguanaDir);
|
|
|
|
mkdirp(iguanaDir, function (err) {
|
|
if (err)
|
|
console.error(err)
|
|
else
|
|
fs.readdir(iguanaDir, (err, files) => {
|
|
files.forEach(file => {
|
|
console.log(file);
|
|
});
|
|
})
|
|
});
|
|
|
|
|
|
|
|
let mainWindow
|
|
|
|
function createWindow () {
|
|
|
|
// initialise window
|
|
mainWindow = new BrowserWindow({width: 800, height: 600})
|
|
|
|
// load our index.html (i.e. easyDEX GUI)
|
|
mainWindow.loadURL('http://localhost:77777/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', createWindow)
|
|
|
|
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 (mainWindow === null) {
|
|
createWindow()
|
|
}
|
|
})
|