87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
const path = require("node:path");
|
|
const fs = require("node:fs");
|
|
const os = require("node:os");
|
|
|
|
const electron = require("electron");
|
|
|
|
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
|
|
}
|
|
});
|
|
}
|
|
|
|
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"),
|
|
"frame": false,
|
|
"transparent": true,
|
|
"resizable": false,
|
|
"show": false
|
|
});
|
|
|
|
window.loadFile(path.join(__dirname, "views", "main.html"));
|
|
|
|
window.on("ready-to-show", window.show);
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
electron.app.on("window-all-closed", function () {
|
|
electron.app.quit();
|
|
});
|