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].description}