Skip to content

Commit

Permalink
Implemented Updater
Browse files Browse the repository at this point in the history
  • Loading branch information
tiuub committed Dec 27, 2023
1 parent dbd5f4c commit 55b7df5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TraewellingWidget",
"version": "1.1.0",
"version": "1.1.1",
"description": "An iOS widget for Scriptable, which shows your stats about your latest train rides checked in via Traewelling.",
"main": "TraewellingWidget.js",
"scripts": {
Expand Down
27 changes: 18 additions & 9 deletions src/TraewellingWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,22 @@ async function main() {

// Update script

if (areRepoUpdatesAvailable) {
try {
await updater.updateScript(scriptName);
} catch (error) {
console.log(`${error.line}: ${error.message}`);
if (areRepoUpdatesAvailable && config.runsInApp) {
let inputAlert = new Alert();
inputAlert.title = "Traewelling Widget Update";
inputAlert.message = "There is an update for Traewelling Widget.\n\nDo you want to install it?";

inputAlert.addAction("No");
inputAlert.addAction("Yes");

let buttonIndex = await inputAlert.present();

if (buttonIndex === 1) {
try {
await updater.updateScript(scriptName);
} catch (error) {
console.log(`${error.line}: ${error.message}`);
}
}
}

Expand Down Expand Up @@ -307,9 +318,7 @@ async function main() {

async function createWidget(traewelling, widgetParams) {
let widget = generateBaseWidget();
if (widgetParams.areRepoUpdatesAvailable) {
widget.url = sourceRepoUrl;
} else {
if (!widgetParams.areRepoUpdatesAvailable) {
let userinfo = await traewelling.getUserInfo();
widget.url = `https://traewelling.de/@${userinfo.data.username}`;
}
Expand Down Expand Up @@ -340,7 +349,7 @@ async function createWidget(traewelling, widgetParams) {
}

if (widgetParams.areRepoUpdatesAvailable)
subtitle = "update available";
subtitle = "click to update";

let widgetFamily = config.widgetFamily;
if (widgetFamily === undefined) {
Expand Down

0 comments on commit 55b7df5

Please sign in to comment.