Skip to content

Commit 0b8225f

Browse files
committed
Added more stability by error handling
1 parent efe1b1f commit 0b8225f

File tree

4 files changed

+48
-38
lines changed

4 files changed

+48
-38
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The App is completely portable meaning you don't have to go through an installat
7373
and it can be copied from system to system seamlessly without any dependencies or extra files needed. **Recommended**
7474
- Terminal: Simply download the binary and run it:
7575
```bash
76-
curl -L https://github.com/SlapBot/powir/releases/download/v1.0.3/powir.1.0.3.exe --output powir.exe
76+
curl -L https://github.com/SlapBot/powir/releases/download/v1.0.4/powir.1.0.4.exe --output powir.exe
7777
./powir
7878
```
7979
- Double Click: Again [download](#desktop-app-main-mode) the binary and run it but please read this [note](#browser-and-windows-defender-warnings)
@@ -130,7 +130,7 @@ and it can be copied from system to system seamlessly without any dependencies o
130130
### Desktop App (Main Mode)
131131

132132
- Simply go to [Releases](https://github.com/SlapBot/powir/releases) and pick the latest version to download.
133-
- Download Current Latest Version (Powir v1): [Github](https://github.com/SlapBot/powir/releases/latest/download/powir.1.0.3.exe) or [GDrive](https://drive.google.com/drive/folders/1ntEjEenEzZXMP8L_nXNoHnIFqNSLpwD9): **Please take a note below before downloading the app**
133+
- Download Current Latest Version (Powir v1): [Github](https://github.com/SlapBot/powir/releases/latest/download/powir.1.0.4.exe) or [GDrive](https://drive.google.com/drive/folders/1ntEjEenEzZXMP8L_nXNoHnIFqNSLpwD9): **Please take a note below before downloading the app**
134134

135135
#### Browser And Windows Defender Warnings
136136

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powir",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Windows 10 based tool to monitor and analyze your system's power and battery usage",
55
"main": "public/electron.js",
66
"repository": {

Diff for: public/app/scrape.js

+43-33
Original file line numberDiff line numberDiff line change
@@ -189,44 +189,54 @@ function getTabulatedData(data, rInfo) {
189189
return data
190190
}
191191

192+
function computeInfo(soup, infoName, index, filterType) {
193+
let info = {
194+
'name': infoName,
195+
'note': "",
196+
'keys': [],
197+
'data': []
198+
}
199+
info.note = getNote(soup, index)
200+
let rawInfo = soup[index].findAll('tr')
201+
switch (filterType) {
202+
case 'KEY_VALUE':
203+
[info.keys, info.data] = rawInfo.reduce(getKeyValueInfo, [[], []]);
204+
break
205+
case 'TABULATED_SIMPLE':
206+
info.keys = getTabulatedKeys({name: infoName}, rawInfo, 0)
207+
info.data = rawInfo.slice(1).reduce(getTabulatedData, {name: infoName, data: []}).data
208+
break
209+
case 'TABULATED_COMPLEX':
210+
info.keys = getTabulatedKeys({name: infoName}, rawInfo, 1)
211+
info.data = rawInfo.slice(2).reduce(getTabulatedData, {name: infoName, data: []}).data
212+
break
213+
case 'TABULATED_OVERALL':
214+
// hardcoded keys to ensure no dependency over each table scrape to ensure concurrency.
215+
info.keys = ["PERIOD", "ACTIVE (AT FULL CHARGE)", "CONNECTED STANDBY (AT FULL CHARGE)",
216+
"ACTIVE (AT DESIGN CAPACITY)", "CONNECTED STANDBY (AT DESIGN CAPACITY)"
217+
]
218+
info.data = rawInfo.reduce(getTabulatedData, {name: infoName, data: []}).data
219+
break
220+
default:
221+
return info
222+
}
223+
return info
224+
}
192225

193226
function getInfo(soup, infoName, index, filterType) {
194227
return new Promise((resolve, reject) => {
195228
// noinspection JSUnresolvedFunction
196-
let rawInfo = soup[index].findAll('tr')
197-
let info = {
198-
'name': infoName,
199-
'note': "",
200-
'keys': [],
201-
'data': []
202-
};
203-
switch (filterType) {
204-
case 'KEY_VALUE':
205-
[info.keys, info.data] = rawInfo.reduce(getKeyValueInfo, [[], []]);
206-
info.note = getNote(soup, index)
207-
break
208-
case 'TABULATED_SIMPLE':
209-
info.keys = getTabulatedKeys({name: infoName}, rawInfo, 0)
210-
info.data = rawInfo.slice(1).reduce(getTabulatedData, {name: infoName, data: []}).data
211-
info.note = getNote(soup, index)
212-
break
213-
case 'TABULATED_COMPLEX':
214-
info.keys = getTabulatedKeys({name: infoName}, rawInfo, 1)
215-
info.data = rawInfo.slice(2).reduce(getTabulatedData, {name: infoName, data: []}).data
216-
info.note = getNote(soup, index)
217-
break
218-
case 'TABULATED_OVERALL':
219-
// hardcoded keys to ensure no dependency over each table scrape to ensure concurrency.
220-
info.keys = ["PERIOD", "ACTIVE (AT FULL CHARGE)", "CONNECTED STANDBY (AT FULL CHARGE)",
221-
"ACTIVE (AT DESIGN CAPACITY)", "CONNECTED STANDBY (AT DESIGN CAPACITY)"
222-
]
223-
info.data = rawInfo.reduce(getTabulatedData, {name: infoName, data: []}).data
224-
info.note = getNote(soup, index)
225-
break
226-
default:
227-
reject(info)
229+
try {
230+
let info = computeInfo(soup, infoName, index, filterType)
231+
resolve(info)
232+
} catch (e) {
233+
resolve({
234+
'name': infoName,
235+
'note': getNote(soup, index),
236+
'keys': [],
237+
'data': []
238+
})
228239
}
229-
resolve(info)
230240
})
231241
}
232242

Diff for: src/components/utils/config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export default {
2-
version: '1.0.3',
2+
version: '1.0.4',
33
liteMode: process.env.REACT_APP_LITE_MODE === '1'
4-
}
4+
}

0 commit comments

Comments
 (0)