Persist user settings
parent
20ad2efbd4
commit
cab228f47e
|
|
@ -914,7 +914,7 @@
|
|||
{ "id": "marioclock",
|
||||
"name": "Mario Clock",
|
||||
"icon": "marioclock.png",
|
||||
"version":"0.10",
|
||||
"version":"0.11",
|
||||
"description": "Animated retro Mario clock, with Gameboy style 8-bit grey-scale graphics.",
|
||||
"tags": "clock,mario,retro",
|
||||
"type": "clock",
|
||||
|
|
|
|||
|
|
@ -8,3 +8,4 @@
|
|||
0.08: Update date panel to be info panel toggling between Date, Battery and Temperature. Add Princes Daisy
|
||||
0.09: Add GadgetBridge functionality. Mario shows message type in speach bubble, while message scrolls in info panel
|
||||
0.10: Swiping left to enable night-mode now also reduces LCD brightness through 3 levels before returning to day-mode.
|
||||
0.11: User settings persisted and read to file.
|
||||
|
|
@ -81,6 +81,16 @@ const phone = {
|
|||
messageType: null,
|
||||
};
|
||||
|
||||
const SETTINGS_FILE = "marioclock.json";
|
||||
|
||||
function readSettings() {
|
||||
return require('Storage').readJSON(SETTINGS_FILE, 1) || {};
|
||||
}
|
||||
|
||||
function writeSettings(newSettings) {
|
||||
require("Storage").writeJSON(SETTINGS_FILE, newSettings);
|
||||
}
|
||||
|
||||
function phoneOutbound(msg) {
|
||||
Bluetooth.println(JSON.stringify(msg));
|
||||
}
|
||||
|
|
@ -567,8 +577,31 @@ function startTimers(){
|
|||
redraw();
|
||||
}
|
||||
|
||||
function loadSettings() {
|
||||
const settings = readSettings();
|
||||
if (!settings) return;
|
||||
|
||||
if (settings.character) characterSprite.character = settings.character;
|
||||
if (settings.nightMode) nightMode = settings.nightMode;
|
||||
if (settings.brightness) {
|
||||
brightness = settings.brightness;
|
||||
Bangle.setLCDBrightness(brightness);
|
||||
}
|
||||
}
|
||||
|
||||
function updateSettings() {
|
||||
const newSettings = {
|
||||
character: characterSprite.character,
|
||||
nightMode: nightMode,
|
||||
brightness: brightness,
|
||||
};
|
||||
writeSettings(newSettings);
|
||||
}
|
||||
|
||||
// Main
|
||||
function init() {
|
||||
loadSettings();
|
||||
|
||||
clearInterval();
|
||||
|
||||
// Initialise display
|
||||
|
|
@ -618,6 +651,8 @@ function init() {
|
|||
default:
|
||||
toggleNightMode();
|
||||
}
|
||||
|
||||
updateSettings();
|
||||
});
|
||||
|
||||
// Phone connectivity
|
||||
|
|
|
|||
Loading…
Reference in New Issue