How to read settings?

Asked by Mikko Majander

Hi,

First of all, thank you for the good work on the JavaScript-support! And then to the actual question: I'm not sure if this is my incompetence or maybe the feature isn't supported yet, but I don't quite understand how to get/read the settings from <scope name>-settings.ini. Should it work and if so, how to use it? I didn't find any examples from the JS-scopes in Launchpad.

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
unity-js-scopes Edit question
Assignee:
No assignee Edit question
Solved by:
Mikko Majander
Solved:
Last query:
Last reply:
Revision history for this message
Alexandre Abreu (abreu-alexandre) said :
#1

http://bazaar.launchpad.net/~webapps/unity-js-scopes/trunk/view/head:/examples/simple/simple.js#L23
FAQ #2742: “How to read the scope's settings contained in the .ini file at runtime?”.

Revision history for this message
Mikko Majander (mikko-majander) said :
#2

Thank you, although I think that doesn't quite achieve what I'm looking for or then I didn't understand the example (which I did test). Let's say I have a news-scope and I have listed few news sources for user to choose from through the settings / configuration. I would like to get the user's current selection and filter the results accordingly. Example:

.ini:
[bbc_source]
type = boolean
defaultValue = true
displayName = BBC

User can toggle the option on and off and the query will be modified to include or leave out news from this source. For this in the scope I would like to know the actual settings (I guess this is the proper object: https://developer.ubuntu.com/api/scopes/cpp/sdk-15.04.1/unity.scopes.ScopeBase/#acddeebb3357c6941b3b77617133cda23). I guess the settings() in unity-js-scopes/index.js is what I should be looking for and that's what I was initially trying to work with.

Revision history for this message
Marcus Tomlinson (marcustomlinson) said :
#3

Hi Mikko, after some investigation it seems that you've actually uncovered a bug! Settings are not accessible through the bindings at all at the moment :/ I'm terribly sorry about that! On the up side though, I've put together a fix for this issue and will hopefully land within the next 24 hours.

Revision history for this message
Marcus Tomlinson (marcustomlinson) said :
#4

Hi again Mikko, once the fix lands (keep an eye on the bug status), you will be able to access your scope's settings by calling scopes.self.settings from anywhere in your scope implementation.

E.g. var bbc_source = scopes.self.settings["bbc_source"].get_bool();

Revision history for this message
Mikko Majander (mikko-majander) said :
#6

Hi,

Thank you for the fix. I just tested it and the settings can be read just as you wrote. Awesome! :) I was hoping originally that it would be a defect instead of my inability to understand documentation.

You are doing really good job with the js-bindings. It really makes it easier to write scopes!