开发者

Firefox extension dev: observing preferences, avoid multiple notifications

开发者 https://www.devze.com 2022-12-29 13:51 出处:网络
Let\'s say my Firefox extension has multiple preferences, but some of them are grouped, like check interval, fail retry interval, destination url. Those are used in just开发者_StackOverflow single fun

Let's say my Firefox extension has multiple preferences, but some of them are grouped, like check interval, fail retry interval, destination url. Those are used in just开发者_StackOverflow single function.

When I subscribe to preference service and add observer, the observe callback will be called for each changed preference, so if by chance user changed all of the settings in group, then I will have to do the same routine for the same subsystem as many times as I have items in that preferences group. It's a great redundancy!

What I want is observe to be called just once for group of preferences. Say

extensions.myextension.interval1
extensions.myextension.site
extensions.myextension.retry

so if one or all of those preferences are changed, I receive only 1 notification about it. In other words, no matter how many preferences changed in branch, I want the observe callback to called once.


When you register a pref observer on a branch (in your case, extensions.myextension), it will notify you about each preference change. There is no way to get it to tell you only once about a change on a branch. When your observe method is called, you do get the name of the preference that changes (it's the third parameter). You will have to filter your callbacks based on that.

0

精彩评论

暂无评论...
验证码 换一张
取 消