04-19-2022 11:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-19-2022 11:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi all,
I am creating a very cool Clockface where you can choose from settings which stats you want to see and also other stuff like colors of background, gradient and text.
I have an issue with preselecting the toggles, making some of the stats turn on by default. There is nothing about it in the documentation.
This is my code in settings/index.jsx
const activityOptions = [...]. // array elements here
{activityOptions.map(([title, settingsKey]) =>
<Toggle
settingsKey={settingsKey}
label={title}
/>
)}
Any ideas?
Answered! Go to the Best Answer.

- Labels:
-
App Gallery - Clock
Accepted Solutions
04-19-2022 14:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-19-2022 14:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
You could do what I suggested before in your initialize() function.
Gondwana Software
04-19-2022 12:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-19-2022 12:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @uezbe your post is being moved to the Developer's Forum area. Where you posted is the area where people discuss the apps they have gotten from the Gallery that were already released. I'm sure you'll get more relevant responses once someone sees it in that area.

04-19-2022 13:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-19-2022 13:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Get your companion code to check whether the settingsStorage item already has a value. If it hasn't, give it whatever value selects the toggle (which you can determine by logging what you get in onSettingsChange).
Gondwana Software
04-19-2022 14:07 - edited 04-19-2022 14:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-19-2022 14:07 - edited 04-19-2022 14:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi @Gondwana,
Here is the implementation of the initialize method I call in the companion/index.js
this is a separate file
import * as messaging from "messaging";
import { settingsStorage } from "settings";
export function initialize() {
settingsStorage.addEventListener("change", evt => {
if (evt.oldValue !== evt.newValue) {
sendValue(evt.key, evt.newValue);
}
});
}
function sendValue(key, val) {
if (val) {
sendSettingData({
key: key,
value: JSON.parse(val)
});
}
}
function sendSettingData(data) {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send(data);
} else {
console.log("No peerSocket connection");
}
}
I'm just initializing it
import * as simpleSettings from "./custom/companion-settings";
mySettings.initialize();

04-19-2022 14:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-19-2022 14:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
You could do what I suggested before in your initialize() function.
Gondwana Software
04-19-2022 14:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-19-2022 14:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
