-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
97 lines (85 loc) · 2.46 KB
/
index.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
const { app, BrowserWindow } = require("electron");
const path = require("path");
const fs = require("fs");
const configYaml = require("config-yaml");
const isDev = require("electron-is-dev");
// Enable auto-reload in development if set
try {
if (isDev && process.env.AUTO_RELOAD) require('electron-reloader')(module);
} catch {}
function getCurrentDirectory() {
let currentDirectory;
if (process.argv.length >= 3) {
currentDirectory = path.normalize(process.argv[2]);
} else if (isDev) {
currentDirectory = path.resolve(app.getAppPath(), "dev-env");
} else if (process.env.PORTABLE_EXECUTABLE_DIR) {
currentDirectory = process.env.PORTABLE_EXECUTABLE_DIR;
} else if (process.env.INIT_CWD) {
currentDirectory = process.env.INIT_CWD;
} else if (app.getPath("exe")) {
currentDirectory = path.dirname(app.getPath("exe"));
} else if (process.execPath) {
currentDirectory = process.execPath;
}
if (path.basename(currentDirectory) === "MacOS") {
currentDirectory = path.resolve(currentDirectory, "..", "..", "..");
}
return currentDirectory;
}
function createWindow() {
let width = 1024;
let height = 576;
let fullscreen = false;
let frame = false;
try {
const currentDirectory = getCurrentDirectory();
const jsonFilePath = path.resolve(currentDirectory, "quick-versus.json");
const yamlFilePath = path.resolve(currentDirectory, "quick-versus.yml");
let config;
if (fs.existsSync(jsonFilePath)) {
config = require(jsonFilePath);
} else if (fs.existsSync(yamlFilePath)) {
config = configYaml(yamlFilePath);
}
if (config) {
if (config.hasOwnProperty("width")) {
width = config.width;
}
if (config.hasOwnProperty("height")) {
height = config.height;
}
if (config.hasOwnProperty("fullscreen")) {
fullscreen = config.fullscreen;
}
if (config.hasOwnProperty("frame")) {
frame = config.frame;
}
}
} catch (error) {
// No override
}
const window = new BrowserWindow({
title: "Quick Versus Launcher",
backgroundColor: "#333333",
frame,
width,
height,
fullscreen,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
},
webSecurity: false
});
window.loadFile("build/index.html");
// window.webContents.openDevTools();
}
app.on("window-all-closed", () => {
app.quit();
});
async function start() {
await app.whenReady();
createWindow();
}
start();