mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-06-06 21:47:40 +00:00
widget catalog removed
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
115be7514e
commit
d9e4c7ec6d
2 changed files with 0 additions and 240 deletions
|
@ -1,53 +0,0 @@
|
|||
{
|
||||
"widgets": [
|
||||
{
|
||||
"name": "Countdown",
|
||||
"version": "1.0.0",
|
||||
"scriptURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Countdown/Countdown.js",
|
||||
"previewURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Countdown/previewLight.jpeg",
|
||||
"descriptionURL": "https://github.com/ThisIsBenny/iOS-Widgets/blob/main/Countdown/README.md"
|
||||
},
|
||||
{
|
||||
"name": "Covid-19 7-Day-Inzidenz for Düsseldorf",
|
||||
"version": "1.0.1",
|
||||
"scriptURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Covid-19/Covid-19.js",
|
||||
"previewURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Covid-19/previewLight.jpeg",
|
||||
"descriptionURL": "https://github.com/ThisIsBenny/iOS-Widgets/blob/main/Covid-19/README.md"
|
||||
},
|
||||
{
|
||||
"name": "Ecosia Tree Counter",
|
||||
"version": "1.0.0",
|
||||
"scriptURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Ecosia/Ecosia.js",
|
||||
"previewURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Ecosia/previewLight.jpeg",
|
||||
"descriptionURL": "https://github.com/ThisIsBenny/iOS-Widgets/blob/main/Ecosia/README.md"
|
||||
},
|
||||
{
|
||||
"name": "Meeting dial in",
|
||||
"version": "0.1.1",
|
||||
"scriptURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Meeting-dial-in/Meeting-dial-in.js",
|
||||
"previewURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Meeting-dial-in/previewLight.jpeg",
|
||||
"descriptionURL": "https://github.com/ThisIsBenny/iOS-Widgets/blob/main/Meeting-dial-in/README.md"
|
||||
},
|
||||
{
|
||||
"name": "Vodafone DE remaining data volume",
|
||||
"version": "1.2.1",
|
||||
"scriptURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/VodafoneDE/VodafoneDE.js",
|
||||
"previewURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/VodafoneDE/previewLight.jpeg",
|
||||
"descriptionURL": "https://github.com/ThisIsBenny/iOS-Widgets/blob/main/VodafoneDE/README.md"
|
||||
},
|
||||
{
|
||||
"name": "VRR-Monitor",
|
||||
"version": "1.2.1",
|
||||
"scriptURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/VRR-Monitor/VRR-Monitor.js",
|
||||
"previewURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/VRR-Monitor/previewLight.jpeg",
|
||||
"descriptionURL": "https://github.com/ThisIsBenny/iOS-Widgets/blob/main/VRR-Monitor/README.md"
|
||||
},
|
||||
{
|
||||
"name": "Where did I park my car?",
|
||||
"version": "1.1.0",
|
||||
"scriptURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/car-location/car-location.js",
|
||||
"previewURL": "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/car-location/previewLight.jpeg",
|
||||
"descriptionURL": "https://github.com/ThisIsBenny/iOS-Widgets/blob/main/car-location/README.md"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,187 +0,0 @@
|
|||
// Variables used by Scriptable.
|
||||
// These must be at the very top of the file. Do not edit.
|
||||
// icon-color: teal; icon-glyph: book-open;
|
||||
// Version 1.1.0
|
||||
|
||||
const catalogURL = "https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Widget-Catalog/catalog.json"
|
||||
const cacheMinutes = 60 * 4;
|
||||
|
||||
// tables
|
||||
let widgetCatalogTable = new UITable();
|
||||
widgetCatalogTable.showSeparators = true
|
||||
|
||||
// Setup Filemanager and paths
|
||||
const fmCloud = FileManager.iCloud()
|
||||
const fmLocal = FileManager.local()
|
||||
|
||||
async function loadScript(url) {
|
||||
let req = new Request(url)
|
||||
let content = await req.loadString()
|
||||
let filename = url.split('/').pop()
|
||||
|
||||
return {
|
||||
content,
|
||||
filename
|
||||
}
|
||||
}
|
||||
|
||||
function compareVersions(a, b) {
|
||||
if (a === b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var a_components = a.split(".");
|
||||
var b_components = b.split(".");
|
||||
|
||||
var len = Math.min(a_components.length, b_components.length);
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (parseInt(a_components[i]) > parseInt(b_components[i])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parseInt(a_components[i]) < parseInt(b_components[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (a_components.length > b_components.length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (a_components.length < b_components.length) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
async function downloadWidget(widget) {
|
||||
let downloadAlert = new Alert()
|
||||
downloadAlert.message = `Do you like to Download the '${widget.name}' Widget-Script?`;
|
||||
downloadAlert.addAction('Yes')
|
||||
downloadAlert.addCancelAction('No')
|
||||
|
||||
if (await downloadAlert.presentAlert() === 0) {
|
||||
let {
|
||||
content,
|
||||
filename
|
||||
} = await loadScript(widget.scriptURL)
|
||||
|
||||
const scriptPath = fmCloud.joinPath(fmCloud.documentsDirectory(), filename)
|
||||
const scriptExists = fmCloud.fileExists(scriptPath)
|
||||
|
||||
if (scriptExists) {
|
||||
let alreadyExistsAlert = new Alert()
|
||||
alreadyExistsAlert.message = `The Script '${filename}' already exists!`;
|
||||
alreadyExistsAlert.addAction('Replace')
|
||||
alreadyExistsAlert.addCancelAction('Cancel')
|
||||
|
||||
if (await alreadyExistsAlert.presentAlert() === -1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
fmCloud.writeString(scriptPath, content)
|
||||
|
||||
let successAlert = new Alert()
|
||||
successAlert.message = `Script '${filename}' saved!`;
|
||||
successAlert.addAction('Close')
|
||||
successAlert.presentAlert()
|
||||
|
||||
return filename
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchCatalog(url) {
|
||||
let req = new Request(url);
|
||||
return await req.loadJSON()
|
||||
}
|
||||
|
||||
function populateWidgetTable(table, widgets) {
|
||||
for (let i = 0; i < widgets.length; i++) {
|
||||
let row = new UITableRow()
|
||||
row.dismissOnSelect = false
|
||||
row.height = 100;
|
||||
row.cellSpacing = 10
|
||||
let imageCell = row.addImageAtURL(widgets[i].previewURL)
|
||||
imageCell.widthWeight = 20
|
||||
|
||||
let subTitle = ""
|
||||
if (widgets[i].localVersion !== "" && compareVersions(widgets[i].version, widgets[i].localVersion) === 1) {
|
||||
subTitle = `✨ New Version (${widgets[i].version}) available ✨`
|
||||
}
|
||||
|
||||
let nameCell = row.addText(widgets[i].name, subTitle)
|
||||
nameCell.widthWeight = 70
|
||||
|
||||
let descriptionButtonCell = row.addButton('ⓘ')
|
||||
descriptionButtonCell.rightAligned()
|
||||
descriptionButtonCell.widthWeight = 10
|
||||
descriptionButtonCell.onTap = () => {
|
||||
Safari.openInApp(widgets[i].descriptionURL)
|
||||
}
|
||||
let downloadButtonCell = row.addButton('↓')
|
||||
downloadButtonCell.rightAligned()
|
||||
downloadButtonCell.widthWeight = 10
|
||||
downloadButtonCell.onTap = async function () {
|
||||
await downloadWidget(widgets[i])
|
||||
}
|
||||
table.addRow(row)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.present = async () => {
|
||||
// Set up cache .
|
||||
const cachePath = fmLocal.joinPath(fmLocal.temporaryDirectory(), "cache-widget-catalog")
|
||||
const cacheExists = fmLocal.fileExists(cachePath)
|
||||
const cacheDate = cacheExists ? fmLocal.modificationDate(cachePath) : 0
|
||||
|
||||
let catalog;
|
||||
try {
|
||||
// If cache exists and it's been less than 30 minutes since last request, use cached data.
|
||||
if (cacheExists && ((new Date()).getTime() - cacheDate.getTime()) < (cacheMinutes * 60 * 1000)) {
|
||||
console.log("Get from Cache")
|
||||
catalog = JSON.parse(fmLocal.readString(cachePath))
|
||||
|
||||
} else {
|
||||
console.log("Get from API")
|
||||
catalog = await fetchCatalog(catalogURL)
|
||||
console.log("Write Data to Cache")
|
||||
try {
|
||||
fmLocal.writeString(cachePath, JSON.stringify(catalog))
|
||||
} catch (e) {
|
||||
console.log("Creating Cache failed!")
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
if (cacheExists) {
|
||||
console.log("Get from Cache")
|
||||
catalog = JSON.parse(fmLocal.readString(cachePath))
|
||||
} else {
|
||||
console.log("No fallback to cache possible. Due to missing cache.")
|
||||
}
|
||||
}
|
||||
|
||||
// Check Version of local Script
|
||||
catalog.widgets = catalog.widgets.map((w) => {
|
||||
w.localVersion = ""
|
||||
|
||||
const filename = w.scriptURL.split('/').pop()
|
||||
const scriptPath = fmCloud.joinPath(fmCloud.documentsDirectory(), filename)
|
||||
const scriptExists = fmCloud.fileExists(scriptPath)
|
||||
|
||||
if (scriptExists) {
|
||||
const scriptContent = fmCloud.readString(scriptPath)
|
||||
const m = scriptContent.match(/Version[\s]*([\d]+(\.[\d]+){0,2})/m)
|
||||
if(m && m[1]) {
|
||||
w.localVersion = m[1]
|
||||
}
|
||||
}
|
||||
|
||||
return w;
|
||||
})
|
||||
console.log(catalog)
|
||||
|
||||
populateWidgetTable(widgetCatalogTable, catalog.widgets)
|
||||
|
||||
await widgetCatalogTable.present()
|
||||
}
|
Loading…
Add table
Reference in a new issue