This repository has been archived by the owner on Oct 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
103 lines (87 loc) · 2.79 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
const {ipcMain, app, BrowserWindow} = require("electron");
const path = require("path");
const url = require("url");
const DEBUG = false;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let main_window,
game_window;
let createWindow = function() {
// Create the browser window.
main_window = new BrowserWindow({
width: 800,
height: 800,
minWidth: 800,
minHeight: 800,
useContentSize: true,
webPreferences: {
experimentalFeatures: true
},
show: false,
resizable: true,
fullscreen: false,
fullscreenable: false,
maximizable: true,
autoHideMenuBar: true
});
// and load the index.html of the app.
main_window.loadURL(url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
}));
if(DEBUG) main_window.webContents.openDevTools();
main_window.once("ready-to-show", () => { main_window.show(); });
main_window.on("closed", () => {
main_window = null;
app.quit();
});
main_window.setMenu(null);
ipcMain.on("run-game", (event, arg) => {
if(game_window == null) {
game_window = new BrowserWindow({
width: 800,
height: 608,
minWidth: 800,
minHeight: 608,
useContentSize: true,
webPreferences: {
experimentalFeatures: true
},
show: false,
resizable: true,
fullscreen: false,
fullscreenable: true,
maximizable: true,
autoHideMenuBar: true
});
game_window.on("closed", () => {
game_window = null;
});
game_window.once("ready-to-show", () => {
game_window.show();
game_window.focus();
game_window.webContents.send("tape-and-code", arg);
if(DEBUG) game_window.webContents.openDevTools();
});
game_window.loadURL(url.format({
pathname: path.join(__dirname, "game.html"),
protocol: "file:",
slashes: true
}));
event.returnValue = "sent";
} else {
game_window.webContents.send("tape-and-code", arg);
game_window.focus();
}
});
}
app.commandLine.appendSwitch("enable-webassembly");
app.on("ready", createWindow);
// Quit when all windows are closed.
app.on("window-all-closed", () => { app.quit(); });
app.on("activate", () => {
if (main_window === null) {
createWindow();
}
});