mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-04-19 23:37:41 +00:00
Gradient added and extra login added
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
86384aa6aa
commit
22a3fd91a1
2 changed files with 44 additions and 10 deletions
|
@ -21,6 +21,10 @@ If no parameter are set or not four colors are set the default color set for lig
|
|||
|
||||
_Roadmap_:
|
||||
* Add GigaDepot volume
|
||||
* MegaByte Support
|
||||
|
||||
_Contributers_:
|
||||
* [Necriso](https://github.com/Necriso)
|
||||
|
||||
_Credits_:
|
||||
* Sillium for the inspiration https://gist.github.com/Sillium/f904fb89444bc8dde12cfc07b8fa8728
|
||||
|
|
|
@ -10,10 +10,13 @@
|
|||
let cacheMinutes = 60;
|
||||
|
||||
let backColor; //Widget background color
|
||||
let backColor2; //Widget background color
|
||||
let textColor; //Widget text color
|
||||
let fillColor;
|
||||
let strokeColor;
|
||||
|
||||
let useGradient = true
|
||||
|
||||
let widgetInputRAW = args.widgetParameter;
|
||||
let widgetInput = null;
|
||||
|
||||
|
@ -27,13 +30,16 @@ if (widgetInput !== null && widgetInput.length == 4) {
|
|||
textColor = widgetInput[1];
|
||||
fillColor = widgetInput[2];
|
||||
strokeColor = widgetInput[3];
|
||||
useGradient = false
|
||||
} else if (Device.isUsingDarkAppearance()) {
|
||||
backColor = '222222';
|
||||
backColor = '111111';
|
||||
backColor2 = '222222';
|
||||
textColor = 'EDEDED';
|
||||
fillColor = 'EDEDED';
|
||||
strokeColor = '121212';
|
||||
} else {
|
||||
backColor = 'D32D1F';
|
||||
backColor2 = '76150C';
|
||||
textColor = 'EDEDED';
|
||||
fillColor = 'EDEDED';
|
||||
strokeColor = 'B0B0B0';
|
||||
|
@ -97,6 +103,7 @@ async function getSessionCookies() {
|
|||
let res = await req.loadJSON()
|
||||
return { cookies: req.response.cookies, msisdn: res.msisdn}
|
||||
} catch (e) {
|
||||
console.log("Login vailed! Please check if Wifi is disabled.")
|
||||
console.log(e)
|
||||
throw e
|
||||
}
|
||||
|
@ -117,20 +124,23 @@ async function getUsage() {
|
|||
}
|
||||
try {
|
||||
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){
|
||||
return v.container == "Daten"
|
||||
})
|
||||
console.log("usageGroup 'Daten' founded")
|
||||
let datenvolumen = datenContainer.usage.find(function(v){
|
||||
return v.code == "-1"
|
||||
})
|
||||
console.log(datenvolumen)
|
||||
return {
|
||||
total: datenvolumen.total,
|
||||
used: datenvolumen.used,
|
||||
remaining: datenvolumen.remaining
|
||||
total: datenvolumen.total || 0,
|
||||
used: datenvolumen.used || 0,
|
||||
remaining: datenvolumen.remaining || 0
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Loading usage data failed")
|
||||
console.log(e)
|
||||
throw e
|
||||
}
|
||||
|
@ -158,7 +168,14 @@ try {
|
|||
} else {
|
||||
console.log("Get from API")
|
||||
data = await getUsage()
|
||||
console.log("Write Data to Cache")
|
||||
try {
|
||||
files.writeString(cachePath, JSON.stringify(data))
|
||||
} catch(e) {
|
||||
console.log("Creating Cache failed!")
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
lastUpdate = today
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -168,15 +185,28 @@ try {
|
|||
lastUpdate = cacheDate
|
||||
}
|
||||
|
||||
console.log(data)
|
||||
|
||||
// Create Widget
|
||||
let widget = new ListWidget();
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
let provider = widget.addText("Vodafone")
|
||||
provider.font = Font.mediumSystemFont(12)
|
||||
provider.color = new Color(textColor)
|
||||
provider.textColor = new Color(textColor)
|
||||
|
||||
widget.addSpacer()
|
||||
|
||||
|
@ -212,7 +242,7 @@ let totalGB = (data.total / 1024).toFixed(0)
|
|||
let totalValuesText = widget.addText(`${remainingGB} GB von ${totalGB} GB`)
|
||||
totalValuesText.font = Font.mediumSystemFont(12)
|
||||
totalValuesText.centerAlignText()
|
||||
totalValuesText.color = new Color(textColor)
|
||||
totalValuesText.textColor = new Color(textColor)
|
||||
|
||||
// Last Update
|
||||
widget.addSpacer(5)
|
||||
|
|
Loading…
Add table
Reference in a new issue