gpt4 book ai didi

firefox-addon-sdk - 在用户分支中设置首选项并在卸载时取消设置

转载 作者:行者123 更新时间:2023-12-04 07:42:31 25 4
gpt4 key购买 nike

我创建了一个带有以下 lib/main.js 的 firefox 插件:

const {Cc,Ci} = require("chrome");
var pref = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
pref.setIntPref("network.http.response.timeout", 3600*24);

不被接受,原因如下:

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.

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.



要将首选项恢复为默认值,由 setIntPref() 设置,我发现我必须做 this卸载时:
pref.clearUserPref("network.http.response.timeout")

如果我在另一个测试插件中调用它,这个命令可以正常工作。我只需要找出 How to implement a command, so it is executed when the firefox-addon is uninstalled?

那么我该如何理解这些评论呢?如何在“用户分支”中设置首选项?

最佳答案

这是我刚才的做法:

function clearPrefBranch(aPrefBranchName) {                                     
var defaultBranch = Services.prefs.getDefaultBranch(null);
defaultBranch.deleteBranch(aPrefBranchName);
}

然后,只需调用 clearPrefBranch参数为 extensions.mypluginname (假设您使用了命名约定,并且您应该能够删除所有扩展安装的首选项。

编辑 :

我在 main.js 文件中使用的代码:
const {Cc,Ci,Cm,Cr,Cu} = require("chrome");                                     
Cu.import("resource://gre/modules/Services.jsm");

exports.onUnload = function(aOptions, aCallbacks) {
MyPlugin.shutdown();
};

function clearPrefBranch(aPrefBranchName) {
var defaultBranch = Services.prefs.getDefaultBranch(null);
defaultBranch.deleteBranch(aPrefBranchName);
}

var MyPlugin = {
shutdown: function() {
prefLoader.clearPrefBranch('extensions.oopstab');

}
};

关于firefox-addon-sdk - 在用户分支中设置首选项并在卸载时取消设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23985279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com