火狐插件:如何卸载插件时卸载? [英] Firefox Addon: how to remove preferences when addon is being uninstalled?

查看:222
本文介绍了火狐插件:如何卸载插件时卸载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Firefox插件中有以下一段代码:

  var firstrun = Services.prefs.getBoolPref(extensions .CustomButton.firstrun); 

if(firstrun){
// alert(first run);
Services.prefs.setBoolPref(extensions.CustomButton.firstrun,false);
installButton(nav-bar,custom-button-1);
} else {
// alert(not first run);

在addon_dir / defaults / preferences / pref.js中,我有以下字符串:

  pref(extensions.CustomButton.firstrun,true); 

当第一次运行插件时,上面的代码可以理解它并在工具栏上安装一个按钮。此外,它还将以下字符串添加到profile_dir / prefs.js中:

  user_pref(extensions.CustomButton.firstrun,false) ; 

工作正常。唯一困扰的是profile_dir / prefs.js中的这个字符串在我卸载插件时不会被清除。所以,如果我第二次安装这个插件,第一次运行的值是false,并且按钮没有被添加到工具栏中。



问题:是的删除addon首选项(在我的情况下,user_pref(extensions.CustomButton.firstrun,false);)当addon被卸载时



:我已阅读这篇文章,但仍然没有知道要等待什么事件。任何工作的例子?我相信这是一个插件创作者的常见操作,我很惊讶没有文章详细解释这些问题。

解决方案

<$ p $ AddonManager.addAddonListener({
onUninstalling:function(addon){
// alert(uninstalling!);
Services.prefs.setBoolPref(extensions .CustomButton.firstrun,true);
}
});


I have the following piece of code in my Firefox addon:

var firstrun = Services.prefs.getBoolPref("extensions.CustomButton.firstrun");

if (firstrun) {
  // alert("first run");
  Services.prefs.setBoolPref("extensions.CustomButton.firstrun", false);
  installButton("nav-bar", "custom-button-1");
} else {
  // alert("not first run");
} 

In addon_dir/defaults/preferences/pref.js, I have the following string:

pref("extensions.CustomButton.firstrun", true);

When addon runs for the first time, the code above understands it and installs a button on the toolbar. Also, it adds the following string to profile_dir/prefs.js:

user_pref("extensions.CustomButton.firstrun", false);

It works fine. The only thing that bothers is this string in profile_dir/prefs.js is not cleared when I uninstall the addon. So, if I install this addon for the second time, the firstrun value is false, and the button is not added to the toolbar.

Question: is it possible to remove addon preferences (in my case, user_pref("extensions.CustomButton.firstrun", false);) when addon is uninstalled?

A note: I have read this article, but still have no idea what event to wait for. Any working example? I believe it is a common operation for addon creators and am very surprised there are no articles explaining these matters in detail.

解决方案

AddonManager.addAddonListener({
    onUninstalling: function(addon){
        // alert("uninstalling!");   
        Services.prefs.setBoolPref("extensions.CustomButton.firstrun", true);
    }
  });

这篇关于火狐插件:如何卸载插件时卸载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