06-12-2018 13:11
06-12-2018 13:11
Hi,
I have a watch face working with persistent storage, but I found that when the companion starts for the first time all the controls have no default values.
So I set the values to the defaults as needed like this in the companion app:
if (!settingsStorage.getItem("screen1")) { settingsStorage.setItem("screen1", JSON.stringify({"selected":[1],"values":[{"name":"Heart"}]})); }; etc.
The user selects their choice and the values are saved in the filesystem on the device. That is OK until the watch face app is updated. Then the companion app is new and displays the default values again even though the new device app is reading the filesystem and using the expected (persistent/carried over) user defaults. So now the two clash.
Option 1: Is there any way to read the device filesystem from the companion? Or a way to send data device to companion.
Option 2: (not preferred) Is there a way to know the device app is newly installed and thus delete the current user settings and return to the defaults.
Or perhaps I am just approaching this in the wrong way?
Many thanks for any advice on this one.
MarkB
06-12-2018 13:54
06-12-2018 13:54
I'm not sure that you should allow settings to be changed in two places (if that's the case).
You can communicate from watch to companion using the messaging API (but it's a bit flakey and things will still look out of whack if the communication fails).
06-12-2018 14:08
06-12-2018 14:08
thanks but I am not trying to change the settings from the watch normally, but a reinstall does not appear to be clean. It leaves the old file system file behind.
So I would really like the companion to just initialise properly. With defaults that both device and companion can agree on. I did not know the connection was flaky, but thought the message checks would catch those cases.
06-22-2018 11:13
06-22-2018 11:13
Any word on this? I would like my companion and watch to agree even when updating.
06-22-2018 22:58 - edited 06-22-2018 23:57
06-22-2018 22:58 - edited 06-22-2018 23:57
You can force a clean install yourself if you implement a software version in a file. Here's how I did it.
// in the beginning of your app/index.js: import * as fs from "fs"; const thisSoftwareVersion = "00000070"; // ... // and then, when you need to access your settings for the first time: let mustWriteVersion = true; try { let storedVersion = fs.readFileSync( "MyVersionFile.txt", "ascii" ); if( storedVersion === thisSoftwareVersion ) { mustWriteVersion = false; // read whatever you need from the device file system } } catch( exc ) { console.log( exc ); } // make sure that you also store your version if( mustWriteVersion ) fs.writeFileSync( "MyVersionFile.txt", thisSoftwareVersion, "ascii" );
"thisSoftwareVersion" can be any string at all - just make sure that you change it between any two updates of your watch face. I just increment the number.
This is also handy in your test environment when you want to test your app with "fresh" settings - again, just increment the number.
06-25-2018 06:28
06-25-2018 06:28
I want to accept this as solution, but it is a solution to Option 2 and I would like this question to stay live for a bit longer in case there is a way to do Option 1. Or perhaps Fitbit improve the companion and add support for defaults.
And thanks for your suggestion.
MarkB