Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I re-save the setting type 'Select' in the app\index.js?

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...

 

Best Answer
0 Votes
5 REPLIES 5

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!

Best Answer
0 Votes
Hi. Yes about clock face. Sorry.Sent from my Samsung Galaxy smartphone.
Best Answer
0 Votes

Hi John - please delete this question. Now that I understand the forum structure better, I'll re-post. Thanks, Mark

Best Answer
0 Votes

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?

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes