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

75 lines
2.7 KiB
JavaScript
Raw Normal View History

var os = require('os');
2020-12-08 23:04:57 +01:00
let launchBtn = document.querySelector('#launch-btn');
let fullProgressBar = document.querySelector('#fullprogressbar')
let progressBar = document.querySelector('#progressbar')
let loadingMessage = document.querySelector('#loading-message')
2020-12-08 23:19:42 +01:00
let disconnectBtn = document.querySelector('#disconnect-btn')
let minMem = document.querySelector('#minMem')
let maxMem = document.querySelector('#maxMem')
let outputMinMem = document.querySelector('#outputMinMem')
let outputMaxMem = document.querySelector('#outputMaxMem')
let totalMem = os.totalmem() / (1.049 * Math.pow(10, 6))
ipcRenderer.on("nick", (event, args) => {
console.log(args)
document.querySelector("#nick-span").innerHTML = args.name
})
2020-12-08 23:04:57 +01:00
launchBtn.addEventListener("click", e => {
launchBtn.classList.add('hidden');
fullProgressBar.classList.remove('hidden');
loadingMessage.classList.remove('hidden');
if(Number(minMem.value) <= Number(maxMem.value)){
ipcRenderer.send('launch', {
minMem: minMem.value + "M",
maxMem: maxMem.value + "M"
})
launchBtn.disabled = true
if(minMem.value && maxMem.value){
localStorage.setItem("minMem", minMem.value)
localStorage.setItem("maxMem", maxMem.value)
}
} else{
ipcRenderer.send('notification', {
title: "Erreur de lancement",
body: "La mémoire minimale doit être inférieure ou égale à la mémoire maximale"
})
}
2020-12-08 23:04:57 +01:00
})
ipcRenderer.on("progress", (e, args) => {
progressBar.style.width = (args.task / args.total) * 100 + "%"
loadingMessage.innerHTML = "Téléchargement de " + args.type + ": " + args.task + " sur " + args.total;
})
ipcRenderer.on("close", (e, args) => {
launchBtn.classList.remove('hidden');
fullProgressBar.classList.add('hidden');
loadingMessage.classList.add('hidden');
loadingMessage.innerHTML = "Téléchargement de Minecraft en cours..."
progressBar.style.width = "0"
launchBtn.disabled = false
2020-12-08 23:19:42 +01:00
})
disconnectBtn.addEventListener('click', e => {
ipcRenderer.send('disconnect')
})
window.addEventListener("DOMContentLoaded", () => {
minMem.value = localStorage.getItem("minMem") != null ? Number(localStorage.getItem("minMem")) : 1024
minMem.max = totalMem
outputMinMem.innerHTML = minMem.value
maxMem.value = localStorage.getItem("maxMem") != null ? Number(localStorage.getItem("maxMem")) : 2048
maxMem.max = totalMem
outputMaxMem.innerHTML = maxMem.value
})
minMem.addEventListener("input", (e) => {
outputMinMem.innerHTML = e.target.value
})
maxMem.addEventListener("input", (e) => {
outputMaxMem.innerHTML = e.target.value
})