当外部应用程序卸载附加组件时恢复 Firefox 首选项的正确方法

发布于 2024-08-06 23:12:03 字数 1284 浏览 11 评论 0原文

我在 Windows 上编写了一个应用程序套件,其中安装了一个 Firefox 附加组件,该附加组件一旦运行就会通过与 nsIPrefService 交互来修改 Firefox 网络首选项。

扩展本身与应用程序的其他部分一起驻留在Program Files下的一个文件夹中,这些部分相互协作。

由于该应用程序由许多组件组成,因此卸载它的正确方法是通过控制面板或通过我为用户提供的卸载快捷方式。

当用户选择卸载时,我无法控制 Firefox 是否会运行(也许我可以尝试检测它是否在卸载程序中运行并请求用户关闭它以继续)。

由于卸载程序的目的是从最终用户系统中删除该程序的所有痕迹,即:

  • Program Files 文件夹下的所有文件,包括扩展组件,
  • 从 Firefox 中删除该附加组件(通过删除 HKEY_CURRENT_USER\Software\Mozilla\Firefox\Extensions 下的注册表项,导致加载项在下一次 Firefox 重新启动时取消注册)
  • 删除应用程序特定的注册表项

然后卸载后,用户系统上不再有我的任何代码将网络首选项恢复到安装组件之前的状态。这会导致最终用户无法浏览网页,并且非常沮丧!

我目前能弄清楚如何做到这一点的唯一方法是让我的组件写入窗口的注册表用户配置文件文件夹的位置 - 我可以使用我的附加组件执行此操作:

Components.classes["@mozilla.org/file/directory_service;1"]
   .getService(Components.interfaces.nsIProperties).get("ProfD", 
    Components.interfaces.nsIFile).path

然后让我的卸载程序直接修改该位置中的 prefs.js 文件。 但这只有在我可以保证 Firefox 在卸载期间不运行的情况下才有效(因为 prefs.js 是在 FF 关闭时重写的)

对我来说这不是一个优雅的解决方案:

  • 它似乎不是面向未来,因为它取决于 prefs.js 使用的格式和符号,这些格式和符号可能在未来的 FF 版本中发生变化。
  • Firefox 有一个不总是正确关闭的坏习惯(有时其他安装的附加组件会阻止它从内存中完全卸载。这会破坏我的卸载程序)。
  • 如果用户使用我的附加组件设置了多个 FF 配置文件,则这将不起作用(无需精心修改)。

有没有更好的或“标准”的方法来完成这个简单的任务?

I have written an application suite on Windows which amongst other things installs a Firefox add-on which once run modifies the Firefox network preferences by interfacing with nsIPrefService.

The extension itself resides in a folder under Program Files along with other parts of the application which work together with each other.

Since the application consists of a number of components, the correct way to uninstall it is via the Control Panel or via an uninstall shortcut I provide for the users.

I have no control over whether Firefox will be running or not when the user chooses to uninstall (possibly I could try to detect if it's running in the uninstaller and request the user close it to continue).

Since the purposes of the uninstaller is to remove all traces of the program from the end-users system i.e:

  • all the files under the Program Files folder, including the extension components
  • remove the add-on from Firefox (by removing the registry key under HKEY_CURRENT_USER\Software\Mozilla\Firefox\Extensions, causing the add-on to unregister on next Firefox restart)
  • remove application specific registry keys

Then after uninstall there isn't any of my code left on the users system capable of restoring the network preferences to what they were before the component was installed. This results in end-users not being able to browse the web and being very frustrated!

The only way I can figure out how to do this at the moment is to have my component write to the window's registry the location of the users profile folder - which I can do with my add-on:

Components.classes["@mozilla.org/file/directory_service;1"]
   .getService(Components.interfaces.nsIProperties).get("ProfD", 
    Components.interfaces.nsIFile).path

And then have my uninstaller modify the prefs.js file in that location directly. But this will only work if I can guarantee Firefox isn't running during uninstall (since prefs.js is re-written on FF close)

To me this is not an elegant solution:

  • It seems not to be future proof since it is dependent on the format and symbols used prefs.js which may change in future FF releases.
  • Firefox has a nasty habbit of not always closing properlly (sometimes other installed add-ons prevent it from completely unloading from memory. This would break my uninstaller).
  • This wouldn't work (without elaborate modification) if the user has multiple FF profiles setup all using my add-on.

Is there a better or "standard" way to achieve this simple task?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀里藏娇 2024-08-13 23:12:04

卸载程序不能“坚持”关闭 Firefox 吗?例如,

check if FireFox is open
  if open, inform user "FF must be closed, or cancel uninstall" ok/cancel
  loop

我已经有几个安装人员对我这样做了。不过,我记得不是卸载程序。

此外,这并不是面向未来的解决方案,也不能处理配置文件。

Can't the uninstaller "insist" that Firefox be closed? eg,

check if FireFox is open
  if open, inform user "FF must be closed, or cancel uninstall" ok/cancel
  loop

I've had several installers do this to me. Not unistallers, though, that I can remember.

Also, this doesn't future-proof the solution, nor deal with profiles.

甜柠檬 2024-08-13 23:12:03

您是否尝试打包默认文件 (defaults/preferences/myprefs.js) 在你的扩展中?我没有检查它是否可以覆盖 Firefox 范围内的默认设置,但它应该可以。

Did you try to package defaults files (defaults/preferences/myprefs.js) in your extension? I didn't check if it works for overriding Firefox-wide defaults, but it should.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文