BangleApps/apps/flashcards/settings.js

79 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-07-07 16:51:40 +00:00
(function(back) {
var storage = require("Storage");
var settingsFile = "flashcards.settings.json";
2023-07-07 16:51:40 +00:00
var dataFile = "flashcards.data.json";
var trelloTimeout = 3000;
var trelloURL = "https://api.trello.com/1/lists/$cardsListId/cards/?fields=name%2Cdesc%2Clist";
var settings = Object.assign({
2023-07-08 12:05:10 +00:00
listId: "",
fontSize: 1,
cardWidth: 9,
swipeGesture: 0
}, storage.readJSON(settingsFile, true) || {});
2023-07-07 16:51:40 +00:00
function writeSettings() {
storage.writeJSON(settingsFile, settings);
2023-07-07 16:51:40 +00:00
}
const fontSizes = [/*LANG*/"Small",/*LANG*/"Medium",/*LANG*/"Large"];
const swipeGestures = [/*LANG*/"Stroke",/*LANG*/"Drag"];
2023-07-07 16:51:40 +00:00
var settingsMenu = {
"" : { "title" : "Flash Cards" },
"< Back" : () => back(),
2023-07-08 12:05:10 +00:00
/*LANG*/"Get from Trello": () => {
2023-07-07 18:44:29 +00:00
if (!storage.read(settingsFile)) { writeSettings();}
2023-07-07 16:51:40 +00:00
E.showPrompt("Download cards?").then((v) => {
let delay = 500;
if (v) {
if (Bangle.http)
{
if (settings.listId)
2023-07-07 16:51:40 +00:00
{
delay = delay + trelloTimeout;
E.showMessage('i: downloading');
Bangle.http(trelloURL.replace("$cardsListId", settings.listId),
{
timeout : trelloTimeout,
method: "GET",
headers: { "Content-Type": "application/json" }
}).then(data=>{
var cardsJSON = JSON.parse(data.resp);
2023-07-07 18:11:45 +00:00
storage.write(dataFile, JSON.stringify(cardsJSON));
2023-07-07 16:51:40 +00:00
E.showMessage('i: downloaded');
})
.catch((e) => {
E.showMessage("e: " + e);
});
} else {
E.showMessage("e: list Id not found");
}
} else {
E.showMessage("e: Gadgetbridge not found");
}
}
setTimeout(() => E.showMenu(settingsMenu), delay);
});
},
/*LANG*/"Font size": {
value: settings.fontSize,
min: 0, max: 2, wrap: true,
format: v => fontSizes[v],
onchange: v => { settings.fontSize = v; writeSettings(); }
},
/*LANG*/"Card width": {
value: settings.cardWidth,
min: 6, max: 12,
onchange: v => { settings.cardWidth = v; writeSettings(); }
},
/*LANG*/"Swipe gesture": {
value: settings.swipeGesture,
min: 0, max: 1, wrap: true,
format: v => swipeGestures[v],
onchange: v => { settings.swipeGesture = v; writeSettings(); }
2023-07-07 16:51:40 +00:00
}
}
// Show the menu
E.showMenu(settingsMenu);
})//(load)