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

Is this a bug?

ANSWERED

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

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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");
}

View best answer in original post

Best Answer
4 REPLIES 4

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.

 

https://github.com/orviwan/fitbit-cliff-star-clock

Best Answer
0 Votes

Thanks 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
0 Votes

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");
}
Best Answer

Excellent, I now have it working, thanks for the advice, much appreciated. 🙂

Best Answer
0 Votes