2023-11-13 18:09:20 -05:00
|
|
|
const path = require("node:path");
|
2023-11-14 16:40:15 -05:00
|
|
|
const fs = require("node:fs");
|
|
|
|
const os = require("node:os");
|
2023-11-13 18:09:20 -05:00
|
|
|
|
|
|
|
const electron = require("electron");
|
|
|
|
|
2023-11-14 16:40:15 -05:00
|
|
|
const downloader = require("./lib/downloader.js");
|
|
|
|
const checker = require("./lib/checker.js");
|
|
|
|
|
|
|
|
let meta = JSON.parse(fs.readFileSync(path.join(__dirname, "meta.json"), "utf-8"));
|
|
|
|
let sources = JSON.parse(fs.readFileSync(path.join(__dirname, "sources.json"), "utf-8"));
|
|
|
|
|
|
|
|
let osPlatform = os.platform();
|
|
|
|
let userHome = os.homedir();
|
|
|
|
|
|
|
|
let gameDirectory;
|
|
|
|
switch (osPlatform) {
|
|
|
|
case "win32":
|
|
|
|
gameDirectory = path.join(userHome, "AppData", "Roaming", ...(meta["install_directory"]).split("/"));
|
|
|
|
break;
|
|
|
|
case "darwin":
|
|
|
|
gameDirectory = path.join(userHome, "Library", "Application Support", ...(meta["install_directory"]).split("/"));
|
|
|
|
break;
|
|
|
|
case "linux":
|
|
|
|
gameDirectory = path.join(userHome, ...(meta["install_directory"]).split("/"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gameDirectory = path.join(userHome, ...(meta["install_directory"]).split("/"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let window;
|
|
|
|
|
|
|
|
function showProgress(progress, ongoing, remaining, total) {
|
|
|
|
window.setProgressBar(progress);
|
|
|
|
|
|
|
|
window.webContents.send("event", {
|
|
|
|
"type": "download-progress",
|
|
|
|
"data": {
|
|
|
|
"ongoing": ongoing,
|
|
|
|
"remaining": remaining,
|
|
|
|
"total": total
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-13 18:09:20 -05:00
|
|
|
electron.app.on("ready", function () {
|
|
|
|
window = new electron.BrowserWindow({
|
|
|
|
"width": 960,
|
|
|
|
"height": 560,
|
|
|
|
"webPreferences": {
|
|
|
|
"nodeIntegration": true,
|
|
|
|
"contextIsolation": true,
|
|
|
|
"preload": path.join(__dirname, "preload.js")
|
|
|
|
},
|
|
|
|
"title": "OpenModLauncher",
|
|
|
|
"icon": path.join(__dirname, "res", "img", "logo.png"),
|
2023-11-14 16:40:15 -05:00
|
|
|
"frame": false,
|
2023-11-13 18:09:20 -05:00
|
|
|
"transparent": true,
|
|
|
|
"resizable": false,
|
|
|
|
"show": false
|
|
|
|
});
|
|
|
|
|
|
|
|
window.loadFile(path.join(__dirname, "views", "main.html"));
|
|
|
|
|
|
|
|
window.on("ready-to-show", window.show);
|
|
|
|
});
|
|
|
|
|
2023-11-14 16:40:15 -05:00
|
|
|
electron.ipcMain.handle("minimize", function (event) {
|
|
|
|
return window.minimize();
|
|
|
|
});
|
|
|
|
|
|
|
|
electron.ipcMain.handle("close", function (event) {
|
|
|
|
return window.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
electron.ipcMain.handle("is-installed", function (event) {
|
|
|
|
return checker.check_install(gameDirectory);
|
|
|
|
});
|
|
|
|
electron.ipcMain.handle("install", function (event) {
|
|
|
|
return downloader.download_minecraft(gameDirectory, meta["minecraft"], sources["minecraft"], showProgress);
|
|
|
|
});
|
|
|
|
|
2023-11-13 18:09:20 -05:00
|
|
|
electron.app.on("window-all-closed", function () {
|
|
|
|
electron.app.quit();
|
|
|
|
});
|