From f5d524948c9894fb2ecafb5f9097eb5e05784bd9 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 8 Dec 2020 23:04:57 +0100 Subject: [PATCH] added progress bar --- .gitignore | 4 +-- index.css => include/index.css | 26 ++++++++++++++++++ include/index.js | 25 +++++++++++++++-- login.css => include/login.css | 0 .../maxresdefault.jpg | Bin menubar.css => include/menubar.css | 0 script.js => include/script.js | 0 index.html | 10 ++++--- login.html | 6 ++-- main.js | 20 ++++++++------ 10 files changed, 71 insertions(+), 20 deletions(-) rename index.css => include/index.css (75%) rename login.css => include/login.css (100%) rename maxresdefault.jpg => include/maxresdefault.jpg (100%) rename menubar.css => include/menubar.css (100%) rename script.js => include/script.js (100%) diff --git a/.gitignore b/.gitignore index 66b8fc9..de34272 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules/ - -out/ \ No newline at end of file +game +out/ diff --git a/index.css b/include/index.css similarity index 75% rename from index.css rename to include/index.css index e64840d..8eac1bc 100644 --- a/index.css +++ b/include/index.css @@ -66,4 +66,30 @@ h3 { background-color: green; border: 1px solid black; border-radius: 3px; +} + +.hidden{ + display:none; +} + +#fullprogressbar{ + position:relative; + margin: 0 auto; + width:80%; + height:25px; + background-color:gray; +} + +#progressbar{ + background-color: green; + height:100%; + width:0; +} + +#loading-message{ + width:80%; + position:relative; + margin: 0 auto; + height:28px; + color:white; } \ No newline at end of file diff --git a/include/index.js b/include/index.js index cae95f5..88b5531 100644 --- a/include/index.js +++ b/include/index.js @@ -1,16 +1,37 @@ minMem= "2G" maxMem = "4G" +let launchBtn = document.querySelector('#launch-btn'); +let fullProgressBar = document.querySelector('#fullprogressbar') +let progressBar = document.querySelector('#progressbar') +let loadingMessage = document.querySelector('#loading-message') ipcRenderer.on("nick", (event, args) => { console.log(args) document.querySelector("#nick-span").innerHTML = args.name }) -document.querySelector('#launch-btn').addEventListener("click", e => { +launchBtn.addEventListener("click", e => { + launchBtn.classList.add('hidden'); + fullProgressBar.classList.remove('hidden'); + loadingMessage.classList.remove('hidden'); ipcRenderer.send('launch', { minMem: minMem, maxMem: maxMem }) - document.querySelector('#launch-btn').disabled = true + launchBtn.disabled = true +}) + +ipcRenderer.on("progress", (e, args) => { + progressBar.style.width = (args.task / args.total) * 100 + "%" + loadingMessage.innerHTML = "Téléchargement de " + args.type + ": " + args.task + " sur " + args.total; +}) + +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..." + progressBar.style.width = "0" + launchBtn.disabled = false }) \ No newline at end of file diff --git a/login.css b/include/login.css similarity index 100% rename from login.css rename to include/login.css diff --git a/maxresdefault.jpg b/include/maxresdefault.jpg similarity index 100% rename from maxresdefault.jpg rename to include/maxresdefault.jpg diff --git a/menubar.css b/include/menubar.css similarity index 100% rename from menubar.css rename to include/menubar.css diff --git a/script.js b/include/script.js similarity index 100% rename from script.js rename to include/script.js diff --git a/index.html b/index.html index f3f2ab5..ee82946 100644 --- a/index.html +++ b/index.html @@ -4,8 +4,8 @@ Launcher Projet Secret - - + + @@ -27,14 +27,16 @@ Contenu
- +
+ +

- + diff --git a/login.html b/login.html index 2fcb02c..7162957 100644 --- a/login.html +++ b/login.html @@ -4,8 +4,8 @@ Launcher Projet Secret - - + + @@ -31,7 +31,7 @@ - + diff --git a/main.js b/main.js index b0b919f..6d3e8d8 100644 --- a/main.js +++ b/main.js @@ -7,14 +7,17 @@ const iconPath = path.join(__dirname, "icon.png"); let win = null let auth = null -let Minecraftpath = "projet-secret" +let Minecraftpath = "game" let clientPackage = "https://www.dropbox.com/s/ww6a052nzzgojdm/modpack.zip?dl=1" -let version = "fabric-loader-0.10.8-1.16.4" +let version = "1.16.4" +let versionFolder = "fabric-loader-0.10.8-1.16.4" function createWindow () { win = new BrowserWindow({ width: 1000, + minWidth: 900, height: 600, + minHeight: 600, icon: iconPath, webPreferences: { nodeIntegration: true, @@ -75,11 +78,10 @@ ipcMain.on("launch", (event, args) => { clientPackage: clientPackage, authorization: auth, root: Minecraftpath, - //forge: fabricmc, version: { - number: "1.16.4", + number: version, type: "release", - custom: version + custom: versionFolder }, memory: { max: args.maxMem, @@ -87,9 +89,9 @@ ipcMain.on("launch", (event, args) => { } } launcher.launch(opts) - launcher.on('debug', (e) => console.log(e)); - launcher.on('data', (e) => console.log(e)); - launcher.on('progress', (e) => console.log(e)); - launcher.on('close', (e) => console.log(e)); + 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('close', (e) => event.sender.send("close", e)); }) \ No newline at end of file