mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-06-07 05:57:41 +00:00
parent
2659c15a55
commit
f8288a4d63
1 changed files with 610 additions and 637 deletions
|
@ -3,11 +3,9 @@
|
|||
// icon-color: red; icon-glyph: broadcast-tower;
|
||||
|
||||
/**************
|
||||
Version 2.4.0
|
||||
Version 2.3.0
|
||||
|
||||
Changelog:
|
||||
v2.4.0:
|
||||
- added Support for flat tariff like "GigaMobil M mit unbegrenzten GB", "GigaMobil XL mit unbegrenzten GB" or other flat tariffs
|
||||
v2.3.0:
|
||||
- Support for lockscreen widgets added
|
||||
v2.2.2:
|
||||
|
@ -254,7 +252,7 @@ async function setupAssistant() {
|
|||
let res, data
|
||||
try {
|
||||
res = await req.loadJSON()
|
||||
if (!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0] || !res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']) {
|
||||
if(!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0] || !res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']) {
|
||||
throw new Error('invalid response: ' + JSON.stringify(res))
|
||||
}
|
||||
data = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']
|
||||
|
@ -376,7 +374,7 @@ function creatProgress(total, havegone) {
|
|||
return context.getImage()
|
||||
}
|
||||
|
||||
function getDiagram(percentage, isFlat, widgetType) {
|
||||
function getDiagram(percentage) {
|
||||
function drawArc(ctr, rad, w, deg) {
|
||||
bgx = ctr.x - rad
|
||||
bgy = ctr.y - rad
|
||||
|
@ -428,22 +426,9 @@ function getDiagram(percentage, isFlat, widgetType) {
|
|||
)
|
||||
canvas.setTextAlignedCenter()
|
||||
canvas.setTextColor(textColor)
|
||||
canvas.setFont(Font.boldSystemFont(108))
|
||||
if (isFlat === true) {
|
||||
if (widgetType === "small" || "medium" || "large" || "extraLarge") {
|
||||
const infinitySize = canvSize / 2;
|
||||
canvas.setFont(Font.boldSystemFont(infinitySize));
|
||||
const textRect = new Rect(0, infinitySize / 3, canvSize, canvSize);
|
||||
canvas.drawTextInRect(`∞`, textRect);
|
||||
} else {
|
||||
const infinitySize = canvSize / 2;
|
||||
canvas.setFont(Font.boldSystemFont(infinitySize));
|
||||
const textRect = new Rect(0, infinitySize / 1, canvSize, canvSize);
|
||||
canvas.drawTextInRect(`∞`, textRect);
|
||||
}
|
||||
} else {
|
||||
canvas.drawTextInRect(`${percentage}%`, canvTextRect);
|
||||
}
|
||||
canvas.setFont(Font.boldSystemFont(canvTextSize))
|
||||
canvas.drawTextInRect(`${percentage}%`, canvTextRect)
|
||||
|
||||
return canvas.getImage()
|
||||
}
|
||||
|
||||
|
@ -464,21 +449,11 @@ 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 if (parseInt(v.total) >= 100000000) {
|
||||
if (showRemainingContingent === true) {
|
||||
totalValues = `Flat`
|
||||
} else {
|
||||
if (v.used <= 1024) {
|
||||
totalValues = `${v.used} MB verbraucht.`
|
||||
} else {
|
||||
let usedGB = (v.used / 1024).toFixed(2)
|
||||
totalValues = `${usedGB} GB verbraucht.`
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let GB = ((showRemainingContingent ? v.remaining : v.used) / 1024).toFixed(2)
|
||||
let totalGB = (v.total / 1024).toFixed(2)
|
||||
|
@ -561,7 +536,7 @@ async function getUsage(user, pass, number) {
|
|||
}
|
||||
try {
|
||||
let res = await req.loadJSON()
|
||||
if (!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0]) {
|
||||
if(!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0]) {
|
||||
if (debug) {
|
||||
console.log(JSON.stringify(res, null, 2))
|
||||
}
|
||||
|
@ -698,9 +673,8 @@ if (data !== undefined) {
|
|||
stack.layoutHorizontally()
|
||||
let v = data.usage[0]
|
||||
if(config.widgetFamily !== "accessoryInline") {
|
||||
const percentage = v.total >= 100000000 ? '∞' : (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
|
||||
const isFlat = v.total >= 100000000
|
||||
stack.addImage(getDiagram(percentage, isFlat, config.widgetFamily));
|
||||
const percentage = (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
|
||||
stack.addImage(getDiagram(percentage));
|
||||
}
|
||||
if(config.widgetFamily === "accessoryRectangular"){
|
||||
stack.addSpacer(5)
|
||||
|
@ -759,12 +733,11 @@ if (data !== undefined) {
|
|||
column.layoutVertically()
|
||||
column.centerAlignContent()
|
||||
|
||||
const percentage = v.total > 100000000 ? 100 : (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
|
||||
const isFlat = v.total >= 100000000
|
||||
const percentage = (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
|
||||
const imageStack = column.addStack()
|
||||
imageStack.layoutHorizontally()
|
||||
imageStack.addSpacer()
|
||||
imageStack.addImage(getDiagram(percentage, isFlat, config.widgetFamily));
|
||||
imageStack.addImage(getDiagram(percentage));
|
||||
imageStack.addSpacer()
|
||||
column.addSpacer(2)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue