简体   繁体   English

强制退出浏览器时未保存Firefox首选项(XPCOM / javascript)

[英]Firefox preferences not saved when browser is force quit (XPCOM/javascript)

Working on a firefox extension. 使用Firefox扩展程序。 I'm trying to set preferences from javascript and observing some odd behavior. 我试图从javascript设置首选项,并观察一些奇怪的行为。

  • Whenever I set a preference, I can see the changes immediately in about:config . 无论何时设置首选项,都可以在about:config立即看到更改。 But if firefox is force terminated (using a Ctrl+C), the preferences are not saved. 但是,如果将Firefox强制终止(使用Ctrl + C),则不会保存首选项。 (Can't see the entry in prefs.js in my profile) (在我的个人资料中看不到prefs.js中的条目)
  • Whenever I set a preference by using about:config toggle option (for boolean), or using a standard prefwindow prefpane, and even if I force terminate firefox, the preferences are saved. 每当我使用about:config切换选项(用于boolean)或使用标准的prefwindow prefpane来设置首选项时,即使我强制终止firefox,也将保存首选项。

If firefox is closed normally, everything is okay. 如果正常关闭Firefox,一切正常。 But I'm just worried that if a force quit happens (like OS shutdown or user sends kill signal), then the user preferences are lost! 但是我只是担心,如果发生强制退出(例如操作系统关闭或用户发送终止信号),那么用户首选项将会丢失!

This is a bootstrapped addon, and I set default preferences during startup. 这是一个自举插件,我在启动时设置了默认首选项。 I have event listeners to read user input, and set the user preference. 我有事件侦听器来读取用户输入,并设置用户首选项。 For eg: 例如:

const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
prefs.setBoolPref("extensions.myextension.test.ffterminate", false);

Am I doing something wrong here ? 我在这里做错什么了吗? Should I be using storage instead of preference branch ? 我应该使用存储而不是首选项分支吗?

EDIT : Raised a bug with Mozilla on this : https://bugzilla.mozilla.org/show_bug.cgi?id=981818 编辑:在此上与Mozilla引发了一个错误: https ://bugzilla.mozilla.org/show_bug.cgi?id =981818

I'm thinking you didn't set it on the default branch. 我在想您没有在默认分支上设置它。

This is how you set the pref on the default branch, so when pref is reset, it doesn't delete itself, it goes to this default value. 这是在默认分支上设置首选项的方式,因此,重置首选项时,它不会自行删除,而是会使用此默认值。 I don't know why on browser force shutdown its losing this but try setting on the default branch: 我不知道为什么在浏览器上强制关闭其丢失的内容,但是尝试在默认分支上进行设置:

Services.ps.getDefaultBranch('my_branch_name')['setBoolPref']('myprefname', false);

you were probably just setting on the non default branch liek this: 您可能只是在非默认分支上设置,如下所示:

Services.ps.getBranch('my_branch_name')['setBoolPref']('myprefname', false);

note: if a value is already set on the non-default branch, setting default value will not change the current value of the pref, only if reset, will the pref go to this default value. 注意:如果在非默认分支上已经设置了值,则设置默认值不会更改首选参数的当前值,只有重置后,首选参数才会变为该默认值。 so dont get confused when u set on default and it doesnt change. 因此,当您将默认设置设为默认值时,请不要感到困惑。 it is still working. 它仍然在工作。 it actually did change it, right click on the pref and click reset to see it jump to the value u set in default 它实际上确实更改了它,右键单击首选项,然后单击重置以查看它跳到默认设置的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM