From 9e20458ff668757c9aacb67f4766e00d6464759a Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 23 Nov 2023 23:30:26 +0100 Subject: [PATCH] Move to electron 28 and changed everything to ESM --- config.forge.js => config.forge.cjs | 98 +++++++++++----------- package.json | 9 +- src/server/install.js | 6 +- src/server/main.js | 126 ++++++++++++++++------------ src/server/menubar.js | 16 +--- src/server/minecraft.js | 34 ++++---- src/server/updater.js | 13 ++- yarn.lock | 77 ++++++++++++----- 8 files changed, 208 insertions(+), 171 deletions(-) rename config.forge.js => config.forge.cjs (96%) diff --git a/config.forge.js b/config.forge.cjs similarity index 96% rename from config.forge.js rename to config.forge.cjs index b031a66..8aeb989 100644 --- a/config.forge.js +++ b/config.forge.cjs @@ -1,49 +1,49 @@ -const path = require('path'); -const pkg = require('./package.json') - -module.exports = { - packagerConfig: { - packageName: "altarik-launcher", - name: "Altarik Launcher", - productName: "altarik-launcher", - icon: path.resolve(__dirname, 'icon.ico'), - asar: true, - }, - plugins: [ - { - name: '@electron-forge/plugin-auto-unpack-natives', - config: {} - } - ], - makers: [ - { - name: "@electron-forge/maker-squirrel", - platforms: ['darwin', 'win32'], - config: { - name: pkg.name, - iconUrl: path.resolve(__dirname, 'icon.ico'), - //loadingGif: path.resolve(__dirname, 'src/assets/loading.gif'), - setupIcon: path.resolve(__dirname, 'icon.ico'), - setupExe: `${pkg.name}-${pkg.version}-win32-x64.exe` - } - }, - { - name: '@electron-forge/maker-zip', - platforms: ['linux'] - } - ], - publishers: [ - { - name: '@electron-forge/publisher-github', - config: { - repository: { - owner: 'AltarikMC', - name: 'Launcher' - }, - preRelease: false, - draft: true, - tagPrefix: '' - } - } - ] -} +const path = require('path'); +const pkg = require('./package.json') + +module.exports = { + packagerConfig: { + packageName: "altarik-launcher", + name: "Altarik Launcher", + productName: "altarik-launcher", + icon: path.resolve(__dirname, 'icon.ico'), + asar: true, + }, + plugins: [ + { + name: '@electron-forge/plugin-auto-unpack-natives', + config: {} + } + ], + makers: [ + { + name: "@electron-forge/maker-squirrel", + platforms: ['darwin', 'win32'], + config: { + name: pkg.name, + iconUrl: path.resolve(__dirname, 'icon.ico'), + //loadingGif: path.resolve(__dirname, 'src/assets/loading.gif'), + setupIcon: path.resolve(__dirname, 'icon.ico'), + setupExe: `${pkg.name}-${pkg.version}-win32-x64.exe` + } + }, + { + name: '@electron-forge/maker-zip', + platforms: ['linux'] + } + ], + publishers: [ + { + name: '@electron-forge/publisher-github', + config: { + repository: { + owner: 'AltarikMC', + name: 'Launcher' + }, + preRelease: false, + draft: true, + tagPrefix: '' + } + } + ] +} diff --git a/package.json b/package.json index 1d2cf6d..30c97e6 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "version": "2.1.0", "description": "Altarik Launcher", "main": "src/server/main.js", + "type": "module", "homepage": "https://altarik.fr/", "private": true, "repository": "AltarikMC/Launcher", @@ -34,7 +35,7 @@ "@electron-forge/maker-zip": "^7.1.0", "@electron-forge/plugin-auto-unpack-natives": "^7.1.0", "@electron-forge/publisher-github": "^7.1.0", - "electron": "^27.1.0" + "electron": "beta" }, "dependencies": { "decompress": "^4.2.1", @@ -42,14 +43,14 @@ "electron-log": "^5.0.0", "electron-squirrel-startup": "^1.0.0", "extract-zip": "^2.0.1", - "hasha": "^5.2.2", + "hasha": "^6.0.0", "izitoast": "^1.4.0", "minecraft-launcher-core": "^3.17.3", "msmc": "^4.1.0", - "node-fetch": "^2.7.0", + "node-fetch": "^3.0.0", "vue": "^3.3.8" }, "config": { - "forge": "./config.forge.js" + "forge": "./config.forge.cjs" } } diff --git a/src/server/install.js b/src/server/install.js index 9dad38e..fc76f64 100644 --- a/src/server/install.js +++ b/src/server/install.js @@ -1,4 +1,4 @@ -function handleSquirrelEvent(app) { +export default function handleSquirrelEvent(app) { if (process.argv.length === 1) { return false; } @@ -45,7 +45,3 @@ function handleSquirrelEvent(app) { return true; } } - -module.exports = { - handleSquirrelEvent -} \ No newline at end of file diff --git a/src/server/main.js b/src/server/main.js index 8f2ac01..c2076f6 100644 --- a/src/server/main.js +++ b/src/server/main.js @@ -1,19 +1,27 @@ -const { app, BrowserWindow, Menu, ipcMain, autoUpdater, dialog } = require('electron') -const logger = require('electron-log') -const { join } = require('path') -const updater = require('./updater.js') -let updaterInstance = new updater.Updater(app, autoUpdater, dialog, logger, showNotification) +import { app, BrowserWindow, Menu, ipcMain, autoUpdater, dialog } from 'electron' +import logger from 'electron-log' +import { join } from 'path' +import updater from './updater.js' +import electronStartup from 'electron-squirrel-startup' +import install from "./install.js" +import mc from './minecraft.js' +import { minimizeWindow, closeWindow } from "./menubar.js"; + +import { fileURLToPath } from 'url' +import { dirname } from 'path' + + +let updaterInstance = new updater(app, autoUpdater, dialog, logger, showNotification) updaterInstance.configUpdater() -if (require('electron-squirrel-startup')) { - require("./install.js").handleSquirrelEvent(app) - app.quit() - return -} -const minecraft = require('./minecraft.js') +let minecraft = new mc() minecraft.showNotification = showNotification + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) const iconPath = join(__dirname, "icon.ico") + let win = null function createWindow () { @@ -35,49 +43,6 @@ function createWindow () { }) } -const { setWindow, minimizeWindow, closeWindow } = require("./menubar.js"); - -app.whenReady().then(() => { - createWindow() - setWindow(win) -}) - -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() - } -}) - -ipcMain.on('minimizeWindow', () => { - minimizeWindow(win) -}) - -ipcMain.on('closeWindow', () => { - closeWindow(win) -}) - -app.on('activate', () => { - if (win === null){ - createWindow() - } -}) - -ipcMain.on("login", (event, args) => { - minecraft.login(event, win, args.user, args.pass) -}) - -ipcMain.on("microsoft-login", (event) => { - minecraft.microsoftLogin(event, win) -}) - -ipcMain.on("invalidateData", event => { - minecraft.invalidateData(event) -}) - -ipcMain.on("launch", (event, args) => { - minecraft.launch(event, args) -}) - function showNotification(title, body="", clazz="info") { win.webContents.send('notification', {title: title, body: body, class: clazz}) } @@ -95,4 +60,55 @@ ipcMain.on("pageReady", (event) => { ipcMain.on("checking-update", () => { updaterInstance.checkForUpdates(win, showNotification) -}) \ No newline at end of file +}) + +function main() { + if (electronStartup) { + install.handleSquirrelEvent(app) + app.quit() + return + } + + app.whenReady().then(() => { + createWindow() + }) + + app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { + app.quit() + } + }) + + ipcMain.on('minimizeWindow', () => { + minimizeWindow(win) + }) + + ipcMain.on('closeWindow', () => { + closeWindow(win) + }) + + app.on('activate', () => { + if (win === null){ + createWindow() + } + }) + + ipcMain.on("login", (event, args) => { + minecraft.login(event, win, args.user, args.pass) + }) + + ipcMain.on("microsoft-login", (event) => { + minecraft.microsoftLogin(event, win) + }) + + ipcMain.on("invalidateData", event => { + minecraft.invalidateData(event) + }) + + ipcMain.on("launch", (event, args) => { + minecraft.launch(event, args) + }) + +} + +main() \ No newline at end of file diff --git a/src/server/menubar.js b/src/server/menubar.js index c782648..7af003c 100644 --- a/src/server/menubar.js +++ b/src/server/menubar.js @@ -1,21 +1,9 @@ -let win; - -function setWindow(browserWindow) { - win = browserWindow; -} - -function minimizeWindow(browserWindow = win) { +export function minimizeWindow(browserWindow) { if(browserWindow.minimizable) { browserWindow.minimize() } } -function closeWindow(browserWindow = win) { +export function closeWindow(browserWindow) { browserWindow.close() } - -module.exports = { - setWindow, - minimizeWindow, - closeWindow -} \ No newline at end of file diff --git a/src/server/minecraft.js b/src/server/minecraft.js index af09558..062f16b 100644 --- a/src/server/minecraft.js +++ b/src/server/minecraft.js @@ -1,18 +1,20 @@ -const isDev = require("electron-is-dev") -const { Authenticator, Client } = require("minecraft-launcher-core") -const fetch = require("node-fetch").default -const hasha = require("hasha") -const fs = require("fs") -const { join } = require("path") -const constants = require("constants") -const zip = require("extract-zip") -const logger = require("electron-log") -const { Auth, lst } = require("msmc") -const decompress = require("decompress") -const decompressTar = require("decompress-targz") +import isDev from "electron-is-dev" +import mlc from "minecraft-launcher-core" +import fetch from "node-fetch" +import { hashFile } from "hasha" +import fs from "fs" +import { join } from "path" +import constants from "constants" +import zip from "extract-zip" +import logger from "electron-log" +import { Auth, lst } from "msmc" +import decompress from "decompress" +import decompressTar from "decompress-targz" + +const { Authenticator, Client } = mlc -class Minecraft { +export default class Minecraft { appdata = process.env.APPDATA || (process.platform === "darwin" ? process.env.HOME + "/Library/Preferences" : process.env.HOME + "/.local/share") localappdata = process.env.LOCALAPPDATA || (process.platform === "darwin" ? process.env.HOME + "/Library/Application Support/" : process.env.HOME + "/.config") @@ -205,7 +207,7 @@ class Minecraft { const path = join(modpackFolder, `modpack${j}.zip`) try { fs.accessSync(path, constants.W_OK) - let sha1 = await hasha.fromFile(path, {algorithm: "sha1"}) + let sha1 = await hashFile(path, {algorithm: "sha1"}) if(sha1 === chapter.modspack.sha1sum[j]) { await this.unzipMods(path).catch(err => { reject(err) @@ -316,7 +318,7 @@ class Minecraft { if(!fs.existsSync(downloadFolder)) fs.mkdirSync(downloadFolder, { recursive: true }) if(fs.existsSync(downloadFile)) { - let sha1 = await hasha.fromFile(downloadFile, {algorithm: "sha256"}) + let sha1 = await hashFile(downloadFile, {algorithm: "sha256"}) if(sha1 === infos.sha256sum) { await this.extractJavaArchive(downloadFile, runtime) let filename = process.platform == "win32" ? "java.exe" : "java" @@ -381,5 +383,3 @@ class Minecraft { event.sender.send("invalidated") } } - -module.exports = new Minecraft \ No newline at end of file diff --git a/src/server/updater.js b/src/server/updater.js index 8c7dc3b..d97dc2d 100644 --- a/src/server/updater.js +++ b/src/server/updater.js @@ -1,9 +1,10 @@ -const isDev = require('electron-is-dev') -const fetch = require('node-fetch').default -const pkg = require('../../package.json') +import isDev from 'electron-is-dev' +import fetch from 'node-fetch' +import pkg from "../../package.json" assert { type: "json" } + const server = 'https://update.electronjs.org' -class Updater { +export default class Updater { constructor(app, autoUpdater, dialog, logger, ipcMain) { this.app = app @@ -95,7 +96,3 @@ class Updater { } } - -module.exports = { - Updater -} diff --git a/yarn.lock b/yarn.lock index 32babdf..dd7bc97 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1177,6 +1177,11 @@ dashdash@^1.12.0: dependencies: assert-plus "^1.0.0" +data-uri-to-buffer@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e" + integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A== + debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.3, debug@^4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" @@ -1347,10 +1352,10 @@ electron-winstaller@^5.0.0: lodash.template "^4.2.2" temp "^0.9.0" -electron@^27.1.0: - version "27.1.0" - resolved "https://registry.yarnpkg.com/electron/-/electron-27.1.0.tgz#d759885e552d7d926526cfc433ab312796f74a9a" - integrity sha512-XPdJiO475QJ8cx59/goWNNWnlV0vab+Ut3occymos7VDxkHV5mFrlW6tcGi+M3bW6gBfwpJocWMng8tw542vww== +electron@beta: + version "28.0.0-beta.9" + resolved "https://registry.yarnpkg.com/electron/-/electron-28.0.0-beta.9.tgz#cc847b6dc872f6b00accae4729476f6323cf4ea9" + integrity sha512-9e42Qo77EQAhEkzgibhXR7Il6OwE8LCzfS2ELXak/66W9DB+oziXCGux/2Bi2iLkotbB5qJeuLD5/cZYOrHzuA== dependencies: "@electron/get" "^2.0.0" "@types/node" "^18.11.18" @@ -1503,6 +1508,14 @@ fd-slicer@~1.1.0: dependencies: pend "~1.2.0" +fetch-blob@^3.1.2, fetch-blob@^3.1.4: + version "3.2.0" + resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9" + integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ== + dependencies: + node-domexception "^1.0.0" + web-streams-polyfill "^3.0.3" + file-type@^3.8.0: version "3.9.0" resolved "https://registry.yarnpkg.com/file-type/-/file-type-3.9.0.tgz#257a078384d1db8087bc449d107d52a52672b9e9" @@ -1584,6 +1597,13 @@ form-data@~2.3.2: combined-stream "^1.0.6" mime-types "^2.1.12" +formdata-polyfill@^4.0.10: + version "4.0.10" + resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423" + integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g== + dependencies: + fetch-blob "^3.1.2" + fs-constants@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" @@ -1883,13 +1903,13 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" -hasha@^5.2.2: - version "5.2.2" - resolved "https://registry.yarnpkg.com/hasha/-/hasha-5.2.2.tgz#a48477989b3b327aea3c04f53096d816d97522a1" - integrity sha512-Hrp5vIK/xr5SkeN2onO32H0MgNZ0f17HRNH39WfL0SYUNOTZ5Lz1TJ8Pajo/87dYGEFlLMm7mIc/k/s6Bvz9HQ== +hasha@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/hasha/-/hasha-6.0.0.tgz#bdf1231ae40b406121c09c13705e5b38c1bb607c" + integrity sha512-MLydoyGp9QJcjlhE5lsLHXYpWayjjWqkavzju2ZWD2tYa1CgmML1K1gWAu22BLFa2eZ0OfvJ/DlfoVjaD54U2Q== dependencies: - is-stream "^2.0.0" - type-fest "^0.8.0" + is-stream "^3.0.0" + type-fest "^4.7.1" homedir-polyfill@^1.0.1: version "1.0.3" @@ -2075,10 +2095,10 @@ is-stream@^1.1.0: resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= -is-stream@^2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077" - integrity sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg== +is-stream@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-3.0.0.tgz#e6bfd7aa6bef69f4f472ce9bb681e3e57b4319ac" + integrity sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA== is-typedarray@~1.0.0: version "1.0.0" @@ -2575,13 +2595,27 @@ node-api-version@^0.1.4: dependencies: semver "^7.3.5" -node-fetch@2.x, node-fetch@^2.6.7, node-fetch@^2.7.0: +node-domexception@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" + integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== + +node-fetch@2.x, node-fetch@^2.6.7: version "2.7.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== dependencies: whatwg-url "^5.0.0" +node-fetch@^3.0.0: + version "3.3.2" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.2.tgz#d1e889bacdf733b4ff3b2b243eb7a12866a0b78b" + integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA== + dependencies: + data-uri-to-buffer "^4.0.0" + fetch-blob "^3.1.4" + formdata-polyfill "^4.0.10" + node-gyp-build@^4.2.1: version "4.4.0" resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.4.0.tgz#42e99687ce87ddeaf3a10b99dc06abc11021f3f4" @@ -3573,10 +3607,10 @@ type-fest@^0.21.3: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -type-fest@^0.8.0: - version "0.8.1" - resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" - integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== +type-fest@^4.7.1: + version "4.8.2" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.8.2.tgz#20d4cc287745723dbabf925de644eeb7de0349c1" + integrity sha512-mcvrCjixA5166hSrUoJgGb9gBQN4loMYyj9zxuMs/66ibHNEFd5JXMw37YVDx58L4/QID9jIzdTBB4mDwDJ6KQ== unbzip2-stream@^1.0.9: version "1.4.3" @@ -3680,6 +3714,11 @@ wcwidth@^1.0.1: dependencies: defaults "^1.0.3" +web-streams-polyfill@^3.0.3: + version "3.2.1" + resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" + integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q== + webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"