【问题标题】:Find out the path to the addon folder in the Thunderbird API在 Thunderbird API 中找出插件文件夹的路径
【发布时间】:2012-10-18 19:01:23
【问题描述】:

我正在修改 Thunderbird 的插件,并在其中一个 javascript 文件中找到硬编码插件的路径。这对我来说似乎很草率,我认为必须有可能以编程方式找出这条路径。但是,经过多次谷歌搜索,我仍然找不到该问题的答案。

你知道如何找到 Thunderbird 插件的文件夹路径(包含 install.rdf)吗?

【问题讨论】:

    标签: thunderbird thunderbird-addon


    【解决方案1】:

    您可以为此使用AddonManager API

    Components.utils.import("resource://gre/modules/AddonManager.jsm");
    
    AddonManager.getAddonByID("foo@example.com", function(addon)
    {
      var uri = addon.getResourceURI("install.rdf");
      if (uri instanceof Components.interfaces.nsIFileURL)
      {
        var file = uri.file;
        alert(file.parent.path);
      }
    });
    

    供参考:AddonnsIFileURLnsIFile

    上面代码中的假设是扩展在安装时解包,您的前任可能将<em:unpack>true</em:unpack>添加到install.rdf。通常不应指定此标志,将扩展打包在磁盘上会更好地提高性能。如果你只是需要从你的扩展中读取一个文件,你可以使用XMLHttpRequest,而不需要它是磁盘上的物理文件:

    Components.utils.import("resource://gre/modules/AddonManager.jsm");
    
    AddonManager.getAddonByID("foo@example.com", function(addon)
    {
      var uri = addon.getResourceURI("example.txt");
      var request = new XMLHttpRequest("GET", uri.spec);
      request.addEventListener("load", function()
      {
        alert(request.responseText);
      }, false);
      request.send();
    });
    

    【讨论】:

    • 但有一件事:我需要运行一个 python 脚本,所以第二段代码并不适合我。但是,这仍然是一个开始,我会对此进行调查。再次感谢。
    • @janoliver:是的,如果你想运行代码,那么你要么必须解压扩展,要么必须先将 Python 脚本复制到临时目录中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 2011-05-25
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 2017-11-24
    • 2015-05-14
    相关资源
    最近更新 更多