02-10-2024 08:24 - edited 02-13-2024 08:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


02-10-2024 08:24 - edited 02-13-2024 08:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Has anyone managed to get Cluster Storage working for sharing data between 2 apps/clocks?
Can they share an example and confirm that the sharing is done at the watch level.
It should be noted that normally each clock/app has it's own private watch storage which possibly suggests that there must be some public watch storage which can be used for sharing.
Author | ch, passion for improvement.
Answered! Go to the Best Answer.

Accepted Solutions
02-13-2024 15:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


02-13-2024 15:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Maybe:
import * as appClusterStorage from 'app-cluster-storage'
const cluster = appClusterStorage.get('gondwana')
console.log(cluster) // should be [object Object]
cluster.setItem('testKey', 'testValue')
const testVar = cluster.getItem('testKey')
console.log(testVar)
I have no way of testing this, since I don't have any relevant watches and I suspect it isn't implemented in the sim.
Gondwana Software
02-12-2024 21:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

02-12-2024 21:19
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Do you mean Cluster Storage? If so, the data would be shared among multiple apps/clock faces via smartphone. I'm sorry I don't have its working example though.

02-13-2024 07:27 - edited 02-13-2024 07:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


02-13-2024 07:27 - edited 02-13-2024 07:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks @r.b - I do mean App Cluster storage.- when I tested it a while back there was no success.
In the package.json permission was requested and the following included
"requestedPermissions": [
"access_app_cluster_storage"
],
"appClusterID": "public",
"developerID": "<your developerID>"
but it doesn't seems to help - the instruction won't build as it has a syntax error
app-cluster-storage.get(clusterID: "public")
And no means is given to set the storage.
There seems also to be a confusion as to whether this is a companion feature, some say it is a watch storage and others a phone storage.
You probably need some import too like
import { appClusterStorage } from "app-cluster-storage";
But even then appClusterStorage is undefined.
Anybody have any ideas to try?
Author | ch, passion for improvement.

02-13-2024 13:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


02-13-2024 13:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Two quick thoughts that probably won't help:
- Get it working in companion first, because we know it's implemented there. Once the syntax is correct in that context, try it in device.
- kpay uses cluster storage (in companion, I assume); you could dredge though kpay debug source for clues.
Re app-cluster-storage.get(clusterID: "public"), I know where you got that from. In JS, hyphens are subtraction so that's a documentation error.
Gondwana Software

02-13-2024 15:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


02-13-2024 15:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Maybe:
import * as appClusterStorage from 'app-cluster-storage'
const cluster = appClusterStorage.get('gondwana')
console.log(cluster) // should be [object Object]
cluster.setItem('testKey', 'testValue')
const testVar = cluster.getItem('testKey')
console.log(testVar)
I have no way of testing this, since I don't have any relevant watches and I suspect it isn't implemented in the sim.
Gondwana Software
02-13-2024 21:26 - edited 04-22-2024 00:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


02-13-2024 21:26 - edited 04-22-2024 00:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Bingo! It works within an App.
This confirms it is on watch storage and no need for the companion and phone storage.
Curiously it causes the simulator to crash the watch, instead of not working.
Thank you, you are a Star!
Author | ch, passion for improvement.
04-21-2024 23:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-21-2024 23:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Gondwana- do you think appClusterStorage has something like appClusterStorage.addEventListener("change", () => {}); ?
It raises an error in the Simulator, may be only because cluster storage is not properly implemented or the syntax is wrong.
Hopefully there is some way of seeing if a change has been made to the storage?
Author | ch, passion for improvement.

04-21-2024 23:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-21-2024 23:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I don't think Device SDK in sim implements cluster storage. Try a real watch. I can't because I don't have any left.
Gondwana Software

04-22-2024 00:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2024 00:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
even on the watch it says expected a function
Author | ch, passion for improvement.

04-22-2024 00:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2024 00:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You could try setting .onchange directly. Total guess...
Gondwana Software

04-22-2024 00:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2024 00:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
appClusterStorage.onchange = function() {
console.log(` detected a change.`);}
Doesn't get triggered when a change is made in the same app.
Author | ch, passion for improvement.

04-22-2024 00:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2024 00:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It's possible that it doesn't implement the LiveStorage interface.
But have you verified that your appClusterStorage var is of the right type? Eg, does it respond correctly to .setItem(), etc?
Gondwana Software

04-22-2024 01:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2024 01:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yes it's working fine, but it means testing values to see if they change, so looking for a way to trap the change to improve it.
Author | ch, passion for improvement.

04-22-2024 02:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

SunsetRunner
04-22-2024 02:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
If you can't attach an eventListener, why not wrap the update in a function checking the getItem against newValue after having set?

04-22-2024 13:15 - edited 04-22-2024 13:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2024 13:15 - edited 04-22-2024 13:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@SunsetRunnergot me thinking about this...
Since only one app can be running at any one time, an app should only need to check for changes made by other apps when it starts. App B can't change storage while App A is running. Internally, App A can communicate its own storage changes using other means. So it may not be necessary for cluster storage to have change events on the device.
I probably didn't explain this well, and I could be wrong.
Gondwana Software

