diff --git a/src/client/assets/js/index.js b/src/client/assets/js/index.js index 5922650..8e07644 100644 --- a/src/client/assets/js/index.js +++ b/src/client/assets/js/index.js @@ -12,6 +12,8 @@ const outputMinMem = document.querySelector('#outputMinMem') const outputMaxMem = document.querySelector('#outputMaxMem') const totalMem = os.totalmem() / (1.049 * Math.pow(10, 6)) const sidebar = document.querySelector("#sidebar-content") +const invalidateButton = document.querySelector("#invalidateData") +let gameLaunching = false let selectedChapter = -1; @@ -43,6 +45,7 @@ launchBtn.addEventListener("click", e => { launchBtn.disabled = true localStorage.setItem("minMem", minMem.value) localStorage.setItem("maxMem", maxMem.value) + gameLaunching = true } else{ ipcRenderer.send('notification', { title: "Erreur de lancement", @@ -57,7 +60,8 @@ document.querySelector("#web").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 => { @@ -68,6 +72,17 @@ document.querySelector("#close").addEventListener("click", e => { 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) => { 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) @@ -80,6 +95,7 @@ ipcRenderer.on("close", (e, args) => { loadingMessage.innerHTML = "Chargement de Minecraft en cours..." progressBar.style.width = "0" launchBtn.disabled = false + gameLaunching = false }) ipcRenderer.on('launch', (e, args) => { diff --git a/src/client/assets/js/login.js b/src/client/assets/js/login.js index 3214a52..e62d4bc 100644 --- a/src/client/assets/js/login.js +++ b/src/client/assets/js/login.js @@ -1,9 +1,12 @@ -user = document.querySelector('#nickname') -password = document.querySelector('#password') +const form = document.querySelector('#login-form') +const user = document.querySelector('#nickname') +const password = document.querySelector('#password') -document.querySelector('#login-form').addEventListener("submit", (e) => { + +form.addEventListener("submit", (e) => { e.preventDefault() - if(user.value){ + form.disabled = true + if(user.value) { ipcRenderer.send("login", { user: user.value, pass: password.value @@ -16,3 +19,7 @@ document.querySelector('#login-form').addEventListener("submit", (e) => { } }) + +ipcRenderer.on("loginError", event => { + form.disabled = false +}) \ No newline at end of file diff --git a/src/client/index.html b/src/client/index.html index edd206d..5abed92 100644 --- a/src/client/index.html +++ b/src/client/index.html @@ -28,6 +28,8 @@


+

Au secours, mon jeu ne démarre pas

+
diff --git a/src/server/main.js b/src/server/main.js index a034d6b..24749f5 100644 --- a/src/server/main.js +++ b/src/server/main.js @@ -64,6 +64,10 @@ ipcMain.on("login", (event, args) => { minecraft.login(event, win, showNotification, args.user, args.pass) }) +ipcMain.on("invalidateData", event => { + minecraft.invalidateData(event) +}) + ipcMain.on("launch", (event, args) => { minecraft.launch(event, showNotification, args) }) diff --git a/src/server/minecraft.js b/src/server/minecraft.js index 7261fe7..dbe2559 100644 --- a/src/server/minecraft.js +++ b/src/server/minecraft.js @@ -25,6 +25,7 @@ class Minecraft { event.sender.send("nick", { name: v.name }) }) }).catch((err) => { + event.sender.send("loginError") logger.error(err) showNotification("Erreur de connexion") }) @@ -51,7 +52,7 @@ class Minecraft { } }) 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) => { event.sender.send("progress", e) 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 \ No newline at end of file