-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
150 lines (134 loc) · 4.05 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'use strict';
// Modules to control application life and create native browser window
const { app, BrowserWindow, globalShortcut, ipcMain } = require('electron');
require('@electron/remote/main').initialize();
const fs = require('fs');
const fse = require('fs-extra');
const path = require('path');
const process = require("process");
const log = require('electron-log');
log.initialize({ preload: true });
let install = false;
//Common paths used throughout the application for consistency/changes
global.mypaths = {};
global.mypaths.app = {};
//armori.app/
global.mypaths.app.package = getPackagePath();
//armori.app/Content/Resources/app/
global.mypaths.app.app = app.getAppPath();
//armori.app/Content/Resources/app/game
global.mypaths.app.game = path.join(global.mypaths.app.app, 'game');
global.mypaths.app.installer = path.join(global.mypaths.app.app, 'installer');
global.mypaths.app.fixes = path.join(global.mypaths.app.app, 'fixes');
//gamefiles
global.mypaths.game = {}
//armori.app/Content/Resources/app/game/js
global.mypaths.game.js = path.join(global.mypaths.app.game, 'js');
global.mypaths.game.libs = path.join(global.mypaths.game.js, 'libs');
Object.freeze(global.mypaths);
log.info(global.mypaths);
async function main() {
//Add chromium switches from nwjs
addChromiumSwitches();
log.info(process.argv);
//if game files exist then run the game later
if (await fse.pathExists(path.join(global.mypaths.game.js, 'main.js'))) {
install = false;
app.setName("OMORI");
} else {
install = true;
app.setName("armori installer");
}
// Quit when all windows are closed
app.on('window-all-closed', function () {
app.quit();
});
await app.whenReady();
await createWindow();
//app.whenReady().then(async () => {
// await createWindow();
//})
}
function getSteamKey() {
let steamkey = process.argv[1];
//If testing use environment variable version
if (!steamkey) steamkey = process.env.DEV_OMORI_STEAMKEY;
return steamkey;
}
async function createWindow() {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 640,
height: 480,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
webSecurity: false,
plugins: true,
spellcheck: false,
// v8CacheOptions:"none",
additionalArguments: ["steamkey=" + getSteamKey(), "install=" + install, "root"],
/// nodeIntegrationInSubFrames: true,
preload: path.join(global.mypaths.app.app, 'preload.js'),
}
});
addRefreshShortcut();
require("@electron/remote/main").enable(mainWindow.webContents);
//run installer
if (install) {
await mainWindow.loadFile(path.join(global.mypaths.app.installer, 'index.html'));
} else {
//run game
await mainWindow.loadFile(path.join(global.mypaths.app.game, 'index.html'));
}
//mainWindow.webContents.openDevTools();
}
//f5 shortcut to relaunch application
function addRefreshShortcut() {
/*
globalShortcut.register('f5', function () {
log.info('f5 is pressed');
app.relaunch();
app.quit();
});
globalShortcut.register('CommandOrControl+R', function () {
log.info('CommandOrControl+R is pressed');
//mainWindow.reload();
app.relaunch();
app.quit();
});
*/
}
//Add chromium switches from nwjs
function addChromiumSwitches() {
app.commandLine.appendSwitch('--js-flags', '--expose-gc');
app.commandLine.appendSwitch('limit-fps', 60);
const args = [
'in-process-gpu',
'disable-direct-composition',
'enable-gpu-rasterization',
'enable-gpu-memory-buffer-video-frames',
'enable-native-gpu-memory-buffers',
'enable-zero-copy',
'enable-gpu-async-worker-context',
];
for (let arg of args) {
app.commandLine.appendArgument(arg);
}
}
function getPackagePath() {
//if we are in an .app dir
const p = app.getAppPath();
let appname = "armori.app";
let f = p.indexOf(appname);
console.log(f);
if (f !== -1) {
let o = path.join(p.slice(0, f + appname.length));
console.log(o);
return o;
}
//win/linux?
//TODO: check pathing
return path.join(app.getAppPath());
}
main();