4
0
mirror of https://github.com/AltarikMC/Launcher synced 2024-11-24 06:39:50 +01:00

Move to electron 28 and changed everything to ESM

This commit is contained in:
Quentin Legot 2023-11-23 23:30:26 +01:00
parent ebf00f0596
commit 9e20458ff6
8 changed files with 208 additions and 171 deletions

View File

@ -4,6 +4,7 @@
"version": "2.1.0", "version": "2.1.0",
"description": "Altarik Launcher", "description": "Altarik Launcher",
"main": "src/server/main.js", "main": "src/server/main.js",
"type": "module",
"homepage": "https://altarik.fr/", "homepage": "https://altarik.fr/",
"private": true, "private": true,
"repository": "AltarikMC/Launcher", "repository": "AltarikMC/Launcher",
@ -34,7 +35,7 @@
"@electron-forge/maker-zip": "^7.1.0", "@electron-forge/maker-zip": "^7.1.0",
"@electron-forge/plugin-auto-unpack-natives": "^7.1.0", "@electron-forge/plugin-auto-unpack-natives": "^7.1.0",
"@electron-forge/publisher-github": "^7.1.0", "@electron-forge/publisher-github": "^7.1.0",
"electron": "^27.1.0" "electron": "beta"
}, },
"dependencies": { "dependencies": {
"decompress": "^4.2.1", "decompress": "^4.2.1",
@ -42,14 +43,14 @@
"electron-log": "^5.0.0", "electron-log": "^5.0.0",
"electron-squirrel-startup": "^1.0.0", "electron-squirrel-startup": "^1.0.0",
"extract-zip": "^2.0.1", "extract-zip": "^2.0.1",
"hasha": "^5.2.2", "hasha": "^6.0.0",
"izitoast": "^1.4.0", "izitoast": "^1.4.0",
"minecraft-launcher-core": "^3.17.3", "minecraft-launcher-core": "^3.17.3",
"msmc": "^4.1.0", "msmc": "^4.1.0",
"node-fetch": "^2.7.0", "node-fetch": "^3.0.0",
"vue": "^3.3.8" "vue": "^3.3.8"
}, },
"config": { "config": {
"forge": "./config.forge.js" "forge": "./config.forge.cjs"
} }
} }

View File

@ -1,4 +1,4 @@
function handleSquirrelEvent(app) { export default function handleSquirrelEvent(app) {
if (process.argv.length === 1) { if (process.argv.length === 1) {
return false; return false;
} }
@ -45,7 +45,3 @@ function handleSquirrelEvent(app) {
return true; return true;
} }
} }
module.exports = {
handleSquirrelEvent
}

View File

