02-02-2019 11:57
02-02-2019 11:57
I have a watch app with settings to control colors of the watch hands, numbers, etc. I'd like to create "themes" that would store all the settings as a group, and allow me to switch themes easily between them.
I have an array of themes like this in my app/index.js:
function getDefaultTheme(name) {
let theme = {};
theme.name=name;
theme.handsColor = 'white';
theme.secHandColor = 'white';
theme.hourNumberColor = 'white';
return theme;
}
let t1 = getDefaultTheme("default1");
let t2 = getDefaultTheme("default2");
settings = {selectedTheme:0, themes:[t1,t2]};
And I save them like this:
const SETTINGS_TYPE = "cbor";
const SETTINGS_FILE = "settings.cbor";
fs.writeFileSync(SETTINGS_FILE, settings, SETTINGS_TYPE);
I can't seem to access the settings in the settings/index.jsx. I have this in the index.jsx:
console.log("In mySettings" + JSON.stringify(props));
and the output is:
[1:30:06 PM] Settings: In mySettings{"settings":{},"settingsStorage":{}}
Both settings and settingsStorage are null.
In the companion app, I have this:
import { settingsStorage } from "settings";
import * as messaging from "messaging";
import { me } from "companion";
let myKeyName = settingsStorage.key(0);
console.log("In companion index.js first key is " + myKeyName);
the output is this:
[1:30:06 PM] Companion: In companion index.js first key is null
Am I missing something?
Answered! Go to the Best Answer.
02-02-2019 13:21 - edited 02-02-2019 14:05
02-02-2019 13:21 - edited 02-02-2019 14:05
As far as I know, the settings module is only available for companion and settings, not in app.
So to sync both worlds (mobile <-> watch) you need to use some messaging magic.
A commonly used pattern is:
Of course, you can share code at build-time, but not data at runtime without any messaging / file-transfer actions.
For example, given the previous checkpoint list:
02-02-2019 12:56
02-02-2019 12:56
Maybe I figured out my problem. I was assuming the settings saved in the app on the device was accessible somehow on the companion app, but that seems to be not true. I think what I need to do is create the initial settings both on the app on the device, and in the companion app, maybe using the common folder so that the code isn't duplicated. Then, the settings index.jsx can see the settings created in the companion app, and if changes are made, they can be sent via a message from the companion to the app on the watch, which will have to save the updated settings in it's own settings file.
The initial settings have to be created on the app running on the watch, in case the user never runs the companion app - the watch app needs to have something to start with.
The initial settings have to be created in the companion also, since it can't see the default settings created on the watch. The app running on the watch can't change the settings, so if the default settings are created the same way on both the watch app and the companion app, then they should be in sync. Any changes made in the companion/settings app will be sent via message to the app, so they should stay in sync if the app saves the updated settings also.
Am I right?
02-02-2019 13:21 - edited 02-02-2019 14:05
02-02-2019 13:21 - edited 02-02-2019 14:05
As far as I know, the settings module is only available for companion and settings, not in app.
So to sync both worlds (mobile <-> watch) you need to use some messaging magic.
A commonly used pattern is:
Of course, you can share code at build-time, but not data at runtime without any messaging / file-transfer actions.
For example, given the previous checkpoint list: