Good evening fitbit community. I have successfully managed to create a watch face with a companion for changing the background colour.
Now when it is running in developer mode, I select the background colour and it changes fine and is fine most of the time.......except when I select another App (music, today, exercise etc) then back out of that App, the watch face then defaults to its original colour and not the one I had selected moments earlier.
Is this just because it's in the developer mode that its not saving the setting or is there something I am missing?
Thanks in advance
Answered! Go to the Best Answer.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Something like this in your app/index.js
import { me } from "appbit";
import * as fs from "fs";
const SETTINGS_FILE = "settings.json";
let settings = loadSettings();
applyTheme();
messaging.peerSocket.onmessage = function(evt) {
settings.myColor = evt.data.value;
applyTheme();
}
function applyTheme() {
myElement.style.fill = settings.myColor;
}
function loadSettings() {
let obj;
try {
obj = fs.readFileSync(SETTINGS_FILE, "json");
} catch(ex) {
obj = {
myColor: "#FFFFFF"
}
}
return obj;
}
me.onunload = () => {
fs.writeFileSync(SETTINGS_FILE, settings, "json");
}
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Are you saving/loading that setting somewhere?
You can see an example of saving the value on the device, then you can load it again when the clock relaunches.
Best AnswerThanks for the reply but I am using the example in the fitbit docs here: https://dev.fitbit.com/build/guides/settings/
I looked at your code but can not work out which bit would relate to this example code as I'm not using a theme (foreground, background)
So how would I save and reload settings using that example code (i've used it as it is)
Thanks again.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Something like this in your app/index.js
import { me } from "appbit";
import * as fs from "fs";
const SETTINGS_FILE = "settings.json";
let settings = loadSettings();
applyTheme();
messaging.peerSocket.onmessage = function(evt) {
settings.myColor = evt.data.value;
applyTheme();
}
function applyTheme() {
myElement.style.fill = settings.myColor;
}
function loadSettings() {
let obj;
try {
obj = fs.readFileSync(SETTINGS_FILE, "json");
} catch(ex) {
obj = {
myColor: "#FFFFFF"
}
}
return obj;
}
me.onunload = () => {
fs.writeFileSync(SETTINGS_FILE, settings, "json");
}
Excellent, I now have it working, thanks for the advice, much appreciated. 🙂
Best Answer