简体   繁体   中英

Gnome-Shell Extension, observe changes on GSettings?

So I'm writing an extension, that has some preferences. I store the preferences in GSettings, using the convenience.js (as described here ). The related code looks like this:

const SETTINGS_APP_SORT_MODE = 'sort-mode';

this._settings = Convenience.getSettings("org.gnome.shell.extensions.workspace-alt-tab"); //get schema

this._settings.set_string(SETTINGS_APP_SORT_MODE,modeCapture); //set value
this._sortMode = this._settings.get_string(SETTINGS_APP_SORT_MODE); //get value

So far it works nicely, and I can also use the command

gsettings monitor org.gnome.shell.extensions.workspace-alt-tab sort-mode

To make sure that I really set the values as I want.

But here it comes to my problem, when I try to capture the changes made to those settings to reflect them in my code. From what I've seen in other extensions, I'm guessing it should look something like this:

   _init: function(params) {
      this._settingsChanged=
         this._settings.connect('changed',
            Lang.bind(this,this._settingsChanged)); //get notified on every schema change
      this._sortModeChangedId =
         this._settings.connect('changed::' + SETTINGS_APP_SORT_MODE,
            Lang.bind(this,this._sortModeChanged)); //get notified for sort-mode changes
      this._sortModeChanged(); //force initialization
    },


    _settingsChanged: function() {
       this._sortMode = this._settings.get_string(SETTINGS_APP_SORT_MODE);
       log("[_settingsChanged] new sortMode: "+this._sortMode);
    },
    _sortModeChanged: function() {
       this._sortMode = this._settings.get_string(SETTINGS_APP_SORT_MODE);
       log("[_sortModeChanged] new sortMode: "+this._sortMode);
    }

But the problem is that I only see the log line called from init:

Gjs-Message: JS LOG: [_sortModeChanged] new sortMode: most-recently-used

Also, I have absolutely no idea about how to debug this kind of thing (even in LookingGlass...). If someone can point to me my silly mistake, or give some pointers as to how to debug this kind of things, it'd be much appreciated!

From the looks of it it seems you are overriding the _settingsChanged variable. Note that inside init() you are doing the following:

this._settingsChanged =
    this._settings.connect('changed',
        Lang.bind(this,this._settingsChanged)); //get notified on every schema change

Here, you are actually overriding the _settingsChanged() method with the value that is returned from connect() . Try saving the return value in a different property, change your code to something like:

this._settingsChangedId =
    this._settings.connect('changed',
        Lang.bind(this,this._settingsChanged)); //get notified on every schema change

Let me know if that fixes the issue for you.
Also, from my excruciating experiences with Gnome-Shell development (no documentation), I found it best to use the IRC channel for support: #gnome-shell on irc.gnome.org

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM