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

Group Storage - Cluster Storage

ANSWERED

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.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
14 REPLIES 14

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.

Best Answer
0 Votes

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.

Best Answer
0 Votes

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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.

Peter McLennan
Gondwana Software
Best Answer

Bingo! It works within an App.

20240214_061945.jpg

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.

Best Answer

@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.

Best Answer
0 Votes

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

even on the watch it says expected a function

Author | ch, passion for improvement.

Best Answer
0 Votes

You could try setting .onchange directly. Total guess...

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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.

Best Answer
0 Votes

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?

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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.

Best Answer
0 Votes

If you can't attach an eventListener, why not wrap the update in a function checking the getItem against newValue after having set?

Best Answer
0 Votes

@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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes