mirror of
https://github.com/AltarikMC/Launcher
synced 2025-12-14 11:52:27 +00:00
Move to electron 28 and changed everything to ESM
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
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()
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user