@ -1,19 +1,27 @@
const { app, BrowserWindow, Menu, ipcMain, autoUpdater, dialog } = require('electron') import { app, BrowserWindow, Menu, ipcMain, autoUpdater, dialog } from 'electron'
const logger = require('electron-log') import logger from 'electron-log'
const { join } = require('path') import { join } from 'path'
const updater = require('./updater.js') import updater from './updater.js'
let updaterInstance = new updater.Updater(app, autoUpdater, dialog, logger, showNotification) 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() updaterInstance.configUpdater()
if (require('electron-squirrel-startup')) { let minecraft = new mc()
require("./install.js").handleSquirrelEvent(app)
app.quit()
return
}
const minecraft = require('./minecraft.js')
minecraft.showNotification = showNotification minecraft.showNotification = showNotification
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const iconPath = join(__dirname, "icon.ico") const iconPath = join(__dirname, "icon.ico")
let win = null let win = null
function createWindow () { 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") { function showNotification(title, body="", clazz="info") {
win.webContents.send('notification', {title: title, body: body, class: clazz}) win.webContents.send('notification', {title: title, body: body, class: clazz})
} }
@ -96,3 +61,54 @@ ipcMain.on("pageReady", (event) => {
ipcMain.on("checking-update", () => { ipcMain.on("checking-update", () => {
updaterInstance.checkForUpdates(win, showNotification) updaterInstance.checkForUpdates(win, showNotification)
}) })
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()

View File

@ -1,21 +1,9 @@
let win; export function minimizeWindow(browserWindow) {
function setWindow(browserWindow) {
win = browserWindow;
}
function minimizeWindow(browserWindow = win) {
if(browserWindow.minimizable) { if(browserWindow.minimizable) {
browserWindow.minimize() browserWindow.minimize()
} }
} }
function closeWindow(browserWindow = win) { export function closeWindow(browserWindow) {
browserWindow.close() browserWindow.close()
} }
module.exports = {
setWindow,
minimizeWindow,
closeWindow
}

View File

@ -1,18 +1,20 @@
const isDev = require("electron-is-dev") import isDev from "electron-is-dev"
const { Authenticator, Client } = require("minecraft-launcher-core") import mlc from "minecraft-launcher-core"
const fetch = require("node-fetch").default import fetch from "node-fetch"
const hasha = require("hasha") import { hashFile } from "hasha"
const fs = require("fs") import fs from "fs"
const { join } = require("path") import { join } from "path"
const constants = require("constants") import constants from "constants"
const zip = require("extract-zip") import zip from "extract-zip"
const logger = require("electron-log") import logger from "electron-log"
const { Auth, lst } = require("msmc") import { Auth, lst } from "msmc"
const decompress = require("decompress") import decompress from "decompress"
const decompressTar = require("decompress-targz") 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") 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") 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`) const path = join(modpackFolder, `modpack${j}.zip`)
try { try {
fs.accessSync(path, constants.W_OK) 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]) { if(sha1 === chapter.modspack.sha1sum[j]) {
await this.unzipMods(path).catch(err => { await this.unzipMods(path).catch(err => {
reject(err) reject(err)
@ -316,7 +318,7 @@ class Minecraft {
if(!fs.existsSync(downloadFolder)) if(!fs.existsSync(downloadFolder))
fs.mkdirSync(downloadFolder, { recursive: true }) fs.mkdirSync(downloadFolder, { recursive: true })
if(fs.existsSync(downloadFile)) { if(fs.existsSync(downloadFile)) {
let sha1 = await hasha.fromFile(downloadFile, {algorithm: "sha256"}) let sha1 = await hashFile(downloadFile, {algorithm: "sha256"})
if(sha1 === infos.sha256sum) { if(sha1 === infos.sha256sum) {
await this.extractJavaArchive(downloadFile, runtime) await this.extractJavaArchive(downloadFile, runtime)
let filename = process.platform == "win32" ? "java.exe" : "java" let filename = process.platform == "win32" ? "java.exe" : "java"
@ -381,5 +383,3 @@ class Minecraft {
event.sender.send("invalidated") event.sender.send("invalidated")
} }
} }
module.exports = new Minecraft

View File

@ -1,9 +1,10 @@
const isDev = require('electron-is-dev') import isDev from 'electron-is-dev'
const fetch = require('node-fetch').default import fetch from 'node-fetch'
const pkg = require('../../package.json') import pkg from "../../package.json" assert { type: "json" }
const server = 'https://update.electronjs.org' const server = 'https://update.electronjs.org'
class Updater { export default class Updater {
constructor(app, autoUpdater, dialog, logger, ipcMain) { constructor(app, autoUpdater, dialog, logger, ipcMain) {
this.app = app this.app = app
@ -95,7 +96,3 @@ class Updater {
} }
} }
module.exports = {
Updater
}

View File

@ -1177,6 +1177,11 @@ dashdash@^1.12.0:
dependencies: dependencies:
assert-plus "^1.0.0" 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: 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" version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" 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" lodash.template "^4.2.2"
temp "^0.9.0" temp "^0.9.0"
electron@^27.1.0: electron@beta:
version "27.1.0" version "28.0.0-beta.9"
resolved "https://registry.yarnpkg.com/electron/-/electron-27.1.0.tgz#d759885e552d7d926526cfc433ab312796f74a9a" resolved "https://registry.yarnpkg.com/electron/-/electron-28.0.0-beta.9.tgz#cc847b6dc872f6b00accae4729476f6323cf4ea9"
integrity sha512-XPdJiO475QJ8cx59/goWNNWnlV0vab+Ut3occymos7VDxkHV5mFrlW6tcGi+M3bW6gBfwpJocWMng8tw542vww== integrity sha512-9e42Qo77EQAhEkzgibhXR7Il6OwE8LCzfS2ELXak/66W9DB+oziXCGux/2Bi2iLkotbB5qJeuLD5/cZYOrHzuA==
dependencies: dependencies:
"@electron/get" "^2.0.0" "@electron/get" "^2.0.0"
"@types/node" "^18.11.18" "@types/node" "^18.11.18"
@ -1503,6 +1508,14 @@ fd-slicer@~1.1.0:
dependencies: dependencies:
pend "~1.2.0" 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: file-type@^3.8.0:
version "3.9.0" version "3.9.0"
resolved "https://registry.yarnpkg.com/file-type/-/file-type-3.9.0.tgz#257a078384d1db8087bc449d107d52a52672b9e9" 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" combined-stream "^1.0.6"
mime-types "^2.1.12" 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: fs-constants@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
@ -1883,13 +1903,13 @@ has@^1.0.3:
dependencies: dependencies:
function-bind "^1.1.1" function-bind "^1.1.1"
hasha@^5.2.2: hasha@^6.0.0:
version "5.2.2" version "6.0.0"
resolved "https://registry.yarnpkg.com/hasha/-/hasha-5.2.2.tgz#a48477989b3b327aea3c04f53096d816d97522a1" resolved "https://registry.yarnpkg.com/hasha/-/hasha-6.0.0.tgz#bdf1231ae40b406121c09c13705e5b38c1bb607c"
integrity sha512-Hrp5vIK/xr5SkeN2onO32H0MgNZ0f17HRNH39WfL0SYUNOTZ5Lz1TJ8Pajo/87dYGEFlLMm7mIc/k/s6Bvz9HQ== integrity sha512-MLydoyGp9QJcjlhE5lsLHXYpWayjjWqkavzju2ZWD2tYa1CgmML1K1gWAu22BLFa2eZ0OfvJ/DlfoVjaD54U2Q==
dependencies: dependencies:
is-stream "^2.0.0" is-stream "^3.0.0"
type-fest "^0.8.0" type-fest "^4.7.1"
homedir-polyfill@^1.0.1: homedir-polyfill@^1.0.1:
version "1.0.3" 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" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ=
is-stream@^2.0.0: is-stream@^3.0.0:
version "2.0.1" version "3.0.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-3.0.0.tgz#e6bfd7aa6bef69f4f472ce9bb681e3e57b4319ac"
integrity sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg== integrity sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==
is-typedarray@~1.0.0: is-typedarray@~1.0.0:
version "1.0.0" version "1.0.0"
@ -2575,13 +2595,27 @@ node-api-version@^0.1.4:
dependencies: dependencies:
semver "^7.3.5" 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" version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies: dependencies:
whatwg-url "^5.0.0" 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: node-gyp-build@^4.2.1:
version "4.4.0" version "4.4.0"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.4.0.tgz#42e99687ce87ddeaf3a10b99dc06abc11021f3f4" 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" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37"
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==
type-fest@^0.8.0: type-fest@^4.7.1:
version "0.8.1" version "4.8.2"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.8.2.tgz#20d4cc287745723dbabf925de644eeb7de0349c1"
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== integrity sha512-mcvrCjixA5166hSrUoJgGb9gBQN4loMYyj9zxuMs/66ibHNEFd5JXMw37YVDx58L4/QID9jIzdTBB4mDwDJ6KQ==
unbzip2-stream@^1.0.9: unbzip2-stream@^1.0.9:
version "1.4.3" version "1.4.3"
@ -3680,6 +3714,11 @@ wcwidth@^1.0.1:
dependencies: dependencies:
defaults "^1.0.3" 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: webidl-conversions@^3.0.0:
version "3.0.1" version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"