From f856bd620eca5a62bf6cf52b55a90849b571e9bb Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 11 Feb 2022 08:48:40 +0100 Subject: [PATCH] Start fixing js files to fit to vue v3 --- src/client/assets/js/index.js | 176 ++++++++++++++++---------------- src/client/assets/js/login.js | 64 ++++++------ src/client/assets/js/preload.js | 14 +-- src/client/index.html | 9 +- src/server/main.js | 7 +- src/server/minecraft.js | 6 +- 6 files changed, 144 insertions(+), 132 deletions(-) diff --git a/src/client/assets/js/index.js b/src/client/assets/js/index.js index 4fd6d4d..a9aafe0 100644 --- a/src/client/assets/js/index.js +++ b/src/client/assets/js/index.js @@ -1,30 +1,31 @@ const os = require('os') const totalMem = os.totalmem() / (1.049 * Math.pow(10, 6)) -let app = new vue({ - el: "#vue", - data: { - minMemValue: localStorage.getItem("minMem") != null ? localStorage.getItem("minMem") : 1024 , - maxMemValue: localStorage.getItem("maxMem") != null ? localStorage.getItem("maxMem") : 2048, - memStep: 128, - memMax: totalMem, - invalidateButtonText: "Supprimer et retélécharger les bibliothèques", - invalidateButtonDisabled: false, - displayFullscreen: "none", - nick: "Chargement", - launchBtnText: "Selectionnez un chapitre", - launchBtnDisable: true, - launchBtnHidden: false, - loadingMessageHidden: true, - loadingMessageText: "Téléchargement de Minecraft en cours...", - fullprogressbarHidden: true, - progressbarWidth: 0, - sidebarContent: "

Chargement en cours

", - notificationTitle: "", - notificationMessage: "" +app = vue.createApp({ + data() { + return { + minMemValue: localStorage.getItem("minMem") != null ? localStorage.getItem("minMem") : 1024 , + maxMemValue: localStorage.getItem("maxMem") != null ? localStorage.getItem("maxMem") : 2048, + memStep: 128, + memMax: totalMem, + invalidateButtonText: "Supprimer et retélécharger les bibliothèques", + invalidateButtonDisabled: false, + displayFullscreen: "none", + nick: "Chargement", + launchBtnText: "Selectionnez un chapitre", + launchBtnDisable: true, + launchBtnHidden: false, + loadingMessageHidden: true, + loadingMessageText: "Téléchargement de Minecraft en cours...", + fullprogressbarHidden: true, + progressbarWidth: 0, + sidebarContent: "

Chargement en cours

", + modsInformations: [], + modsInformationsLoaded: true + } + }, - mounted: function () { - this.demandModsInformations() + mounted () { iziToast.settings({ close: false, closeOnClick: true, @@ -32,9 +33,19 @@ let app = new vue({ position: 'topRight', resetOnHover: true, }) + ipcRenderer.on("modsInformations", (e, args) => { + console.log("loaded") + if(args === null) { + this.modsInformationsLoaded = false + } else { + this.modsInformationsLoaded = true + } + this.updateModsInformations(args) + }) + ipcRenderer.on("nick", (_, args) => root.nick = args.name) }, methods: { - invalidateData: function () { + invalidateData () { this.invalidateButtonDisabled = true this.invalidateButtonText = "Opération en cours" this.notificationTitle = "Opération en cours" @@ -42,115 +53,108 @@ let app = new vue({ this.showInfo() ipcRenderer.send('invalidateData') }, - launchBtnClick: function () { + launchBtnClick () { this.launchBtnHidden = true this.fullprogressbarHidden = false - app.loadingMessageHidden = false + this.loadingMessageHidden = false if(Number(this.minMemValue) <= Number(this.maxMemValue)){ ipcRenderer.send('launch', { minMem: this.minMemValue + "M", maxMem: this.maxMemValue + "M", chapter: selectedChapter }) - app.launchBtnDisable = true + this.launchBtnDisable = true localStorage.setItem("minMem", this.minMemValue) localStorage.setItem("maxMem", this.maxMemValue) gameLaunching = true - } else{ - app.notificationTitle = "Erreur de lancement" - app.notificationMessage = "La mémoire minimale doit être inférieure ou égale à la mémoire maximale." - this.showError() + } else { + this.showError("Erreur de lancement", "La mémoire minimale doit être inférieure ou égale à la mémoire maximale.") } }, - disconnectBtn: function () { + disconnectBtn () { ipcRenderer.send('disconnect') }, - options: function () { + options () { if(!gameLaunching) this.displayFullscreen = "block" }, - discord: () => shell.openExternal("https://discord.gg/b923tMhmRE"), - web: () => shell.openExternal("https://altarik.fr"), - closeFullscreen: function () { + discord() { + shell.openExternal("https://discord.gg/b923tMhmRE") } + , + web() { + shell.openExternal("https://altarik.fr") + }, + closeFullscreen () { this.displayFullscreen = "none" }, - demandModsInformations: function () { - ipcRenderer.send('demandModsInformations') + updateModsInformations(content) { + this.modsInformations = content + nextTick(() => {}) }, - showInfo: function () { + getModsInformations() { + return this.modsInformations + }, + showInfo(title, body) { iziToast.info({ - title: this.notificationTitle, - message: this.notificationMessage, + title: title, + message: body, + color: 'blue' }) }, - showError: function() { - iziToast.show({ - title: this.notificationTitle, - message: this.notificationMessage, - color: 'red' - + showError(title, body) { + iziToast.error({ + title: title, + message: body, + color: 'red', }) }, - showWarning: function() { + showWarning(title, body) { iziToast.warning({ - title: this.notificationTitle, - message: this.notificationMessage, + title: title, + message: body, + color: 'yellow' }) }, - showSuccess: function () { + showSuccess(title, body) { iziToast.success({ - title: this.notificationTitle, - message: this.notificationMessage, + title: title, + message: body, + color: 'green' }) } } }) + +let root = app.mount("#vue") + let gameLaunching = false let selectedChapter = -1; -ipcRenderer.on("nick", (_, args) => app.nick = args.name) - ipcRenderer.on("invalidated", () => { - app.invalidateButtonDisabled = false - app.invalidateButtonText = "Supprimer et retélécharger les bibliothèques" - app.notificationTitle = "Opération terminée" - app.notificationMessage = "Les données du jeu ont été supprimé avec succès" - app.showSuccess() + root.invalidateButtonDisabled = false + root.invalidateButtonText = "Supprimer et retélécharger les bibliothèques" + root.showSuccess("Opération terminée", "Les données du jeu ont été supprimé avec succès") }) ipcRenderer.on("progress", (e, args) => { - app.progressbarWidth = (args.task / Math.max(args.total, args.task)) * 100 - app.loadingMessageText = "Téléchargement de " + args.type + ": " + args.task + " sur " + Math.max(args.total, args.task) + root.progressbarWidth = (args.task / Math.max(args.total, args.task)) * 100 + root.loadingMessageText = "Téléchargement de " + args.type + ": " + args.task + " sur " + Math.max(args.total, args.task) }) ipcRenderer.on("close", (_e, _args) => { - app.launchBtnHidden = false - app.fullprogressbarHidden = true - app.loadingMessageHidden = true - app.loadingMessageText = "Chargement de Minecraft en cours..." - app.progressbarWidth = 0 - app.launchBtnDisable = false + root.launchBtnHidden = false + root.fullprogressbarHidden = true + root.loadingMessageHidden = true + root.loadingMessageText = "Chargement de Minecraft en cours..." + root.progressbarWidth = 0 + root.launchBtnDisable = false gameLaunching = false }) ipcRenderer.on('launch', (_e, _args) => { - app.fullprogressbarHidden = true - app.loadingMessageHidden = true -}) - -ipcRenderer.on("modsInformations", (e, args) => { - console.log(args) - if(args === null) { - app.sidebarContent = "

Une erreur est survenue lors de la récupération des informations, vérifiez votre connexion internet puis cliquez sur réessayez

" - + "" - } else { - let element = "" - for(const i in args) { - element += `

${args[i].title}

${args[i].description}

` - } - app.sidebarContent = element - } + root.fullprogressbarHidden = true + root.loadingMessageHidden = true }) function changeSelectedChapter(element) { @@ -159,6 +163,6 @@ function changeSelectedChapter(element) { v.classList.remove("selected") }) element.classList.add("selected") - app.launchBtnText = "JOUER" - app.launchBtnDisable = false + root.launchBtnText = "JOUER" + root.launchBtnDisable = false } diff --git a/src/client/assets/js/login.js b/src/client/assets/js/login.js index cce4bb5..9c185b8 100644 --- a/src/client/assets/js/login.js +++ b/src/client/assets/js/login.js @@ -1,16 +1,16 @@ // const {default: iziToast } = require('izitoast') -let app = new vue({ - el: "#vue", - data: { - login: "Connexion", - email: "Email", - password: "Mot de passe", - send_credentials: "Se connecter", - microsoft_button: "Connexion avec un compte Microsoft", - notificationTitle: "", - notificationMessage: "" + +app = vue.createApp({ + data() { + return { + login: "Connexion", + email: "Email", + password: "Mot de passe", + send_credentials: "Se connecter", + microsoft_button: "Connexion avec un compte Microsoft", + } }, - mounted: function () { + mounted() { iziToast.settings({ close: false, closeOnClick: true, @@ -20,7 +20,7 @@ let app = new vue({ }) }, methods: { - formSubmit: function (e) { + formSubmit (e) { e.preventDefault() if(!microsoftButton.disabled) { form.disabled = true @@ -30,13 +30,12 @@ let app = new vue({ pass: password.value }) }else{ - this.notificationTitle = "Erreur de connexion" - this.notificationMessage = "Veuillez entrer des identifiants" - this.showWarning() + this.showWarning("Erreur de connexion", "Veuillez entrer des identifiants") + form.disabled = false } } }, - microsoftButton: function (e) { + microsoftButton(e) { e.preventDefault() if(!form.disabled) { microsoftButton.disabled = true @@ -44,44 +43,47 @@ let app = new vue({ ipcRenderer.send("microsoft-login") } }, - showInfo: function () { + showInfo(title, body) { iziToast.info({ - title: this.notificationTitle, - message: this.notificationMessage, + title: title, + message: body, color: 'blue' }) }, - showError: function() { - iziToast.show({ - title: this.notificationTitle, - message: this.notificationMessage, - color: 'red' - + showError(title, body) { + iziToast.error({ + title: title, + message: body, + color: 'red', }) }, - showWarning: function() { + showWarning(title, body) { iziToast.warning({ - title: this.notificationTitle, - message: this.notificationMessage, + title: title, + message: body, color: 'yellow' }) }, - showSuccess: function () { + showSuccess(title, body) { iziToast.success({ - title: this.notificationTitle, - message: this.notificationMessage, + title: title, + message: body, color: 'green' }) } } }); +app.mount("#vue"); + // theirs const are declared after vue cause vue modify them when declaring new vue instance const form = document.querySelector('#login-form') const user = document.querySelector('#nickname') const password = document.querySelector('#password') const microsoftButton = document.querySelector("#microsoft-button") + + ipcRenderer.on("loginError", () => { form.disabled = false microsoftButton.disabled = false diff --git a/src/client/assets/js/preload.js b/src/client/assets/js/preload.js index 822e5aa..76c5a59 100644 --- a/src/client/assets/js/preload.js +++ b/src/client/assets/js/preload.js @@ -1,7 +1,7 @@ 'use strict'; -const { ipcRenderer, shell } = require('electron'); -const vue = require('vue/dist/vue.common.prod') - +const { ipcRenderer } = require('electron'); +const vue = require('vue/dist/vue.cjs.js') +let app; window.addEventListener("DOMContentLoaded", () => { const minimizeButton = document.getElementById("minimize-btn") const closeButton = document.getElementById("close-btn") @@ -16,15 +16,15 @@ ipcRenderer.on('notification', (_e, args) => { app.notificationMessage = args.body switch(args.class) { case "success": - app.showSuccess() + app._component.methods.showSuccess(args.title, args.body) break; case "warning": - app.showWarning() + app._component.methods.showWarning(args.title, args.body) break; case "error": - app.showError() + app._component.methods.showError(args.title, args.body) break; case "info":default: - app.showInfo() + app._component.methods.showInfo(args.title, args.body) } }) diff --git a/src/client/index.html b/src/client/index.html index 28469d2..5a30849 100644 --- a/src/client/index.html +++ b/src/client/index.html @@ -38,7 +38,14 @@
diff --git a/src/server/main.js b/src/server/main.js index 2cf9f0f..fa80452 100644 --- a/src/server/main.js +++ b/src/server/main.js @@ -24,7 +24,7 @@ function createWindow () { }, frame: false }) - Menu.setApplicationMenu(null) + //Menu.setApplicationMenu(null) win.loadFile('src/client/login.html').then(() => { require('./updater.js').configUpdater(app, autoUpdater, dialog, logger, showNotification) }) @@ -87,9 +87,4 @@ ipcMain.on("disconnect", () => { }) -ipcMain.on("demandModsInformations", (e) => { - minecraft.getModsInformations(e) -}) - - diff --git a/src/server/minecraft.js b/src/server/minecraft.js index 8d8d28a..ceb5399 100644 --- a/src/server/minecraft.js +++ b/src/server/minecraft.js @@ -31,7 +31,11 @@ class Minecraft { this.auth = Authenticator.getAuth(username, password) this.auth.then(v => { win.loadFile('src/client/index.html').then(() => { - event.sender.send("nick", { name: v.name }) + setInterval(() => { + event.sender.send("nick", { name: v.name }) + this.getModsInformations(e) + }, 1000) + }) }).catch(() => { event.sender.send("loginError")