Skip to content

Commit eec3d89

Browse files
authored
Merge pull request espruino#3651 from bobrippling/feat/settings-var-cache
messages: settings only loads from storage once
2 parents b6da987 + 9b19fa1 commit eec3d89

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

apps/messages/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
0.61: Add repeatCalls option to allow different repeat settings for messages vs calls
88
0.62: Add option for driving on left (affects roundabout icons in navigation)
99
0.63: Add option to not open the first unread message
10+
0.64: Only load from storage once in settings

apps/messages/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "messages",
33
"name": "Messages",
4-
"version": "0.63",
4+
"version": "0.64",
55
"description": "Library to handle, load and store message events received from Android/iOS",
66
"icon": "app.png",
77
"type": "module",

apps/messages/settings.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function(back) {
22
const iconColorModes = ['color', 'mono'];
33

4-
function settings() {
4+
function loadSettings() {
55
let settings = require('Storage').readJSON("messages.settings.json", true) || {};
66
if (settings.vibrate===undefined) settings.vibrate=":";
77
if (settings.vibrateCalls===undefined) settings.vibrateCalls=":";
@@ -19,42 +19,42 @@
1919
return settings;
2020
}
2121
function updateSetting(setting, value) {
22-
let settings = require('Storage').readJSON("messages.settings.json", true) || {};
2322
settings[setting] = value;
2423
require('Storage').writeJSON("messages.settings.json", settings);
2524
}
25+
var settings = loadSettings();
2626

2727
var mainmenu = {
2828
"" : { "title" : /*LANG*/"Messages" },
2929
"< Back" : back,
30-
/*LANG*/'Vibrate': require("buzz_menu").pattern(settings().vibrate, v => updateSetting("vibrate", v)),
31-
/*LANG*/'Vibrate for calls': require("buzz_menu").pattern(settings().vibrateCalls, v => updateSetting("vibrateCalls", v)),
30+
/*LANG*/'Vibrate': require("buzz_menu").pattern(settings.vibrate, v => updateSetting("vibrate", v)),
31+
/*LANG*/'Vibrate for calls': require("buzz_menu").pattern(settings.vibrateCalls, v => updateSetting("vibrateCalls", v)),
3232
/*LANG*/'Repeat': {
33-
value: settings().repeat,
33+
value: settings.repeat,
3434
min: 0, max: 10,
3535
format: v => v?v+"s":/*LANG*/"Off",
3636
onchange: v => updateSetting("repeat", v)
3737
},
3838
/*LANG*/'Repeat for calls': {
39-
value: settings().repeatCalls,
39+
value: settings.repeatCalls,
4040
min: 0, max: 10,
4141
format: v => v?v+"s":/*LANG*/"Off",
4242
onchange: v => updateSetting("repeatCalls", v)
4343
},
4444
/*LANG*/'Vibrate timer': {
45-
value: settings().vibrateTimeout,
46-
min: 0, max: settings().maxUnreadTimeout, step : 10,
45+
value: settings.vibrateTimeout,
46+
min: 0, max: settings.maxUnreadTimeout, step : 10,
4747
format: v => v?v+"s":/*LANG*/"Off",
4848
onchange: v => updateSetting("vibrateTimeout", v)
4949
},
5050
/*LANG*/'Unread timer': {
51-
value: settings().unreadTimeout,
52-
min: 0, max: settings().maxUnreadTimeout, step : 10,
51+
value: settings.unreadTimeout,
52+
min: 0, max: settings.maxUnreadTimeout, step : 10,
5353
format: v => v?v+"s":/*LANG*/"Off",
5454
onchange: v => updateSetting("unreadTimeout", v)
5555
},
5656
/*LANG*/'Min Font': {
57-
value: 0|settings().fontSize,
57+
value: 0|settings.fontSize,
5858
min: 0, max: 1,
5959
format: v => [/*LANG*/"Small",/*LANG*/"Medium"][v],
6060
onchange: v => updateSetting("fontSize", v)
@@ -64,39 +64,39 @@
6464
onchange: v => updateSetting("ignoreUnread", v)
6565
},
6666
/*LANG*/'Auto-Open Music': {
67-
value: !!settings().openMusic,
67+
value: !!settings.openMusic,
6868
onchange: v => updateSetting("openMusic", v)
6969
},
7070
/*LANG*/'Unlock Watch': {
71-
value: !!settings().unlockWatch,
71+
value: !!settings.unlockWatch,
7272
onchange: v => updateSetting("unlockWatch", v)
7373
},
7474
/*LANG*/'Flash Icon': {
75-
value: !!settings().flash,
75+
value: !!settings.flash,
7676
onchange: v => updateSetting("flash", v)
7777
},
7878
/*LANG*/'Quiet mode disables auto-open': {
79-
value: !!settings().quietNoAutOpn,
79+
value: !!settings.quietNoAutOpn,
8080
onchange: v => updateSetting("quietNoAutOpn", v)
8181
},
8282
/*LANG*/'Disable auto-open': {
83-
value: !!settings().noAutOpn,
83+
value: !!settings.noAutOpn,
8484
onchange: v => updateSetting("noAutOpn", v)
8585
},
8686
/*LANG*/'Widget messages': {
87-
value:0|settings().maxMessages,
87+
value:0|settings.maxMessages,
8888
min: 0, max: 5,
8989
format: v => v ? v :/*LANG*/"Hide",
9090
onchange: v => updateSetting("maxMessages", v)
9191
},
9292
/*LANG*/'Icon color mode': {
93-
value: Math.max(0,iconColorModes.indexOf(settings().iconColorMode)),
93+
value: Math.max(0,iconColorModes.indexOf(settings.iconColorMode)),
9494
min: 0, max: iconColorModes.length - 1,
9595
format: v => iconColorModes[v],
9696
onchange: v => updateSetting("iconColorMode", iconColorModes[v])
9797
},
9898
/*LANG*/'Car driver pos': { // used by messagegui
99-
value:!!settings().carIsRHD,
99+
value:!!settings.carIsRHD,
100100
format: v => v ? /*LANG*/"Right" :/*LANG*/"Left",
101101
onchange: v => updateSetting("carIsRHD", v)
102102
},

0 commit comments

Comments
 (0)