2021-09-21 13:32:06 -04:00
|
|
|
const { app, BrowserWindow, Menu, globalShortcut, shell } = require("electron");
|
2021-11-27 15:07:25 -05:00
|
|
|
const greenworks = require("./greenworks");
|
2021-09-21 13:29:16 -04:00
|
|
|
|
2021-11-27 15:07:25 -05:00
|
|
|
if (greenworks.init()) {
|
|
|
|
console.log("Steam API has been initialized.");
|
|
|
|
} else {
|
|
|
|
console.log("Steam API has failed to initialize.");
|
|
|
|
}
|
|
|
|
|
2021-11-28 23:51:01 -05:00
|
|
|
const debug = false;
|
2021-11-05 00:14:11 -04:00
|
|
|
|
2021-09-15 12:22:36 -04:00
|
|
|
Menu.setApplicationMenu(false);
|
|
|
|
function createWindow() {
|
|
|
|
const win = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
2021-11-05 00:14:11 -04:00
|
|
|
devTools: debug,
|
2021-09-15 12:22:36 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
win.removeMenu();
|
|
|
|
win.maximize();
|
|
|
|
win.loadFile("index.html");
|
|
|
|
win.show();
|
2021-11-05 00:19:41 -04:00
|
|
|
if (debug) win.webContents.openDevTools();
|
2021-09-21 13:29:16 -04:00
|
|
|
globalShortcut.register("f5", function () {
|
|
|
|
win.loadFile("index.html");
|
|
|
|
});
|
|
|
|
globalShortcut.register("f8", function () {
|
|
|
|
win.loadFile("index.html", { query: { noScripts: "true" } });
|
|
|
|
});
|
2021-09-21 13:32:06 -04:00
|
|
|
|
|
|
|
win.webContents.on("new-window", function (e, url) {
|
|
|
|
// make sure local urls stay in electron perimeter
|
2021-09-25 01:26:03 -04:00
|
|
|
if (url.substr(0, "file://".length) === "file://") {
|
2021-09-21 13:32:06 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and open every other protocols on the browser
|
|
|
|
e.preventDefault();
|
|
|
|
shell.openExternal(url);
|
|
|
|
});
|
2021-11-27 15:07:25 -05:00
|
|
|
|
2021-11-28 23:51:01 -05:00
|
|
|
// 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();
|
2021-11-27 15:07:25 -05:00
|
|
|
setInterval(async () => {
|
2021-11-28 23:51:01 -05:00
|
|
|
const achs = await win.webContents.executeJavaScript("document.achievements");
|
|
|
|
for (const ach of achs) {
|
|
|
|
if (!achievements.includes(ach)) continue;
|
|
|
|
greenworks.activateAchievement(ach, () => undefined);
|
|
|
|
}
|
2021-11-27 15:07:25 -05:00
|
|
|
}, 1000);
|
2021-09-15 12:22:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
createWindow();
|
|
|
|
});
|