From d11c6a2c55afcdaed12881081d7684fae2bef1bd Mon Sep 17 00:00:00 2001 From: Nicco Date: Sat, 7 Mar 2020 16:35:28 +0100 Subject: [PATCH 1/5] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ce15c53..35c7940 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Battery assistant for prolonging the lifespan of your battery. Runs in the backg ### [Download](https://github.com/CupCakeArmy/volta/releases) +## Contributions 🙏 + +- https://github.com/daaanny90 dark mode support + ## What does it do? Good question. It gives you notifications about when to plug and unplug your charger. From 017e8d27c0a9dba2549c1ed9c37190b95e959301 Mon Sep 17 00:00:00 2001 From: "3m5.Danny Spina" Date: Mon, 9 Mar 2020 14:04:37 +0100 Subject: [PATCH 2/5] Add battery informations --- src/index.css | 56 +++++++++++++++++++++++++++++ src/index.html | 21 ++++++++--- src/index.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.js | 37 ++++++++++++++++++-- 4 files changed, 203 insertions(+), 6 deletions(-) diff --git a/src/index.css b/src/index.css index 01495cf..bd65562 100755 --- a/src/index.css +++ b/src/index.css @@ -52,6 +52,61 @@ hr { font-weight: bold; } +#app .subtitle { + font-size: 1em; + font-weight: bold; +} + +#app .subtitle #cycleNumber, +#app .subtitle #condition { + cursor: pointer; + z-index: 1; +} + + +#app .subtitle .normal { + color: lightgreen; +} + +#app .subtitle .warning { + color: yellow; +} + +#app .subtitle .danger { + color: red; +} + +#app .info { + position: absolute; + background: #333; + padding: 1em; + border-radius: 8px; + font-weight: normal; + width: 100%; + min-height: 30%; + top: 0; + left: 0; + opacity: 0; + pointer-events: none; + transition: opacity .3s ease-in; + display: flex; + flex-direction: column; + justify-content: space-between; +} + +#app .info .close { + text-align: right; + color: #3F8EFC; + cursor: pointer; +} + +#app .info.active { + opacity: 1; + transition: opacity .3s ease-in; + pointer-events: auto; + z-index: 2; +} + #app .link { color: #3F8EFC; font-size: 1em; @@ -74,6 +129,7 @@ hr { #settings #slider { padding: 1em .6em; + z-index: 0 } #settings #slider-cont { diff --git a/src/index.html b/src/index.html index 825cab1..088fe3d 100755 --- a/src/index.html +++ b/src/index.html @@ -20,7 +20,20 @@
Current:
-
+
Cycle: + +
+
Remaining: + +
+
Condition: + +
+
+
+ Close +
+
Limits
@@ -37,15 +50,15 @@
-
+
Set at which battery level Volta should notify you -
+
Start on boot
-
+
diff --git a/src/index.js b/src/index.js index f6199fc..e17a1f1 100755 --- a/src/index.js +++ b/src/index.js @@ -7,8 +7,11 @@ const darkMode = require('dark-mode') let rangeSlider let autoLaunch +let batteryCondition +let cycle document.addEventListener('DOMContentLoaded', () => { + document.getElementById('quit').addEventListener('click', () => { ipcRenderer.send('quit') }) @@ -23,6 +26,48 @@ document.addEventListener('DOMContentLoaded', () => { document.querySelector('#app').classList.add('light') } }) + + document.querySelector('.close').addEventListener('click', function() { + document.querySelector('.info').classList.toggle('active') + }) + + document.getElementById('condition').addEventListener('click', function() { + let infoContent = document.querySelector('.infoContent') + + document.querySelector('.info').classList.toggle('active') + + switch(batteryCondition) { + case(1): + infoContent.innerText = 'The battery is functioning normally.' + break; + case(2): + infoContent.innerText = 'The battery is functioning normally but holds less charge than it did when it was new. You should monitor the health of the battery periodically.' + break; + case(3): + infoContent.innerText = 'The battery is functioning normally but holds significantly less charge than it did when it was new. You can safely continue using your computer, but if its lowered charging capacity is affecting your experience.' + break; + case(4): + infoContent.innerText = 'The battery isn’t functioning normally. You can safely use your Mac only when it\'s connected to an appropriate power adapter.' + } + }) + + document.getElementById('cycleNumber').addEventListener('click', function() { + let infoContent = document.querySelector('.infoContent') + + document.querySelector('.info').classList.toggle('active') + + // TODO: write sentencees with a sense. + switch(cycle) { + case(1): + infoContent.innerText = 'Your battery is healthy and in the first part of it\'s life.' + break; + case(2): + infoContent.innerText = 'Your battery is now in the second part of it\'s life. The maximum limit for all modern Macbooks is 1000 cycles.' + break; + case(3): + infoContent.innerText = 'According to Apple, all Macbook models since 2008/2009 have a cycle limit of 1000. After this limit, your battery is considered consumed.' + } + }) }) function iniSlider() { @@ -68,3 +113,53 @@ ipcRenderer.on('launch', (event, checked) => { ipcRenderer.on('battery', (event, value) => { document.getElementById('currentBattery').innerText = `${value}%` }) + +ipcRenderer.on('cycleNumber', (event, value) => { + let cycleElement = document.getElementById('cycleNumber') + cycleElement.innerText = `${value}` + + if (parseInt(value) < 500) { + cycleElement.classList.add('normal') + cycle = 1 + } else if (value >= 500 && value < 1000) { + cycleElement.classList.add('warning') + cycle = 2 + } else if (value >= 1000) { + cycleElement.classList.add('danger') + cycle = 3 + } + + // https://support.apple.com/en-us/HT201585 600 is the average value of all models + // 1000 is the max cycle number of the best laptop, so over 1000 is for all models too much +}) + +ipcRenderer.on('remaining', (event, value) => { + if (value == '') { + value = 'calculating...' + } + document.getElementById('remaining').innerText = `${value}` +}) + +ipcRenderer.on('condition', (event, value) => { + let conditionElement = document.getElementById('condition') + let infoElement = document.querySelector('infocondition') + conditionElement.innerText = `${value}` + + switch(value.trim()) { + case("Normal"): + conditionElement.classList.add('normal') + batteryCondition = 1 + break; + case("Replace Soon"): + conditionElement.classList.add('warning') + batteryCondition = 2 + break; + case("Replace Now"): + conditionElement.classList.add('danger') + batteryCondition = 3 + break; + case("Service Battery"): + conditionElement.classList.add('danger') + batteryCondition = 4 + } +}) diff --git a/src/main.js b/src/main.js index 8e8e1c2..043d1ce 100755 --- a/src/main.js +++ b/src/main.js @@ -60,7 +60,7 @@ const createTray = () => { tray.on('click', toggleWindow) } -nativeTheme.on('updated', function () { +nativeTheme.on('updated', function() { tray.destroy() createTray() window.reload() @@ -150,7 +150,7 @@ function sendMax() { let level = '--'; setInterval(() => { - exec('pmset -g batt | egrep "([0-9]+\%)" -o', function (err, stdout, stderr) { + exec('pmset -g batt | egrep "([0-9]+\%)" -o', function(err, stdout, stderr) { if (err) { console.log(error.stack) console.log('Error code: ' + error.code) @@ -168,5 +168,38 @@ setInterval(() => { else if (level >= limits.max) sendMax() else numMax = numMin = 0 + exec("system_profiler SPPowerDataType | grep 'Cycle Count' | awk '{print $3}'", function(err, stdout, stderr) { + let cycleNumber + if (err) { + console.log(err.stack) + console.log('Error code: ' + err.code) + console.log('Signal received: ' + err.signal) + } + cycleNumber = stdout + window.webContents.send('cycleNumber', cycleNumber) + }) + + exec("pmset -g batt | awk '{print $5}' | grep :", function(err, stdout, stderr) { + let remaining = '--' + if (err) { + console.log(err.stack) + console.log('Error code: ' + err.code) + console.log('Signal received: ' + err.signal) + } + remaining = stdout + window.webContents.send('remaining', remaining) + }) + + exec("system_profiler SPPowerDataType | grep Condition | awk '{print $2}'", function(err, stdout, stderr) { + let condition + if (err) { + console.log(err.stack) + console.log('Error code: ' + err.code) + console.log('Signal received: ' + err.signal) + } + condition = stdout + window.webContents.send('condition', condition) + }) + window.webContents.send('battery', level) }, 3000) From f6f7620e61d11035e072e90461955795d17d46c8 Mon Sep 17 00:00:00 2001 From: "3m5.Danny Spina" Date: Mon, 9 Mar 2020 14:12:24 +0100 Subject: [PATCH 3/5] Fix comment --- src/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index e17a1f1..2dfe7ef 100755 --- a/src/index.js +++ b/src/index.js @@ -129,8 +129,7 @@ ipcRenderer.on('cycleNumber', (event, value) => { cycle = 3 } - // https://support.apple.com/en-us/HT201585 600 is the average value of all models - // 1000 is the max cycle number of the best laptop, so over 1000 is for all models too much + // https://support.apple.com/en-us/HT201585 for the last models (afetr 2008-2009) the max limit is 1000 cycles }) ipcRenderer.on('remaining', (event, value) => { From d29814c547e4e36bc4cb92be126e75177f141fcd Mon Sep 17 00:00:00 2001 From: "3m5.Danny Spina" Date: Mon, 9 Mar 2020 14:13:53 +0100 Subject: [PATCH 4/5] Clean todo --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index 2dfe7ef..7ed937c 100755 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,6 @@ document.addEventListener('DOMContentLoaded', () => { document.querySelector('.info').classList.toggle('active') - // TODO: write sentencees with a sense. switch(cycle) { case(1): infoContent.innerText = 'Your battery is healthy and in the first part of it\'s life.' From 2750f5deb6a8797512193a09500a5506457f3059 Mon Sep 17 00:00:00 2001 From: "3m5.Danny Spina" Date: Fri, 13 Mar 2020 20:29:26 +0100 Subject: [PATCH 5/5] Fix style --- src/index.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.css b/src/index.css index bd65562..fe89524 100755 --- a/src/index.css +++ b/src/index.css @@ -24,9 +24,9 @@ body, color: #3B252C; font-family: 'Source Sans Pro', sans-serif; width: 100%; + height: 100%; padding: 0; margin: 0; - border-radius: 8px; } #app.dark {