2021-12-12 18:48:42 +01:00
|
|
|
const { app, BrowserWindow, Menu, shell } = require("electron");
|
2021-11-27 21:07:25 +01:00
|
|
|
const greenworks = require("./greenworks");
|
2021-09-21 19:29:16 +02:00
|
|
|
|
2021-11-27 21:07:25 +01:00
|
|
|
if (greenworks.init()) {
|
|
|
|
console.log("Steam API has been initialized.");
|
|
|
|
} else {
|
|
|
|
console.log("Steam API has failed to initialize.");
|
|
|
|
}
|
|
|
|
|
2021-11-29 05:51:01 +01:00
|
|
|
const debug = false;
|
2021-11-05 05:14:11 +01:00
|
|
|
|
2021-09-15 18:22:36 +02:00
|
|
|
function createWindow() {
|
|
|
|
const win = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
win.removeMenu();
|
|
|
|
win.maximize();
|
|
|
|
win.loadFile("index.html");
|
|
|
|
win.show();
|
2021-11-05 05:19:41 +01:00
|
|
|
if (debug) win.webContents.openDevTools();
|
2021-09-21 19:32:06 +02:00
|
|
|
|
|
|
|
win.webContents.on("new-window", function (e, url) {
|
|
|
|
// make sure local urls stay in electron perimeter
|
2021-09-25 07:26:03 +02:00
|
|
|
if (url.substr(0, "file://".length) === "file://") {
|
2021-09-21 19:32:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and open every other protocols on the browser
|
|
|
|
e.preventDefault();
|
|
|
|
shell.openExternal(url);
|
|
|
|
});
|
2021-12-14 04:26:22 +01:00
|
|
|
win.webContents.backgroundThrottling = false;
|
|
|
|
|
|
|
|
// This is backward but the game fills in an array called `document.achievements` and we retrieve it from
|
|
|
|
// here. Hey if it works it works.
|
|
|
|
const achievements = greenworks.getAchievementNames();
|
|
|
|
const intervalID = setInterval(async () => {
|
|
|
|
const achs = await win.webContents.executeJavaScript("document.achievements");
|
|
|
|
console.log(achs);
|
|
|
|
for (const ach of achs) {
|
|
|
|
if (!achievements.includes(ach)) continue;
|
|
|
|
greenworks.activateAchievement(ach, () => undefined);
|
|
|
|
}
|
|
|
|
}, 1000);
|
2021-11-27 21:07:25 +01:00
|
|
|
|
2021-12-03 00:42:30 +01:00
|
|
|
// Create the Application's main menu
|
|
|
|
Menu.setApplicationMenu(
|
|
|
|
Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: "Edit",
|
|
|
|
submenu: [
|
|
|
|
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
|
|
|
|
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
|
|
|
|
{ type: "separator" },
|
|
|
|
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
|
|
|
|
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
|
|
|
|
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
|
|
|
|
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" },
|
|
|
|
],
|
|
|
|
},
|
2021-12-12 18:48:42 +01:00
|
|
|
{
|
|
|
|
label: "reloads",
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: "reload",
|
|
|
|
accelerator: "f5",
|
|
|
|
click: () => {
|
|
|
|
win.loadFile("index.html");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "reload & kill all scripts",
|
|
|
|
click: () => {
|
2021-12-14 04:26:22 +01:00
|
|
|
if (intervalID) clearInterval(intervalID);
|
2021-12-12 18:48:42 +01:00
|
|
|
win.webContents.forcefullyCrashRenderer();
|
2021-12-14 04:26:22 +01:00
|
|
|
win.close();
|
|
|
|
createWindow();
|
2021-12-12 18:48:42 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-12-12 18:58:57 +01:00
|
|
|
{
|
|
|
|
label: "fullscreen",
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: "toggle",
|
|
|
|
accelerator: "f9",
|
|
|
|
click: (() => {
|
|
|
|
let full = false;
|
|
|
|
return () => {
|
|
|
|
full = !full;
|
|
|
|
win.setFullScreen(full);
|
|
|
|
};
|
|
|
|
})(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-12-12 19:25:28 +01:00
|
|
|
{
|
|
|
|
label: "debug",
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: "activate",
|
|
|
|
click: () => win.webContents.openDevTools(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-12-03 00:42:30 +01:00
|
|
|
]),
|
|
|
|
);
|
2021-09-15 18:22:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
createWindow();
|
|
|
|
});
|