4
0
mirror of https://github.com/AltarikMC/Launcher synced 2024-11-22 06:19:50 +01:00

Fixed a bug with allocation + deleted progress bar when game load

This commit is contained in:
Quentin Legot 2021-01-12 16:48:33 +01:00 committed by Quentin Legot
parent 4695e2c187
commit 1d3d7d0feb
5 changed files with 44 additions and 59 deletions

View File

@ -57,9 +57,9 @@ h3 {
#launch-btn { #launch-btn {
position: relative; position: relative;
top: -25px; top: 50%;
left:50%; left:50%;
transform: translateX(-50%); transform: translate(-50%, -50%);
width: 20%; width: 20%;
max-width:200px; max-width:200px;
height:50px; height:50px;

View File

@ -1,14 +1,23 @@
var os = require('os'); const os = require('os');
let launchBtn = document.querySelector('#launch-btn'); const launchBtn = document.querySelector('#launch-btn');
let fullProgressBar = document.querySelector('#fullprogressbar') const fullProgressBar = document.querySelector('#fullprogressbar')
let progressBar = document.querySelector('#progressbar') const progressBar = document.querySelector('#progressbar')
let loadingMessage = document.querySelector('#loading-message') const loadingMessage = document.querySelector('#loading-message')
let disconnectBtn = document.querySelector('#disconnect-btn') const disconnectBtn = document.querySelector('#disconnect-btn')
let minMem = document.querySelector('#minMem') const minMem = document.querySelector('#minMem')
let maxMem = document.querySelector('#maxMem') const maxMem = document.querySelector('#maxMem')
let outputMinMem = document.querySelector('#outputMinMem') const outputMinMem = document.querySelector('#outputMinMem')
let outputMaxMem = document.querySelector('#outputMaxMem') const outputMaxMem = document.querySelector('#outputMaxMem')
let totalMem = os.totalmem() / (1.049 * Math.pow(10, 6)) 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) => { ipcRenderer.on("nick", (event, args) => {
console.log(args) console.log(args)
@ -25,10 +34,8 @@ launchBtn.addEventListener("click", e => {
maxMem: maxMem.value + "M" maxMem: maxMem.value + "M"
}) })
launchBtn.disabled = true launchBtn.disabled = true
if(minMem.value && maxMem.value){
localStorage.setItem("minMem", minMem.value) localStorage.setItem("minMem", minMem.value)
localStorage.setItem("maxMem", maxMem.value) localStorage.setItem("maxMem", maxMem.value)
}
} else{ } else{
ipcRenderer.send('notification', { ipcRenderer.send('notification', {
title: "Erreur de lancement", title: "Erreur de lancement",
@ -47,23 +54,18 @@ ipcRenderer.on("close", (e, args) => {
launchBtn.classList.remove('hidden'); launchBtn.classList.remove('hidden');
fullProgressBar.classList.add('hidden'); fullProgressBar.classList.add('hidden');
loadingMessage.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" progressBar.style.width = "0"
launchBtn.disabled = false launchBtn.disabled = false
}) })
disconnectBtn.addEventListener('click', e => { ipcRenderer.on('launch', (e, args) => {
ipcRenderer.send('disconnect') fullProgressBar.classList.add('hidden');
loadingMessage.classList.add('hidden');
}) })
window.addEventListener("DOMContentLoaded", () => { disconnectBtn.addEventListener('click', e => {
minMem.value = localStorage.getItem("minMem") != null ? Number(localStorage.getItem("minMem")) : 1024 ipcRenderer.send('disconnect')
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
}) })
minMem.addEventListener("input", (e) => { minMem.addEventListener("input", (e) => {

View File

@ -20,26 +20,9 @@ window.addEventListener("DOMContentLoaded", () => {
const maxUnmaxButton = document.getElementById("max-unmax-btn") const maxUnmaxButton = document.getElementById("max-unmax-btn")
const closeButton = document.getElementById("close-btn") const closeButton = document.getElementById("close-btn")
minimizeButton.addEventListener("click", e => { minimizeButton.addEventListener("click", e => window.minimizeWindow())
window.minimizeWindow()
})
maxUnmaxButton.addEventListener("click", e => { maxUnmaxButton.addEventListener("click", e => window.maxUnmaxWindow())
const icon = maxUnmaxButton.querySelector("#icon-maxUnmax")
window.maxUnmaxWindow() closeButton.addEventListener("click", e => window.closeWindow())
// 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")
}
})
closeButton.addEventListener("click", e => {
window.closeWindow()
})
}) })

View File

@ -29,7 +29,7 @@
<h4>Allocation mémoire</h4> <h4>Allocation mémoire</h4>
<label for="minMem">mémoire minimale : <div id="outputMinMem"></div></label> <label for="minMem">mémoire minimale : <div id="outputMinMem"></div></label>
<input type="range" min="1024" max="2048" step="128" value="1" class="slider" id="minMem"> <input type="range" min="1024" max="2048" step="128" value="1" class="slider" id="minMem">
<label for="minMem">mémoire maximale : <div id="outputMaxMem"></div></label> <label for="maxMem">mémoire maximale : <div id="outputMaxMem"></div></label>
<input type="range" min="1024" max="2048" step="128" value="1" class="slider" id="maxMem"> <input type="range" min="1024" max="2048" step="128" value="1" class="slider" id="maxMem">
</div> </div>
<div id="main"> <div id="main">

18
main.js
View File

@ -1,10 +1,9 @@
const { app, BrowserWindow, Menu, ipcMain, Notification } = require('electron') const { app, BrowserWindow, Menu, ipcMain, Notification } = require('electron')
const path = require('path') const path = require('path')
if (handleSquirrelEvent()) return;
const { Client, Authenticator } = require('minecraft-launcher-core') 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() { function handleSquirrelEvent() {
if (process.argv.length === 1) { if (process.argv.length === 1) {
@ -52,14 +51,14 @@ function handleSquirrelEvent() {
app.quit(); app.quit();
return true; return true;
} }
}; }
const launcher = new Client(); const launcher = new Client();
const iconPath = path.join(__dirname, "icon.ico"); const iconPath = path.join(__dirname, "icon.ico");
let win = null let win = null
let auth = 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 clientPackage = "https://www.dropbox.com/s/ww6a052nzzgojdm/modpack.zip?dl=1"
let version = "1.16.4" let version = "1.16.4"
let versionFolder = "fabric-loader-0.10.8-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 = { const notification = {
title: title, title: title,
body: body body: body
@ -142,14 +141,15 @@ ipcMain.on("launch", (event, args) => {
} }
launcher.launch(opts) launcher.launch(opts)
// launcher.on('debug', (e) => console.log("debug", e)); // launcher.on('debug', (e) => console.log("debug", e));
launcher.on('data', (e) => console.log("data", e)); // launcher.on('data', (e) => console.log("data", e));
launcher.on('progress', (e) => event.sender.send("progress", e)); launcher.on('progress', (e) => event.sender.send("progress", e))
launcher.on('arguments', (e) => event.sender.send("launch", e))
launcher.on('close', (e) => { launcher.on('close', (e) => {
event.sender.send("close", e) event.sender.send("close", e)
if(e !== 0){ if(e !== 0){
showNotification("Une erreur est suvenue", "Minecraft ne s'est pas fermé correctement") showNotification("Une erreur est suvenue", "Minecraft ne s'est pas fermé correctement")
} }
}); })
}) })