forked from Noobulater/gmforge-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
104 lines (90 loc) · 2.9 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var app = require('electron').app;
var Window = require('electron').BrowserWindow; // jshint ignore:line
var Tray = require('electron').Tray; // jshint ignore:line
var Menu = require('electron').Menu; // jshint ignore:line
var fs = require('fs');
var server = require('./app');
var game = require('./lib/game.js');
var mainWindow = null;
var options = server.options;
app.commandLine.appendSwitch("in-process-gpu");
let invalidateIntervalId = undefined;
process.on('uncaughtException', function (err) {
console.log(err);
})
app.on('ready', function () {
'use strict';
var path = require('path');
var iconPath = path.resolve(".", './brandsmall.png');
const appIcon = new Tray(iconPath);
mainWindow = new Window({
width: options.width || 1280,
height: options.height || 960,
autoHideMenuBar: true,
useContentSize: true,
resizable: true,
fullscreen : options.fullscreen,
icon: iconPath,
title : "GM Forge",
webPreferences: {
plugins: true,
nativeWindowOpen : true
},
// 'node-integration': false // otherwise various client-side things may break
});
mainWindow.webContents.on("dom-ready", () => {
invalidateIntervalId = setInterval(() => {
// help the steam overlay
try {
mainWindow.webContents.invalidate();
}
catch (err) {
}
}, 10);
});
appIcon.setToolTip('GM Forge');
mainWindow.loadURL('http://127.0.0.1:'+ (options.port || 30000)+'/');
mainWindow.webContents.on('new-window', function(e, url) {
if (url != "about:blank") {
e.preventDefault();
require('electron').shell.openExternal(url);
}
else if (e.sender && e.WebContents && e.WebContents.BrowserWindowOptions) {
console.log(e, url);
e.WebContents.BrowserWindowOptions = null;
}
});
mainWindow.webContents.on('before-input-event', (event, input) => {
if (input.type == "keyUp" && input.key == "F10") {
mainWindow.webContents.openDevTools();
}
if (input.type == "keyUp" && input.key == "F5") {
mainWindow.webContents.reloadIgnoringCache();
}
if (input.type == "keyUp" && input.key == "F8") {
server.server.close();
app.quit();
}
});
mainWindow.focus();
server.exit(function(){
if (invalidateIntervalId !== undefined) {
clearInterval(invalidateIntervalId);
}
game.saveGame("localhost", true);
mainWindow.close();
app.quit();
require('ngrok').kill();
});
//require('electron').shell.openExternal("http://www.gmforge.io");
});
// shut down all parts to app after windows all closed.
app.on('window-all-closed', function () {
if (invalidateIntervalId !== undefined) {
clearInterval(invalidateIntervalId);
}
'use strict';
server.server.close();
app.quit();
require('ngrok').kill();
});