Hi all,
Is there a way to detect that a user has changed the time display settings (ie: 12 to 24 hour display or vice versa)? Perhaps an eventListener?
At the moment I have a clock face that updates (clock.granularity) every minute. If the user changes the display from 12 to 24 hour then the time will not update until the minute ticks over. I can change clock.granularity to "seconds" to get around the problem but this seems wasteful.
Thanks 🙂
Best AnswerThere are events and eventlisteners within the SDK but I don't believe if there is one for a change in the time display settings or more general for a change in preferences.
According to https://dev.fitbit.com/build/reference/device-api/events/ there are some interfaces including EventListener and EventTarget. On the page there is a list which interfaces implement the EventTarget interface but the preferences interface is not one of them according to the references. So I don't think there is such an event as far as I can find in the references. I could be wrong though but then someone with more knowledge of the API would need to help you further.
Best AnswerAs I understand, if the "user-settings" api would have implemented EventTarget you could have added an eventListener like you could do with the "power" api. From the power api:
addEventListener() Returns: void Add an event handler for the change event. This event is emitted whenever a change occurs in the state of the charger (when the charger is connected or disconnected, and/or when the quality of the power received from the charger changes). power.addEventListener(type: "change", listener: (this: Charger, event: Event) => any)
So I'm afraid that a direct event from the "user-settings" would not be possible.
Best AnswerThanks all.
Thinking about it further, I probably don't need to detect it since, as far as I know, you can't change that setting on the watch from within a clock face. You actually need to open settings/preferences, change it there, and then restart the clock face which will update the display.
Does that sound reasonable?
Best AnswerYeah, if the watch resets every time you open it should be enough to check the user settings upon initialization. That's how I see it.
Best AnswerWhile looking into code examples I came across this piece of code:
// A user changes Settings
settingsStorage.onchange = evt => {
if (evt.key === "oauth") {
// Settings page sent us an oAuth token
let data = JSON.parse(evt.newValue);
fetchSleepData(data.access_token) ;
}
};The full code is here.
Maybe it is possible to get an onchange event on the user-settings which you can then check for change in time display? This piece of code is for the companion and settings though but I guess it's worth a shot to try something like this to see if it's possible:
import { preferences } from "user-settings";
preferences.onchange = evt => {
console.log('Preferences onchange evt.key:' + evt.key);
};
Could someone else, a Fitbit developer maybe, confirm if this is possible or not?
Best Answer