4
0
mirror of https://github.com/AltarikMC/Launcher synced 2024-11-25 06:49:51 +01:00
Launcher/main.js

95 lines
2.1 KiB
JavaScript
Raw Normal View History

const { app, BrowserWindow, Menu, ipcMain, Notification } = require('electron')
const path = require('path')
const { Client, Authenticator } = require('minecraft-launcher-core')
const launcher = new Client();
const iconPath = path.join(__dirname, "icon.png");
let win = null
let auth = null
let Minecraftpath = "projet-secret"
let clientPackage = "https://www.dropbox.com/s/ww6a052nzzgojdm/modpack.zip?dl=1"
let version = "fabric-loader-0.10.8-1.16.4"
2020-12-05 21:08:32 +01:00
function createWindow () {
win = new BrowserWindow({
width: 1000,
2020-12-05 21:08:32 +01:00
height: 600,
icon: iconPath,
2020-12-05 21:08:32 +01:00
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
},
frame: false
})
Menu.setApplicationMenu(null)
win.loadFile('login.html')
2020-12-05 21:08:32 +01:00
}
app.whenReady().then(() => {
createWindow()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (win === null){
createWindow()
}
})
ipcMain.on("login", (event, args) => {
auth = Authenticator.getAuth(args.user, args.pass)
auth.then(v => {
win.loadFile('index.html')
setTimeout(() => {
event.sender.send("nick", {
name: v.name
})
}, 1000)
}).catch((err) => {
console.warn(err)
showNotification("Erreur de connexion")
})
})
function showNotification(title="", body="") {
const notification = {
title: title,
body: body
}
new Notification(notification).show()
}
ipcMain.on("notification", (event, args) => {
showNotification(args.title, args.body)
})
ipcMain.on("launch", (event, args) => {
let opts = {
clientPackage: clientPackage,
authorization: auth,
root: Minecraftpath,
//forge: fabricmc,
version: {
number: "1.16.4",
type: "release",
custom: version
},
memory: {
max: args.maxMem,
min: args.minMem
}
}
launcher.launch(opts)
launcher.on('debug', (e) => console.log(e));
launcher.on('data', (e) => console.log(e));
launcher.on('progress', (e) => console.log(e));
launcher.on('close', (e) => console.log(e));
})