Gradient added and extra login added

Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
Benny Samir Hierl 2020-10-21 23:14:30 +02:00
parent 86384aa6aa
commit 22a3fd91a1
No known key found for this signature in database
GPG key ID: 69DE3C3C097DB7F7
2 changed files with 44 additions and 10 deletions

View file

@ -21,6 +21,10 @@ If no parameter are set or not four colors are set the default color set for lig
_Roadmap_: _Roadmap_:
* Add GigaDepot volume * Add GigaDepot volume
* MegaByte Support
_Contributers_:
* [Necriso](https://github.com/Necriso)
_Credits_: _Credits_:
* Sillium for the inspiration https://gist.github.com/Sillium/f904fb89444bc8dde12cfc07b8fa8728 * Sillium for the inspiration https://gist.github.com/Sillium/f904fb89444bc8dde12cfc07b8fa8728

View file

@ -10,10 +10,13 @@
let cacheMinutes = 60; let cacheMinutes = 60;
let backColor; //Widget background color let backColor; //Widget background color
let backColor2; //Widget background color
let textColor; //Widget text color let textColor; //Widget text color
let fillColor; let fillColor;
let strokeColor; let strokeColor;
let useGradient = true
let widgetInputRAW = args.widgetParameter; let widgetInputRAW = args.widgetParameter;
let widgetInput = null; let widgetInput = null;
@ -27,13 +30,16 @@ if (widgetInput !== null && widgetInput.length == 4) {
textColor = widgetInput[1]; textColor = widgetInput[1];
fillColor = widgetInput[2]; fillColor = widgetInput[2];
strokeColor = widgetInput[3]; strokeColor = widgetInput[3];
useGradient = false
} else if (Device.isUsingDarkAppearance()) { } else if (Device.isUsingDarkAppearance()) {
backColor = '222222'; backColor = '111111';
backColor2 = '222222';
textColor = 'EDEDED'; textColor = 'EDEDED';
fillColor = 'EDEDED'; fillColor = 'EDEDED';
strokeColor = '121212'; strokeColor = '121212';
} else { } else {
backColor = 'D32D1F'; backColor = 'D32D1F';
backColor2 = '76150C';
textColor = 'EDEDED'; textColor = 'EDEDED';
fillColor = 'EDEDED'; fillColor = 'EDEDED';
strokeColor = 'B0B0B0'; strokeColor = 'B0B0B0';
@ -97,6 +103,7 @@ async function getSessionCookies() {
let res = await req.loadJSON() let res = await req.loadJSON()
return { cookies: req.response.cookies, msisdn: res.msisdn} return { cookies: req.response.cookies, msisdn: res.msisdn}
} catch (e) { } catch (e) {
console.log("Login vailed! Please check if Wifi is disabled.")
console.log(e) console.log(e)
throw e throw e
} }
@ -117,20 +124,23 @@ async function getUsage() {
} }
try { try {
let res = await req.loadJSON() let res = await req.loadJSON()
console.log("unbilled-usage loaded")
console.log("Try to find usageGroup 'Daten'")
let datenContainer = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup'].find(function(v){ let datenContainer = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup'].find(function(v){
return v.container == "Daten" return v.container == "Daten"
}) })
console.log("usageGroup 'Daten' founded")
let datenvolumen = datenContainer.usage.find(function(v){ let datenvolumen = datenContainer.usage.find(function(v){
return v.code == "-1" return v.code == "-1"
}) })
console.log(datenvolumen) console.log(datenvolumen)
return { return {
total: datenvolumen.total, total: datenvolumen.total || 0,
used: datenvolumen.used, used: datenvolumen.used || 0,
remaining: datenvolumen.remaining remaining: datenvolumen.remaining || 0
} }
} catch (e) { } catch (e) {
console.log("Loading usage data failed")
console.log(e) console.log(e)
throw e throw e
} }
@ -158,7 +168,14 @@ try {
} else { } else {
console.log("Get from API") console.log("Get from API")
data = await getUsage() data = await getUsage()
console.log("Write Data to Cache")
try {
files.writeString(cachePath, JSON.stringify(data)) files.writeString(cachePath, JSON.stringify(data))
} catch(e) {
console.log("Creating Cache failed!")
console.log(e)
}
lastUpdate = today lastUpdate = today
} }
} catch (e) { } catch (e) {
@ -168,15 +185,28 @@ try {
lastUpdate = cacheDate lastUpdate = cacheDate
} }
console.log(data)
// Create Widget // Create Widget
let widget = new ListWidget(); let widget = new ListWidget();
widget.setPadding(10, 10, 10, 10) widget.setPadding(10, 10, 10, 10)
if (useGradient) {
const gradient = new LinearGradient()
gradient.locations = [0, 1]
gradient.colors = [
new Color(backColor),
new Color(backColor2)
]
widget.backgroundGradient = gradient
} else {
widget.backgroundColor = new Color(backColor) widget.backgroundColor = new Color(backColor)
}
let provider = widget.addText("Vodafone") let provider = widget.addText("Vodafone")
provider.font = Font.mediumSystemFont(12) provider.font = Font.mediumSystemFont(12)
provider.color = new Color(textColor) provider.textColor = new Color(textColor)
widget.addSpacer() widget.addSpacer()
@ -212,7 +242,7 @@ let totalGB = (data.total / 1024).toFixed(0)
let totalValuesText = widget.addText(`${remainingGB} GB von ${totalGB} GB`) let totalValuesText = widget.addText(`${remainingGB} GB von ${totalGB} GB`)
totalValuesText.font = Font.mediumSystemFont(12) totalValuesText.font = Font.mediumSystemFont(12)
totalValuesText.centerAlignText() totalValuesText.centerAlignText()
totalValuesText.color = new Color(textColor) totalValuesText.textColor = new Color(textColor)
// Last Update // Last Update
widget.addSpacer(5) widget.addSpacer(5)