From cc8cec3f5ab556a0e550472a2dc7bead2d46e582 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 12 Jan 2021 16:48:33 +0100 Subject: [PATCH] Fixed a bug with allocation + deleted progress bar when game load --- include/index.css | 4 ++-- include/index.js | 54 ++++++++++++++++++++++++----------------------- include/script.js | 23 +++----------------- index.html | 2 +- main.js | 20 +++++++++--------- 5 files changed, 44 insertions(+), 59 deletions(-) diff --git a/include/index.css b/include/index.css index d5d32f0..c95f344 100644 --- a/include/index.css +++ b/include/index.css @@ -57,9 +57,9 @@ h3 { #launch-btn { position: relative; - top: -25px; + top: 50%; left:50%; - transform: translateX(-50%); + transform: translate(-50%, -50%); width: 20%; max-width:200px; height:50px; diff --git a/include/index.js b/include/index.js index e402b99..28efd4d 100644 --- a/include/index.js +++ b/include/index.js @@ -1,14 +1,23 @@ -var os = require('os'); -let launchBtn = document.querySelector('#launch-btn'); -let fullProgressBar = document.querySelector('#fullprogressbar') -let progressBar = document.querySelector('#progressbar') -let loadingMessage = document.querySelector('#loading-message') -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)) +const os = require('os'); +const launchBtn = document.querySelector('#launch-btn'); +const fullProgressBar = document.querySelector('#fullprogressbar') +const progressBar = document.querySelector('#progressbar') +const loadingMessage = document.querySelector('#loading-message') +const disconnectBtn = document.querySelector('#disconnect-btn') +const minMem = document.querySelector('#minMem') +const maxMem = document.querySelector('#maxMem') +const outputMinMem = document.querySelector('#outputMinMem') +const outputMaxMem = document.querySelector('#outputMaxMem') +const totalMem = os.totalmem() / (1.049 * Math.pow(10, 6)) + +document.body.onload = (e) => { + minMem.max = totalMem + maxMem.max = totalMem + minMem.value = localStorage.getItem("minMem") + outputMinMem.innerHTML = minMem.value + maxMem.value = localStorage.getItem("maxMem") + outputMaxMem.innerHTML = maxMem.value +} ipcRenderer.on("nick", (event, args) => { console.log(args) @@ -25,10 +34,8 @@ launchBtn.addEventListener("click", e => { maxMem: maxMem.value + "M" }) launchBtn.disabled = true - if(minMem.value && maxMem.value){ - localStorage.setItem("minMem", minMem.value) - localStorage.setItem("maxMem", maxMem.value) - } + localStorage.setItem("minMem", minMem.value) + localStorage.setItem("maxMem", maxMem.value) } else{ ipcRenderer.send('notification', { title: "Erreur de lancement", @@ -47,23 +54,18 @@ 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..." + loadingMessage.innerHTML = "Chargement de Minecraft en cours..." progressBar.style.width = "0" launchBtn.disabled = false }) -disconnectBtn.addEventListener('click', e => { - ipcRenderer.send('disconnect') +ipcRenderer.on('launch', (e, args) => { + fullProgressBar.classList.add('hidden'); + loadingMessage.classList.add('hidden'); }) -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 - +disconnectBtn.addEventListener('click', e => { + ipcRenderer.send('disconnect') }) minMem.addEventListener("input", (e) => { diff --git a/include/script.js b/include/script.js index 0377917..e2fd680 100644 --- a/include/script.js +++ b/include/script.js @@ -20,26 +20,9 @@ window.addEventListener("DOMContentLoaded", () => { const maxUnmaxButton = document.getElementById("max-unmax-btn") const closeButton = document.getElementById("close-btn") - minimizeButton.addEventListener("click", e => { - window.minimizeWindow() - }) + minimizeButton.addEventListener("click", e => window.minimizeWindow()) - maxUnmaxButton.addEventListener("click", e => { - const icon = maxUnmaxButton.querySelector("#icon-maxUnmax") - - window.maxUnmaxWindow() - - // Change the middle maximize-unmaximize icons. - if (window.isWindowMaximized()) { - icon.classList.remove("icon-square") - icon.classList.add("icon-clone") - } else { - icon.classList.add("icon-square") - icon.classList.remove("icon-clone") - } - }) + maxUnmaxButton.addEventListener("click", e => window.maxUnmaxWindow()) - closeButton.addEventListener("click", e => { - window.closeWindow() - }) + closeButton.addEventListener("click", e => window.closeWindow()) }) diff --git a/index.html b/index.html index 8b793a5..9ad42fc 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@

Allocation mémoire

- +
diff --git a/main.js b/main.js index 61160c8..ae27d37 100644 --- a/main.js +++ b/main.js @@ -1,10 +1,9 @@ const { app, BrowserWindow, Menu, ipcMain, Notification } = require('electron') const path = require('path') +if (handleSquirrelEvent()) return; const { Client, Authenticator } = require('minecraft-launcher-core') +const appdata = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + "/.local/share") -if (handleSquirrelEvent()) { - return; -} function handleSquirrelEvent() { if (process.argv.length === 1) { @@ -52,14 +51,14 @@ function handleSquirrelEvent() { app.quit(); return true; } -}; +} const launcher = new Client(); const iconPath = path.join(__dirname, "icon.ico"); let win = null let auth = null -let Minecraftpath = "game" +let Minecraftpath = path.join(appdata, ".ps") let clientPackage = "https://www.dropbox.com/s/ww6a052nzzgojdm/modpack.zip?dl=1" let version = "1.16.4" let versionFolder = "fabric-loader-0.10.8-1.16.4" @@ -113,7 +112,7 @@ ipcMain.on("login", (event, args) => { }) }) -function showNotification(title="", body="") { +function showNotification(title, body="") { const notification = { title: title, body: body @@ -142,17 +141,18 @@ ipcMain.on("launch", (event, args) => { } launcher.launch(opts) // launcher.on('debug', (e) => console.log("debug", e)); - launcher.on('data', (e) => console.log("data", e)); - launcher.on('progress', (e) => event.sender.send("progress", e)); + // launcher.on('data', (e) => console.log("data", e)); + launcher.on('progress', (e) => event.sender.send("progress", e)) + launcher.on('arguments', (e) => event.sender.send("launch", e)) launcher.on('close', (e) => { event.sender.send("close", e) if(e !== 0){ showNotification("Une erreur est suvenue", "Minecraft ne s'est pas fermé correctement") } - }); + }) }) ipcMain.on("disconnect", (e) => { win.loadFile('login.html') -}) \ No newline at end of file +})