在用户分支中设置首选项,并在卸载时取消设置 [英] Set preferences in the user branch and unset them on uninstall
问题描述
我创建了一个带有以下lib/main.js
:
I created a firefox add-on with the following lib/main.js
:
const {Cc,Ci} = require("chrome");
var pref = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
pref.setIntPref("network.http.response.timeout", 3600*24);
由于以下原因而未被接受:
It wasn't accepted with the following reason:
更改关键设置的加载项在禁用或卸载后必须还原更改.您还应该在默认分支(而不是用户分支)中进行更改.
Add-ons which change critical settings must revert the changes when disabled or uninstalled. You should also make the changes in the default, rather than the user, branch.
您需要在首选项服务上调用getDefaultBranch("")
,并在返回的对象而不是直接在首选项服务上调用首选项方法.
You need to call getDefaultBranch("")
on the preferences service, and call the preference methods on the returned object rather than on the preference service directly.
To revert a preference back to the default, set by setIntPref()
, I found out that I have to do this on uninstall:
pref.clearUserPref("network.http.response.timeout")
如果我在另一个测试插件中调用此命令,它将正常工作.我只需要找出
This command works fine If I call it in another test-addon. I only have to find out How to implement a command, so it is executed when the firefox-addon is uninstalled?
那么我该如何理解这些评论?如何在用户分支"中设置首选项?
So how do I have to understand these comments? How do I set the preferences in a "user branch"?
推荐答案
我像这样解决了第二部分(卸载),在我的main.js
中,我在末尾添加了以下代码:
I solved the second part (uninstall) like this, that in my main.js
I added this code at the end:
exports.onUnload = function(reason) {
//called when add-on is
// uninstalled
// disabled
// shutdown
// upgraded
// downgraded
pref.clearUserPref("network.http.response.timeout");
};
这可以用来禁用和卸载该加载项.
That worked on disabling and uninstalling the add-on.
这篇关于在用户分支中设置首选项,并在卸载时取消设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!