From 66be046adcf76d8eb8558b55762e99cb966a761f Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sat, 19 Dec 2020 13:38:59 +0100 Subject: [PATCH] Improved ram selection + improved UX + added CI (may not work) --- .github/workflows/electron.yml | 27 +++++++++++++++++++ include/index.js | 47 ++++++++++++++++++++++++++-------- index.html | 8 +++--- 3 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/electron.yml diff --git a/.github/workflows/electron.yml b/.github/workflows/electron.yml new file mode 100644 index 0000000..80ef705 --- /dev/null +++ b/.github/workflows/electron.yml @@ -0,0 +1,27 @@ +name: CI +on: [ push ] +jobs: + build: + strategy: + matrix: + os: [ ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Use Node.js 14 + uses: actions/setup-node@v1 + with: + node-version: 14.x + - name: Get npm cache directory + id: npm-cache + run: | + echo "::set-output name=dir::$(npm config get cache)" + - uses: actions/cache@v2 + with: + path: ${{ steps.npm-cache.outputs.dir }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Intall dependencies + run: npm ci + - run: npm run make --if-present diff --git a/include/index.js b/include/index.js index a105dc9..e402b99 100644 --- a/include/index.js +++ b/include/index.js @@ -1,8 +1,14 @@ +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)) ipcRenderer.on("nick", (event, args) => { console.log(args) @@ -13,15 +19,23 @@ launchBtn.addEventListener("click", e => { launchBtn.classList.add('hidden'); fullProgressBar.classList.remove('hidden'); loadingMessage.classList.remove('hidden'); - ipcRenderer.send('launch', { - minMem: document.querySelector('#minMem').value, - maxMem: document.querySelector('#maxMem').value - }) - launchBtn.disabled = true - if(document.querySelector('#minMem').value.trim() && document.querySelector('#maxMem').value.trim()){ - localStorage.setItem("minMem", document.querySelector('#minMem').value.trim()) - localStorage.setItem("maxMem", document.querySelector('#maxMem').value.trim()) + if(Number(minMem.value) <= Number(maxMem.value)){ + ipcRenderer.send('launch', { + minMem: minMem.value + "M", + maxMem: maxMem.value + "M" + }) + launchBtn.disabled = true + if(minMem.value && maxMem.value){ + localStorage.setItem("minMem", minMem.value) + localStorage.setItem("maxMem", maxMem.value) + } + } else{ + ipcRenderer.send('notification', { + title: "Erreur de lancement", + body: "La mémoire minimale doit être inférieure ou égale à la mémoire maximale" + }) } + }) ipcRenderer.on("progress", (e, args) => { @@ -43,6 +57,19 @@ disconnectBtn.addEventListener('click', e => { }) window.addEventListener("DOMContentLoaded", () => { - document.querySelector('#minMem').value = localStorage.getItem("minMem") != null ? localStorage.getItem("minMem") : "2G" - document.querySelector('#maxMem').value = localStorage.getItem("maxMem") != null ? localStorage.getItem("maxMem") : "4G" + 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 + +}) + +minMem.addEventListener("input", (e) => { + outputMinMem.innerHTML = e.target.value +}) + +maxMem.addEventListener("input", (e) => { + outputMaxMem.innerHTML = e.target.value }) \ No newline at end of file diff --git a/index.html b/index.html index 1007ca1..3155c06 100644 --- a/index.html +++ b/index.html @@ -26,10 +26,10 @@

Modifier la configuration


Allocation mémoire

- - - - + + + +