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

Import problems with settings

Hello Ionic-Devs,

 

I'm trying to import some helper functions in my settings/index.jsx that I want to use also in the companion but I did not get it running:

 

companion/config.js:

import { settingsStorage } from "settings";

export function setDefaults()
{
...
}

settings/index.jsx:

import * as config from "../companion/config.js";

function clear(props)
{
  config.setDefaults();
  return;
}

...

The compiler error message is:

settings is imported by companion/config.js, but could not be resolved

Did anybody have some hints?

 

Best regards,

 

Grizzi

 

Best Answer
0 Votes
12 REPLIES 12

Have you tried putting config.js inside the /common folder, then referencing it from there? Just a guess. 

Best Answer
0 Votes

Were you able to find any workaround?

Best Answer
0 Votes

Hello!

 

I'm having the same trouble, too. 

I encountered this in a project I'm currently working it. To make sure I didn't mess it up by myself, I started a blank project and gave it try. It resulted in the same issue. 

 

In first place I created the blank starter project and put this code in the app/index.js:

 

import { settingsStorage } from "settings";
settingsStorage.setItem("myKey", "test");

console.log("App code started");

Which results in: 

settings is imported by app/index.js, but could not be resolved
Build failed.

After that I tried what @JonFitbit suggested and put it into the /common-folder: 

 

app/index.js: 

import Test from "../common/test"

console.log("App code started");

let test = new Test();
test.retrieveValue();

common/test.js:

import { settingsStorage } from "settings";

export default class Test {
  constructor() {
    settingsStorage.setItem("myKey", "test");
  }
  
  retrieveValue() {
    console.log(settingsStorage.getItem("myKey"));
  }
}

 

And the build fails again: 

settings is imported by common/test.js, but could not be resolved

What am I doing wrong? I don't get it. Smiley Sad

 

Thanks!

Best Answer
0 Votes
and put this code in the app/index.js:

 

import { settingsStorage } from "settings";
settingsStorage.setItem("myKey", "test");

console.log("App code started");

Which results in: 

settings is imported by app/index.js, but could not be resolved
Build failed.

 


settingsStorage is part of the companion api, not the device api. It can only be used in the companion/index.js file.

 

Take a look at the settings guide https://dev.fitbit.com/build/guides/settings/

and the Moment example https://github.com/Fitbit/sdk-moment

Best Answer

The moment you realize: RTFM is the answer. Smiley LOL

Thanks @JonFitbit for your support!

Best Answer
0 Votes

Suspect I'm completely misunderstanding the architecture of the APIs here, but does this mean it's not possible to access settings in the app?

 

What if I want to use a setting in my clock.onTick() section?

Best Answer
0 Votes

You can't DIRECTLY access settings from the watch app, so you're on the right track. You have to use messaging or file transfer to send settings from companion to watch.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thanks for that.

 

So I get that I would use messaging in the case where a user changes the settings in the app - to send the new setting to the app.

 

But I'm trying to format date/time based on user setting so I want to check what's in the settings on each clock.onTick(). Are you saying that I would write those settings to a file to be able to check them at any given point in the app?

Best Answer
0 Votes

Are you talking about changing settings in the .jsx bit of your app, or other settings in the Fitbit app (eg, 12/24-hour time display formatting)?

 

You don't need settings to be stored in a file on the watch to be able to access them in onTick(). Variables will do. But you'll probably want to store them in a file on the watch so you can reinitialise the variables if the user restarts your clockface.

 

I think there's a sample of all this somewhere; it might be here.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Yes, I'm talking about settings set in the .jsx.

 

So the use case would be:

 

- Set a setting in app on phone.It's a <Toggle/> selector that will have a boolean value.

- Refer to that setting in onTick() section of app.

 

Happy to refer to variable in the app - just can't work out where to get the value from.

I've looked at that example app that you posted but couldn't quite see where it does this.

Best Answer
0 Votes

You've left a lot of steps out of your outline.

  • Set a setting in app on phone.It's a <Toggle/> selector that will have a boolean value.
  • Detect the .jsx setting change in your companion code.
  • Send the setting from companion to clockface (messaging or file transfer).
  • Receive setting in clockface (messaging or file transfer).
  • Save setting in a variable in clockface.
  • Refer to that setting in onTick() section of app.

This ignores the desirability of saving and restoring settings on the clockface to streamline restarts.

Peter McLennan
Gondwana Software
Best Answer

Thanks again for your help. Got there in the end.

Best Answer
0 Votes