Reverting preferences when extension is disabled (XUL)

Talk about add-ons and extension development.
Post Reply
isaacschemm
Posts: 270
Joined: January 20th, 2015, 12:29 pm

Reverting preferences when extension is disabled (XUL)

Post by isaacschemm »

What's the best way to revert an about:config preference to its initial value when an XUL overlay extension is disabled or uninstalled? (It's an extension for SeaMonkey only which is why I'm not using WebExtensions.)
lithopsian
Posts: 3664
Joined: September 15th, 2010, 9:03 am

Re: Reverting preferences when extension is disabled (XUL)

Post by lithopsian »

Are you talking about an application preference or an addon preference? It would be difficult to know whether an application preference is set to a non-default value because of the addon or not, hence questionable whether it should be set back to a default value when the addon is disabled. For preferences specific to the addon, it isn't really necessary to set them back to their default values, although it might be nice to tidy up.

For the technical details, you would use an AddonListener to receive notifications including when the addon is (about to be) disabled. Then you can do what you need to do. Make sure you use onDisabling(), not onDisabled(), or you won't be called until after the addon has been disabled - ie. never.
isaacschemm
Posts: 270
Joined: January 20th, 2015, 12:29 pm

Re: Reverting preferences when extension is disabled (XUL)

Post by isaacschemm »

Thanks.

This is one of the addons.mozilla.org guidelines (my add-on was denied because of it):
Modifications to internal Firefox preferences need to be reverted to the previous value when the add-on gets uninstalled or disabled.
I'm not going to complain, it makes sense. I just gotta figure out how to do it.

Also, I'm trying to rewrite the add-on to use an XPCOM component written in JavaScript, but I'm having some problems with the component's preference listener seeming to stop working after I open the browser toolbox. EDIT: never mind - found an exception that wasn't being logged until I imported resource://gre/modules/Console.jsm.
Post Reply