electron prototype

This commit is contained in:
azivner 2017-10-20 23:43:20 -04:00
parent 0a793d0c47
commit 83243dd936
7 changed files with 89 additions and 7 deletions

54
index.js Normal file
View File

@ -0,0 +1,54 @@
'use strict';
const electron = require('electron');
const app = electron.app;
// Adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')();
// Prevent window being garbage collected
let mainWindow;
function onClosed() {
// Dereference the window
// For multiple windows store them in an array
mainWindow = null;
}
function createMainWindow() {
const win = new electron.BrowserWindow({
width: 1200,
height: 900
});
win.setMenu(null);
win.loadURL('http://localhost:3000');
win.on('closed', onClosed);
win.webContents.on('new-window', (e, url) => {
if (url !== mainWindow.webContents.getURL()) {
e.preventDefault();
require('electron').shell.openExternal(url);
}
});
return win;
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});
app.on('ready', () => {
mainWindow = createMainWindow();
});
require('./bin/www');

View File

@ -3,13 +3,17 @@
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./bin/www"
"start": "node ./bin/www",
"test-electron": "xo",
"start-electron": "electron .",
"build-electron": "electron-packager . --out=dist --asar --overwrite --all"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~3.1.0",
"ejs": "~2.5.7",
"electron": "^1.7.9",
"express": "~4.16.2",
"express-session": "^1.15.6",
"express-sessions": "^1.0.6",
@ -20,6 +24,20 @@
"scrypt": "^6.0.3",
"serve-favicon": "~2.4.5",
"session-file-store": "^1.1.2",
"sqlite": "^2.8.0"
"sqlite": "^2.8.0",
"electron-debug": "^1.0.0",
"electron-rebuild": "^1.6.0"
},
"devDependencies": {
"devtron": "^1.1.0",
"electron-packager": "^8.0.0",
"electron": "^1.6.6",
"xo": "^0.18.0"
},
"xo": {
"envs": [
"node",
"browser"
]
}
}

View File

@ -80,4 +80,8 @@ $(document).tooltip({
});
});
}
});
});
function isElectron() {
return window && window.process && window.process.type;
}

View File

@ -1,3 +0,0 @@
<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>

View File

@ -217,6 +217,9 @@
const baseApiUrl = 'api/';
</script>
<!-- Required for correct loading of scripts in Electron -->
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<script src="libraries/jquery.min.js"></script>
<!-- bootstrap needs to be included before jQuery UI, otherwise close icon in the dialog will be missing -->

View File

@ -43,7 +43,10 @@
</div>
</div>
</div>
<!-- Required for correct loading of scripts in Electron -->
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<link href="libraries/bootstrap/css/bootstrap.css" rel="stylesheet">
<script src="libraries/bootstrap/js/bootstrap.js"></script>
</body>

View File

@ -47,6 +47,9 @@
const baseApiUrl = 'api/';
</script>
<!-- Required for correct loading of scripts in Electron -->
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<script src="stat/lib/jquery.min.js"></script>
<link href="stat/lib/bootstrap/css/bootstrap.css" rel="stylesheet">