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

add fix game launch button + prevent options from opening while game is running or launching + prevent sending more than 1 authentification form

This commit is contained in:
Quentin Legot 2021-05-15 17:11:57 +02:00
parent 2a5e8f7805
commit 0c865c0129
5 changed files with 49 additions and 6 deletions

View File

@ -12,6 +12,8 @@ const outputMinMem = document.querySelector('#outputMinMem')
const outputMaxMem = document.querySelector('#outputMaxMem') const outputMaxMem = document.querySelector('#outputMaxMem')
const totalMem = os.totalmem() / (1.049 * Math.pow(10, 6)) const totalMem = os.totalmem() / (1.049 * Math.pow(10, 6))
const sidebar = document.querySelector("#sidebar-content") const sidebar = document.querySelector("#sidebar-content")
const invalidateButton = document.querySelector("#invalidateData")
let gameLaunching = false
let selectedChapter = -1; let selectedChapter = -1;
@ -43,6 +45,7 @@ launchBtn.addEventListener("click", e => {
launchBtn.disabled = true launchBtn.disabled = true
localStorage.setItem("minMem", minMem.value) localStorage.setItem("minMem", minMem.value)
localStorage.setItem("maxMem", maxMem.value) localStorage.setItem("maxMem", maxMem.value)
gameLaunching = true
} else{ } else{
ipcRenderer.send('notification', { ipcRenderer.send('notification', {
title: "Erreur de lancement", title: "Erreur de lancement",
@ -57,7 +60,8 @@ document.querySelector("#web").addEventListener("click", e => {
}) })
document.querySelector("#options").addEventListener("click", e => { document.querySelector("#options").addEventListener("click", e => {
fullscreen.style.display = "block" if(!gameLaunching)
fullscreen.style.display = "block"
}) })
document.querySelector("#discord").addEventListener("click", e => { document.querySelector("#discord").addEventListener("click", e => {
@ -68,6 +72,17 @@ document.querySelector("#close").addEventListener("click", e => {
fullscreen.style.display = "none" fullscreen.style.display = "none"
}); });
invalidateButton.addEventListener("click", e => {
invalidateButton.disabled = true
invalidateButton.childNodes[0].nodeValue = "Opération en cours"
ipcRenderer.send('invalidateData')
})
ipcRenderer.on("invalidated", e => {
invalidateButton.disabled = false
invalidateButton.childNodes[0].nodeValue = "Supprimer et retélécharger les bibliothèques"
})
ipcRenderer.on("progress", (e, args) => { ipcRenderer.on("progress", (e, args) => {
progressBar.style.width = (args.task / Math.max(args.total, args.task)) * 100 + "%" progressBar.style.width = (args.task / Math.max(args.total, args.task)) * 100 + "%"
loadingMessage.innerHTML = "Téléchargement de " + args.type + ": " + args.task + " sur " + Math.max(args.total, args.task) loadingMessage.innerHTML = "Téléchargement de " + args.type + ": " + args.task + " sur " + Math.max(args.total, args.task)
@ -80,6 +95,7 @@ ipcRenderer.on("close", (e, args) => {
loadingMessage.innerHTML = "Chargement de Minecraft en cours..." loadingMessage.innerHTML = "Chargement de Minecraft en cours..."
progressBar.style.width = "0" progressBar.style.width = "0"
launchBtn.disabled = false launchBtn.disabled = false
gameLaunching = false
}) })
ipcRenderer.on('launch', (e, args) => { ipcRenderer.on('launch', (e, args) => {

View File

@ -1,9 +1,12 @@
user = document.querySelector('#nickname') const form = document.querySelector('#login-form')
password = document.querySelector('#password') const user = document.querySelector('#nickname')
const password = document.querySelector('#password')
document.querySelector('#login-form').addEventListener("submit", (e) => {
form.addEventListener("submit", (e) => {
e.preventDefault() e.preventDefault()
if(user.value){ form.disabled = true
if(user.value) {
ipcRenderer.send("login", { ipcRenderer.send("login", {
user: user.value, user: user.value,
pass: password.value pass: password.value
@ -16,3 +19,7 @@ document.querySelector('#login-form').addEventListener("submit", (e) => {
} }
}) })
ipcRenderer.on("loginError", event => {
form.disabled = false
})

View File

@ -28,6 +28,8 @@
<input type="range" min="1024" max="2048" step="128" value="1" class="slider" id="minMem"><br /> <input type="range" min="1024" max="2048" step="128" value="1" class="slider" id="minMem"><br />
<label for="maxMem">mémoire maximale : <span id="outputMaxMem"></span></label><br /> <label for="maxMem">mémoire maximale : <span id="outputMaxMem"></span></label><br />
<input type="range" min="1024" max="2048" step="128" value="1" class="slider" id="maxMem"><br /> <input type="range" min="1024" max="2048" step="128" value="1" class="slider" id="maxMem"><br />
<h4>Au secours, mon jeu ne démarre pas</h4>
<button id="invalidateData">Supprimer et retélécharger les bibliothèques</button>
</div> </div>
</div> </div>
<div id="content"> <div id="content">

View File

@ -64,6 +64,10 @@ ipcMain.on("login", (event, args) => {
minecraft.login(event, win, showNotification, args.user, args.pass) minecraft.login(event, win, showNotification, args.user, args.pass)
}) })
ipcMain.on("invalidateData", event => {
minecraft.invalidateData(event)
})
ipcMain.on("launch", (event, args) => { ipcMain.on("launch", (event, args) => {
minecraft.launch(event, showNotification, args) minecraft.launch(event, showNotification, args)
}) })

View File

@ -25,6 +25,7 @@ class Minecraft {
event.sender.send("nick", { name: v.name }) event.sender.send("nick", { name: v.name })
}) })
}).catch((err) => { }).catch((err) => {
event.sender.send("loginError")
logger.error(err) logger.error(err)
showNotification("Erreur de connexion") showNotification("Erreur de connexion")
}) })
@ -51,7 +52,7 @@ class Minecraft {
} }
}) })
this.launcher.on('debug', (e) => logger.info(`debug: ${e}`)); this.launcher.on('debug', (e) => logger.info(`debug: ${e}`));
// this.launcher.on('data', (e) => logger.info(`data: ${e}`)); this.launcher.on('data', (e) => logger.info(`data: ${e}`));
this.launcher.on('progress', (e) => { this.launcher.on('progress', (e) => {
event.sender.send("progress", e) event.sender.send("progress", e)
logger.info(`progress ${e.type} :${e.task} / ${e.total}`) logger.info(`progress ${e.type} :${e.task} / ${e.total}`)
@ -261,6 +262,19 @@ class Minecraft {
}) })
}) })
} }
invalidateData(event) {
const assets = join(this.minecraftpath, 'assets')
const librairies = join(this.minecraftpath,'libraries')
const natives = join(this.minecraftpath, 'natives')
if(fs.existsSync(assets))
fs.rmdirSync(assets, { recursive: true })
if(fs.existsSync(librairies))
fs.rmdirSync(librairies, { recursive: true })
if(fs.existsSync(natives))
fs.rmdirSync(natives, { recursive: true })
event.sender.send("invalidated")
}
} }
module.exports = new Minecraft module.exports = new Minecraft