Skip to content

Instantly share code, notes, and snippets.

@Sillium
Last active March 1, 2023 13:41
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Sillium/313164aec3d835c076ebfcd330f1be14 to your computer and use it in GitHub Desktop.
Save Sillium/313164aec3d835c076ebfcd330f1be14 to your computer and use it in GitHub Desktop.
Telekom Data Usage - iOS 14 Widget for Scriptable app
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: pink; icon-glyph: exchange-alt;
const DEBUG = false
const log = DEBUG ? console.log.bind(console) : function () { };
// configure the library
const libraryInfo = {
name: 'TelekomDataUsageLibrary',
version: '1.0.3',
gitlabProject: 'https://gitlab.com/sillium-scriptable-projects/universal-scriptable-widget-libraries',
forceDownload: DEBUG
}
// download and import library
let library = importModule(await downloadLibrary(libraryInfo))
// create the widget
const params = {
widgetParameter: args.widgetParameter,
debug: DEBUG
}
const widget = await library.createWidget(params)
// preview the widget
if (!config.runsInWidget) {
await widget.presentSmall()
}
Script.setWidget(widget)
Script.complete()
/**
* - creates directory for library if not existing
* - downloads library file if not existing or forced
* - returns relative path to library module
* @param {{name: string, version: string, gitlabProject: string, forceDownload: bool}} library
*/
async function downloadLibrary(library) {
let fm = FileManager.local()
let scriptPath = module.filename
let libraryDir = scriptPath.replace(fm.fileName(scriptPath, true), fm.fileName(scriptPath, false))
if (fm.fileExists(libraryDir) && !fm.isDirectory(libraryDir)) {
fm.remove(libraryDir)
}
if (!fm.fileExists(libraryDir)) {
fm.createDirectory(libraryDir)
}
let libraryFilename = library.name + '_' + library.version + '.js'
let path = fm.joinPath(libraryDir, libraryFilename)
let forceDownload = (library.forceDownload) ? library.forceDownload : false
if (fm.fileExists(path) && !forceDownload) {
log("Not downloading library file")
} else {
let r = Math.random().toString(36).substring(7);
let libraryUrl = library.gitlabProject + '/-/raw/' + library.version + '/' + library.name + '.js?random=' + r
log("Downloading library file '" + libraryUrl + "' to '" + path + "'")
const req = new Request(libraryUrl)
let libraryFile = await req.load()
fm.write(path, libraryFile)
}
return fm.fileName(scriptPath, false) + '/' + libraryFilename
}
@toddy1986
Copy link

toddy1986 commented Jul 29, 2021

Erhalte Fehlermeldung

457AFDCA-3047-460F-9B8F-3DCBD3BAA08E

@20CCAA07
Copy link

Erhalte Fehlermeldung

Diese Fehlermeldung hatte ich seit gestern auch. Ich habe dann den Ordner "TelekomDataUsage" im iCloud Drive gelöscht und das Widget in Scriptable noch mal neu ausgeführt. Seitdem ist alles wieder in Ordnung.

@toddy1986
Copy link

Erhalte Fehlermeldung

Diese Fehlermeldung hatte ich seit gestern auch. Ich habe dann den Ordner "TelekomDataUsage" im iCloud Drive gelöscht und das Widget in Scriptable noch mal neu ausgeführt. Seitdem ist alles wieder in Ordnung.

Danke, das hat geholfen.

@cars11
Copy link

cars11 commented Oct 2, 2021

Statt dass mit wlan an api offline angezeigt wird, was ja nicht stimmt, wäre besser das wlan mit ausrufezeichen symbok anzuzeigen. Das andere telekom Skript kann das. Außerdem aktualisert es bei mir nicht mehr wenn ich aus wlan raus bin :(
Sonst aber top!
0458644B-432A-4B58-A2CE-54633AA92081

@Piwio
Copy link

Piwio commented May 16, 2022

E7712C7D-B672-4CA9-83A5-7B737D25281E

Bekomme seit ein paar Tagen folgenden Fehler.
Schon bekannt? Kann man da was machen?
Danke und Lg!

@Piwio
Copy link

Piwio commented May 21, 2022

Erhalte Fehlermeldung

Diese Fehlermeldung hatte ich seit gestern auch. Ich habe dann den Ordner "TelekomDataUsage" im iCloud Drive gelöscht und das Widget in Scriptable noch mal neu ausgeführt. Seitdem ist alles wieder in Ordnung.

Danke, das hat geholfen.

Hilft bei mir leider nur kurzfristig…
Scheint irgendwas anderes fehlerhaft zu sein :-/

@Funterrain
Copy link

Seit ein paar Tagen bekomme ich folgende Meldung:
2022-06-23 09:05:39: Error on line 16:27: No file to import at Telekom/TelekomDataUsageLibrary_1.0.3.

Was kann ich tun?

@hstoerk
Copy link

hstoerk commented Jun 24, 2022

Ich habe nicht wirklich Zeit, mich drum zu kümmern, aber beim Fehler "Error on line 16:27: No file to import at Telekom/TelekomDataUsageLibrary_1.0.3." probiert mal bitte, die Zeile 12 zu ändern von forceDownload: DEBUG nach forceDownload: true.

@Funterrain
Copy link

das klappt leider auch nicht

@Funterrain
Copy link

2022-06-26 16:18:05: telekom.png is stored in iCloud but the file have not been downloaded. Use downloadFileFromiCloud(filePath) on a FileManager to download the file before accessing it.
2022-06-26 16:18:05: Error on line 191:44: Expected value of type Image but got value of type null.

@Sillium
Copy link
Author

Sillium commented Jul 5, 2022

Ich habe nicht wirklich Zeit, aber hier ist eine neue Version, die ein paar Fehler beheben sollte: https://gist.github.com/Sillium/235dc9fd873b25e321b3299da64c9c38

Bitte unbedingt einmal den Folder iCloud Drive --> Scriptable --> löschen, oder wie auch immer ihr das Script bei euch genannt habt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment