mirror of
https://github.com/cupcakearmy/volta.git
synced 2024-12-22 16:06:27 +00:00
Fix precision of battery level
This commit is contained in:
parent
bd5aa44be9
commit
dd3fba2052
@ -16,7 +16,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"auto-launch": "^5",
|
"auto-launch": "^5",
|
||||||
"battery-level": "^3",
|
"child_process": "^1.0.2",
|
||||||
"dark-mode": "^3.0.0",
|
"dark-mode": "^3.0.0",
|
||||||
"electron-settings": "^3"
|
"electron-settings": "^3"
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Weather</title>
|
<title>Volta</title>
|
||||||
<link rel="stylesheet" href="./index.css" charset="utf-8">
|
<link rel="stylesheet" href="./index.css" charset="utf-8">
|
||||||
<link rel="stylesheet" href="./vendor/nouislider.min.css" charset="utf-8">
|
<link rel="stylesheet" href="./vendor/nouislider.min.css" charset="utf-8">
|
||||||
<script charset="utf-8" src="./vendor/nouislider.min.js">
|
<script charset="utf-8" src="./vendor/nouislider.min.js">
|
||||||
@ -20,7 +20,6 @@
|
|||||||
<div class="title">Current:
|
<div class="title">Current:
|
||||||
<span id="currentBattery"></span>
|
<span id="currentBattery"></span>
|
||||||
</div>
|
</div>
|
||||||
<small>Note: Due to limits in the implementation the actual battery value may differ from the one given by the OS</small>
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
<div id="settings">
|
<div id="settings">
|
||||||
|
@ -66,5 +66,5 @@ ipcRenderer.on('launch', (event, checked) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ipcRenderer.on('battery', (event, value) => {
|
ipcRenderer.on('battery', (event, value) => {
|
||||||
document.getElementById('currentBattery').innerText = `${value}%`
|
document.getElementById('currentBattery').innerText = `${value}`
|
||||||
})
|
})
|
||||||
|
25
src/main.js
25
src/main.js
@ -12,6 +12,7 @@ const settings = require('electron-settings')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const AutoLaunch = require('auto-launch')
|
const AutoLaunch = require('auto-launch')
|
||||||
const batteryLevel = require('battery-level')
|
const batteryLevel = require('battery-level')
|
||||||
|
const exec = require('child_process').exec
|
||||||
|
|
||||||
const al = new AutoLaunch({
|
const al = new AutoLaunch({
|
||||||
name: 'Volta'
|
name: 'Volta'
|
||||||
@ -148,21 +149,15 @@ function sendMax() {
|
|||||||
}).show()
|
}).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let level = 'checking...';
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
batteryLevel().then(level => {
|
exec('pmset -g batt | egrep "([0-9]+\%)" -o', function(err, stdout, stderr) {
|
||||||
level = parseInt(level * 100)
|
if (err) {
|
||||||
|
console.log(error.stack)
|
||||||
if (level === lastBattery) return
|
console.log('Error code: ' + error.code)
|
||||||
if (level > lastBattery) charging = true
|
console.log('Signal received: ' + error.signal)
|
||||||
else charging = false
|
}
|
||||||
lastBattery = level
|
level = String(stdout)
|
||||||
|
})
|
||||||
const limits = settings.get('values', defaultValues)
|
|
||||||
|
|
||||||
if (level <= limits.min) sendMin()
|
|
||||||
else if (level >= limits.max) sendMax()
|
|
||||||
else numMax = numMin = 0
|
|
||||||
|
|
||||||
window.webContents.send('battery', level)
|
window.webContents.send('battery', level)
|
||||||
}).catch(() => console.log('Could not get Battery level'))
|
|
||||||
}, 3000)
|
}, 3000)
|
||||||
|
Loading…
Reference in New Issue
Block a user