From 03e7a5735a275ad5980640e2325f18c7c952b74b Mon Sep 17 00:00:00 2001 From: X3F200C Date: Fri, 8 Nov 2024 22:58:23 -0500 Subject: [PATCH] Create a basic ElectronJS app in src/main.js --- package.json | 2 +- src/main.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/main.js diff --git a/package.json b/package.json index abde8ad..7030e83 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-plutonium-launcher", "version": "0.0.1", "description": "A Plutonium launcher that aims to make old CoD games more accessible", - "main": "main.js", + "main": "src/main.js", "scripts": { "start": "electron ." }, diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..36f0867 --- /dev/null +++ b/src/main.js @@ -0,0 +1,54 @@ +const path = require("node:path"); +const fs = require("node:fs"); +const https = require("node:https"); +const process = require("node:process"); +const os = require("node:os"); +const child_process = require("node:child_process"); +const electron = require("electron"); + +let configFilePath; +switch (os.platform()) { + case "win32": + configFilePath = path.join(process.env["LOCALAPPDATA"], "Plutonium", "open-plutonium-launcher.json"); + break; + case "linux": + configFilePath = path.join(os.userInfo().homedir, ".config", "open-plutonium-launcher.json"); + break; + case "darwin": + configFilePath = path.join(os.userInfo().homedir, "Library", "Application Support", "open-plutonium-launcher.json"); + break; + default: + electron.dialog.showErrorBox("Incompatible system", "Sorry, your operating system doesn't seem to be supported..."); + process.exit(1); +} + +let mainWindow; + +function createMainWindow() { + mainWindow = new electron.BrowserWindow({ + "minWidth": 640, + "minHeight": 480, + "width": 800, + "height": 600, + "fullscreenable": false, + "show": false, + "webPreferences": { + "preload": path.join(__dirname, "preload.js"), + "contextIsolation": true + } + }); + + mainWindow.loadFile(path.join(__dirname, "index.html")); + + mainWindow.once("ready-to-show", function () { + mainWindow.show(); + }); +} + +electron.app.once("ready", function () { + createMainWindow(); +}); + +electron.app.on("window-all-closed", function () { + electron.app.quit(); +});