mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-06-07 05:57:41 +00:00
v.2.3.0 Vodafone Widget
Support for Lockscreen Widgets added to Vodafone Widget
This commit is contained in:
parent
ccadb48cdd
commit
75139896e1
1 changed files with 50 additions and 15 deletions
|
@ -3,9 +3,11 @@
|
||||||
// icon-color: red; icon-glyph: broadcast-tower;
|
// icon-color: red; icon-glyph: broadcast-tower;
|
||||||
|
|
||||||
/**************
|
/**************
|
||||||
Version 2.2.2
|
Version 2.3.0
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
v2.3.0:
|
||||||
|
- Support for lockscreen widgets added
|
||||||
v2.2.2:
|
v2.2.2:
|
||||||
- fix const variable issue
|
- fix const variable issue
|
||||||
v2.2.1:
|
v2.2.1:
|
||||||
|
@ -102,9 +104,11 @@ let widgetInput = null;
|
||||||
let user, pass, number, json, cacheUUID
|
let user, pass, number, json, cacheUUID
|
||||||
if (widgetInputRAW !== null) {
|
if (widgetInputRAW !== null) {
|
||||||
const parameter = widgetInputRAW.toString().split("|")
|
const parameter = widgetInputRAW.toString().split("|")
|
||||||
|
|
||||||
if(parameter.length > 1) {
|
if(parameter.length > 1) {
|
||||||
[user, pass, number, json] = parameter;
|
[user, pass, number, json] = parameter;
|
||||||
|
|
||||||
|
|
||||||
if (!user || !pass || !number) {
|
if (!user || !pass || !number) {
|
||||||
throw new Error("Invalid Widget parameter. Expected format: username|password|phonenumber")
|
throw new Error("Invalid Widget parameter. Expected format: username|password|phonenumber")
|
||||||
}
|
}
|
||||||
|
@ -444,6 +448,20 @@ function getTimeRemaining(endtime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTotalValues(v) {
|
||||||
|
let totalValues;
|
||||||
|
if (v.unitOfMeasure !== 'MB') {
|
||||||
|
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure} von ${v.total} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure}`
|
||||||
|
} else if (parseInt(v.total) < 1000) {
|
||||||
|
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} MB von ${v.total} MB`
|
||||||
|
} else {
|
||||||
|
let GB = ((showRemainingContingent ? v.remaining : v.used) / 1024).toFixed(2)
|
||||||
|
let totalGB = (v.total / 1024).toFixed(2)
|
||||||
|
totalValues = `${GB} GB von ${totalGB} GB`
|
||||||
|
}
|
||||||
|
return totalValues
|
||||||
|
}
|
||||||
|
|
||||||
async function getSessionCookiesViaNetworkLogin() {
|
async function getSessionCookiesViaNetworkLogin() {
|
||||||
let req;
|
let req;
|
||||||
req = new Request("https://www.vodafone.de/mint/rest/session/start")
|
req = new Request("https://www.vodafone.de/mint/rest/session/start")
|
||||||
|
@ -522,7 +540,7 @@ async function getUsage(user, pass, number) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log(JSON.stringify(res, null, 2))
|
console.log(JSON.stringify(res, null, 2))
|
||||||
}
|
}
|
||||||
|
throw new Error("Invalid Response")
|
||||||
}
|
}
|
||||||
console.log("unbilled-usage loaded")
|
console.log("unbilled-usage loaded")
|
||||||
if (debug) {
|
if (debug) {
|
||||||
|
@ -637,16 +655,39 @@ try {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lockscreenWidget = config.widgetFamily.includes('accessory')
|
||||||
|
|
||||||
// Create Widget
|
// Create Widget
|
||||||
let widget = new ListWidget();
|
let widget = new ListWidget();
|
||||||
|
|
||||||
widget.setPadding(10, 10, 10, 10)
|
if(!lockscreenWidget) {
|
||||||
|
widget.setPadding(10, 10, 10, 10)
|
||||||
|
}
|
||||||
|
|
||||||
if (data !== undefined) {
|
if (data !== undefined) {
|
||||||
if(debug) {
|
if(debug) {
|
||||||
console.log(JSON.stringify(data, null, 2))
|
console.log(JSON.stringify(data, null, 2))
|
||||||
}
|
}
|
||||||
const gradient = new LinearGradient()
|
if(lockscreenWidget) {
|
||||||
|
let stack = widget.addStack()
|
||||||
|
stack.layoutHorizontally()
|
||||||
|
let v = data.usage[0]
|
||||||
|
if(config.widgetFamily !== "accessoryInline") {
|
||||||
|
const percentage = (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
|
||||||
|
stack.addImage(getDiagram(percentage));
|
||||||
|
}
|
||||||
|
if(config.widgetFamily === "accessoryRectangular"){
|
||||||
|
stack.addSpacer(5)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(config.widgetFamily !== "accessoryCircular"){
|
||||||
|
const totalValues = getTotalValues(v)
|
||||||
|
stack.centerAlignContent()
|
||||||
|
stack.addText(totalValues)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const gradient = new LinearGradient()
|
||||||
gradient.locations = [0, 1]
|
gradient.locations = [0, 1]
|
||||||
gradient.colors = [
|
gradient.colors = [
|
||||||
backColor,
|
backColor,
|
||||||
|
@ -701,16 +742,7 @@ if (data !== undefined) {
|
||||||
column.addSpacer(2)
|
column.addSpacer(2)
|
||||||
|
|
||||||
// Total Values
|
// Total Values
|
||||||
let totalValues;
|
let totalValues = getTotalValues(v)
|
||||||
if (v.unitOfMeasure !== 'MB') {
|
|
||||||
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure} von ${v.total} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure}`
|
|
||||||
} else if (parseInt(v.total) < 1000) {
|
|
||||||
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} MB von ${v.total} MB`
|
|
||||||
} else {
|
|
||||||
let GB = ((showRemainingContingent ? v.remaining : v.used) / 1024).toFixed(2)
|
|
||||||
let totalGB = (v.total / 1024).toFixed(2)
|
|
||||||
totalValues = `${GB} GB von ${totalGB} GB`
|
|
||||||
}
|
|
||||||
textStack = column.addStack()
|
textStack = column.addStack()
|
||||||
textStack.layoutHorizontally()
|
textStack.layoutHorizontally()
|
||||||
textStack.addSpacer()
|
textStack.addSpacer()
|
||||||
|
@ -760,7 +792,7 @@ if (data !== undefined) {
|
||||||
remainingDaysText.centerAlignText()
|
remainingDaysText.centerAlignText()
|
||||||
remainingDaysText.textColor = textColor
|
remainingDaysText.textColor = textColor
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let fallbackText = widget.addText("Es ist ein Fehler aufgetreten! Bitte prüfen Sie die Logs direkt in der App.")
|
let fallbackText = widget.addText("Es ist ein Fehler aufgetreten! Bitte prüfen Sie die Logs direkt in der App.")
|
||||||
fallbackText.font = Font.mediumSystemFont(12)
|
fallbackText.font = Font.mediumSystemFont(12)
|
||||||
|
@ -772,6 +804,9 @@ if (!config.runsInWidget) {
|
||||||
case 'small': await widget.presentSmall(); break;
|
case 'small': await widget.presentSmall(); break;
|
||||||
case 'medium': await widget.presentMedium(); break;
|
case 'medium': await widget.presentMedium(); break;
|
||||||
case 'large': await widget.presentLarge(); break;
|
case 'large': await widget.presentLarge(); break;
|
||||||
|
case 'accessoryRectangular': await widget.presentAccessoryRectangular(); break;
|
||||||
|
case 'accessoryCircular': await widget.presentAccessoryCircular(); break;
|
||||||
|
case 'accessoryInline': await widget.presentAccessoryInline(); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue