Merge pull request #3651 from bobrippling/feat/settings-var-cache

messages: settings only loads from storage once
master
Gordon Williams 2024-11-11 13:49:46 +00:00 committed by GitHub
commit eec3d89b45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 20 deletions

View File

@ -7,3 +7,4 @@
0.61: Add repeatCalls option to allow different repeat settings for messages vs calls 0.61: Add repeatCalls option to allow different repeat settings for messages vs calls
0.62: Add option for driving on left (affects roundabout icons in navigation) 0.62: Add option for driving on left (affects roundabout icons in navigation)
0.63: Add option to not open the first unread message 0.63: Add option to not open the first unread message
0.64: Only load from storage once in settings

View File

@ -1,7 +1,7 @@
{ {
"id": "messages", "id": "messages",
"name": "Messages", "name": "Messages",
"version": "0.63", "version": "0.64",
"description": "Library to handle, load and store message events received from Android/iOS", "description": "Library to handle, load and store message events received from Android/iOS",
"icon": "app.png", "icon": "app.png",
"type": "module", "type": "module",

View File

@ -1,7 +1,7 @@
(function(back) { (function(back) {
const iconColorModes = ['color', 'mono']; const iconColorModes = ['color', 'mono'];
function settings() { function loadSettings() {
let settings = require('Storage').readJSON("messages.settings.json", true) || {}; let settings = require('Storage').readJSON("messages.settings.json", true) || {};
if (settings.vibrate===undefined) settings.vibrate=":"; if (settings.vibrate===undefined) settings.vibrate=":";
if (settings.vibrateCalls===undefined) settings.vibrateCalls=":"; if (settings.vibrateCalls===undefined) settings.vibrateCalls=":";
@ -19,42 +19,42 @@
return settings; return settings;
} }
function updateSetting(setting, value) { function updateSetting(setting, value) {
let settings = require('Storage').readJSON("messages.settings.json", true) || {};
settings[setting] = value; settings[setting] = value;
require('Storage').writeJSON("messages.settings.json", settings); require('Storage').writeJSON("messages.settings.json", settings);
} }
var settings = loadSettings();
var mainmenu = { var mainmenu = {
"" : { "title" : /*LANG*/"Messages" }, "" : { "title" : /*LANG*/"Messages" },
"< Back" : back, "< Back" : back,
/*LANG*/'Vibrate': require("buzz_menu").pattern(settings().vibrate, v => updateSetting("vibrate", v)), /*LANG*/'Vibrate': require("buzz_menu").pattern(settings.vibrate, v => updateSetting("vibrate", v)),
/*LANG*/'Vibrate for calls': require("buzz_menu").pattern(settings().vibrateCalls, v => updateSetting("vibrateCalls", v)), /*LANG*/'Vibrate for calls': require("buzz_menu").pattern(settings.vibrateCalls, v => updateSetting("vibrateCalls", v)),
/*LANG*/'Repeat': { /*LANG*/'Repeat': {
value: settings().repeat, value: settings.repeat,
min: 0, max: 10, min: 0, max: 10,
format: v => v?v+"s":/*LANG*/"Off", format: v => v?v+"s":/*LANG*/"Off",
onchange: v => updateSetting("repeat", v) onchange: v => updateSetting("repeat", v)
}, },
/*LANG*/'Repeat for calls': { /*LANG*/'Repeat for calls': {
value: settings().repeatCalls, value: settings.repeatCalls,
min: 0, max: 10, min: 0, max: 10,
format: v => v?v+"s":/*LANG*/"Off", format: v => v?v+"s":/*LANG*/"Off",
onchange: v => updateSetting("repeatCalls", v) onchange: v => updateSetting("repeatCalls", v)
}, },
/*LANG*/'Vibrate timer': { /*LANG*/'Vibrate timer': {
value: settings().vibrateTimeout, value: settings.vibrateTimeout,
min: 0, max: settings().maxUnreadTimeout, step : 10, min: 0, max: settings.maxUnreadTimeout, step : 10,
format: v => v?v+"s":/*LANG*/"Off", format: v => v?v+"s":/*LANG*/"Off",
onchange: v => updateSetting("vibrateTimeout", v) onchange: v => updateSetting("vibrateTimeout", v)
}, },
/*LANG*/'Unread timer': { /*LANG*/'Unread timer': {
value: settings().unreadTimeout, value: settings.unreadTimeout,
min: 0, max: settings().maxUnreadTimeout, step : 10, min: 0, max: settings.maxUnreadTimeout, step : 10,
format: v => v?v+"s":/*LANG*/"Off", format: v => v?v+"s":/*LANG*/"Off",
onchange: v => updateSetting("unreadTimeout", v) onchange: v => updateSetting("unreadTimeout", v)
}, },
/*LANG*/'Min Font': { /*LANG*/'Min Font': {
value: 0|settings().fontSize, value: 0|settings.fontSize,
min: 0, max: 1, min: 0, max: 1,
format: v => [/*LANG*/"Small",/*LANG*/"Medium"][v], format: v => [/*LANG*/"Small",/*LANG*/"Medium"][v],
onchange: v => updateSetting("fontSize", v) onchange: v => updateSetting("fontSize", v)
@ -64,39 +64,39 @@
onchange: v => updateSetting("ignoreUnread", v) onchange: v => updateSetting("ignoreUnread", v)
}, },
/*LANG*/'Auto-Open Music': { /*LANG*/'Auto-Open Music': {
value: !!settings().openMusic, value: !!settings.openMusic,
onchange: v => updateSetting("openMusic", v) onchange: v => updateSetting("openMusic", v)
}, },
/*LANG*/'Unlock Watch': { /*LANG*/'Unlock Watch': {
value: !!settings().unlockWatch, value: !!settings.unlockWatch,
onchange: v => updateSetting("unlockWatch", v) onchange: v => updateSetting("unlockWatch", v)
}, },
/*LANG*/'Flash Icon': { /*LANG*/'Flash Icon': {
value: !!settings().flash, value: !!settings.flash,
onchange: v => updateSetting("flash", v) onchange: v => updateSetting("flash", v)
}, },
/*LANG*/'Quiet mode disables auto-open': { /*LANG*/'Quiet mode disables auto-open': {
value: !!settings().quietNoAutOpn, value: !!settings.quietNoAutOpn,
onchange: v => updateSetting("quietNoAutOpn", v) onchange: v => updateSetting("quietNoAutOpn", v)
}, },
/*LANG*/'Disable auto-open': { /*LANG*/'Disable auto-open': {
value: !!settings().noAutOpn, value: !!settings.noAutOpn,
onchange: v => updateSetting("noAutOpn", v) onchange: v => updateSetting("noAutOpn", v)
}, },
/*LANG*/'Widget messages': { /*LANG*/'Widget messages': {
value:0|settings().maxMessages, value:0|settings.maxMessages,
min: 0, max: 5, min: 0, max: 5,
format: v => v ? v :/*LANG*/"Hide", format: v => v ? v :/*LANG*/"Hide",
onchange: v => updateSetting("maxMessages", v) onchange: v => updateSetting("maxMessages", v)
}, },
/*LANG*/'Icon color mode': { /*LANG*/'Icon color mode': {
value: Math.max(0,iconColorModes.indexOf(settings().iconColorMode)), value: Math.max(0,iconColorModes.indexOf(settings.iconColorMode)),
min: 0, max: iconColorModes.length - 1, min: 0, max: iconColorModes.length - 1,
format: v => iconColorModes[v], format: v => iconColorModes[v],
onchange: v => updateSetting("iconColorMode", iconColorModes[v]) onchange: v => updateSetting("iconColorMode", iconColorModes[v])
}, },
/*LANG*/'Car driver pos': { // used by messagegui /*LANG*/'Car driver pos': { // used by messagegui
value:!!settings().carIsRHD, value:!!settings.carIsRHD,
format: v => v ? /*LANG*/"Right" :/*LANG*/"Left", format: v => v ? /*LANG*/"Right" :/*LANG*/"Left",
onchange: v => updateSetting("carIsRHD", v) onchange: v => updateSetting("carIsRHD", v)
}, },