04-10-2020 11:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-10-2020 11:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello - I'm using a 'Select' type setting, but I can't figure out how to save it back in the main code (app\index.js). Other types work OK (e.g. Slider), but I can't figure out this one.
I can read the setting OK, to use it - but not write it back when it's been changed in the phone settings.
Setting is read as, for example: {"values":[{"name":"90s","value":"2"}],"selected":[2]} so I have to use string manipulation to get the required value.
settings.index.jsx (partial):
<Select
settingsKey="ledtheme"
label="Theme"
options={[
{name:"70s", value:"0"},
{name:"80s", value:"1"},
{name:"90s", value:"2"},
{name:"60s", value:"3"},
{name:"Custom", value:"4"}
]}
/>
companion/index.js (partial):
if (me.launchReasons.settingsChanged) {
// Send the value of the setting
sendValue(KEY_THEME, settingsStorage.getItem(KEY_THEME));
}
function sendValue(key, val) {
if (val) {
sendSettingData({
key: key,
value: JSON.parse(val)
});
}
}
app\index.js (partial):
// Apply theme colors to elements
function applySettingTheme(ledtheme) {
let ledthemeval = JSON.stringify(ledtheme).slice(-3).slice(0, 1); //only way I can figure to get the value
switch (ledthemeval) {
case "0": //70s
colBackground = COL0_SEVENTIES;
colTime = COL1_SEVENTIES;
break;
case "1": //80s
colBackground = COL0_EIGHTIES;
colTime = COL1_EIGHTIES;
break;
case "2": //90s
colBackground = COL0_NINETIES;
colTime = COL1_NINETIES;
break;
case "3": //60s
colBackground = COL0_SIXTIES;
colTime = COL1_SIXTIES;
break;
case "4": //custom
colBackground = settingColBackground;
colTime = settingColTime;
break;
default:
}
console.log("applySettingTheme (settings.ledtheme): " + settings.ledtheme);
settings.ledtheme = ledthemeval; //I've tried all sorts here... ledtheme / stringify ledtheme too
console.log("applySettingTheme (ledthemeval): " + ledthemeval);
console.log("applySettingTheme (json.stringify(ledtheme)): " + JSON.stringify(ledtheme));
}
Thanks for any insights...

- Labels:
-
JavaScript
04-13-2020 12:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



04-13-2020 12:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @MarkEMarkEMark,
Welcome to the forums!
Is this a question about your clockface? If so, I'll need to move your thread to the SDK forum.
Hope to hear from you soon!

04-13-2020 12:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-13-2020 12:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-14-2020 02:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-14-2020 02:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi John - please delete this question. Now that I understand the forum structure better, I'll re-post. Thanks, Mark

04-14-2020 14:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-14-2020 14:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi; just me again. 🙂 I'll try to stay focused on the question this time. 🙂
When you say "save it back", can you explain where you're trying to save the setting, and how it got changed?
If the change was done by the user, the new value would normally be saved in settingsStorage automatically (assuming you're using a 'managed' approach).
If you're changing the setting in JS code, that's another story. There's a way to write it back, but is this what you want?
Gondwana Software

04-14-2020 14:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-14-2020 14:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
PS. The inclusion of app/index.js code is confusing me. That code runs on the watch, which doesn't have direct access to settingsStorage, which only exists on the phone.
Gondwana Software

