搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Experiment API to save a text file

  • 2 个回答
  • 0 人有此问题
  • 10 次查看
  • 最后回复者为 richard344

more options

I'm trying to write a Thunderbird add-on that allows me to export specific messages to some other custom-built software by saving in a specific local folder. I've written an add-on and included an experiment API because I understand that saving a file isn't possible through the built in APIs. I've lifted much of the code from other places and stitched it together. Everything works apart from the implementation of the API (which of course is the difficult bit)

My problem is that I think I need to use IOUtils but can't seem to get this to load. Has this been deprecated?

My experiment API implementation file currently looks like the following and it's the line: XPCOMUtils.defineLazyGlobalGetters(this, ["IOUtils"]); that seems to be causing it to fail

"use strict";

// Using a closure to not leak anything but the API to the outside world. (function (exports) {

 // Get various parts of the WebExtension framework that we need.
 var { ExtensionCommon } = ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm");
 // You probably already know what this does.
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 // A helpful class for listening to windows opening and closing.
 var { ExtensionSupport } = ChromeUtils.import("resource:///modules/ExtensionSupport.jsm");
 var { FileUtils }       = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
 var { XPCOMUtils }      = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyGlobalGetters(this, ["IOUtils"]);
 
 var ContactAPI = class extends ExtensionCommon.ExtensionAPI {
   getAPI(context) {
     return {
       ContactAPI: {
         saveTextFile: async function(fname, mydata) {
           var uint8 = new Uint8Array(mydata);
           uint8.reduce((binary, uint8) => binary + uint8.toString(2), "");
           Services.wm.getMostRecentWindow("mail:3pane").alert(mydata);
           var ret = await IOUtils.write(fname, uint8);
           return ret;
         },
       },
     };
   }
   onShutdown(isAppShutdown) {
     // This function is called if the extension is disabled or removed, or Thunderbird closes.
     // We usually do not have to do any cleanup, if Thunderbird is shutting down entirely
     if (isAppShutdown) {
       return;
     }
     console.log("Goodbye world!");
   }
 };
 // Export the api by assigning in to the exports parameter of the anonymous closure
 // function, which is the global this.
 exports.ContactAPI = ContactAPI;

})(this)

I'm trying to write a Thunderbird add-on that allows me to export specific messages to some other custom-built software by saving in a specific local folder. I've written an add-on and included an experiment API because I understand that saving a file isn't possible through the built in APIs. I've lifted much of the code from other places and stitched it together. Everything works apart from the implementation of the API (which of course is the difficult bit) My problem is that I think I need to use IOUtils but can't seem to get this to load. Has this been deprecated? My experiment API implementation file currently looks like the following and it's the line: XPCOMUtils.defineLazyGlobalGetters(this, ["IOUtils"]); that seems to be causing it to fail "use strict"; // Using a closure to not leak anything but the API to the outside world. (function (exports) { // Get various parts of the WebExtension framework that we need. var { ExtensionCommon } = ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm"); // You probably already know what this does. var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); // A helpful class for listening to windows opening and closing. var { ExtensionSupport } = ChromeUtils.import("resource:///modules/ExtensionSupport.jsm"); var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm"); var { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyGlobalGetters(this, ["IOUtils"]); var ContactAPI = class extends ExtensionCommon.ExtensionAPI { getAPI(context) { return { ContactAPI: { saveTextFile: async function(fname, mydata) { var uint8 = new Uint8Array(mydata); uint8.reduce((binary, uint8) => binary + uint8.toString(2), ""); Services.wm.getMostRecentWindow("mail:3pane").alert(mydata); var ret = await IOUtils.write(fname, uint8); return ret; }, }, }; } onShutdown(isAppShutdown) { // This function is called if the extension is disabled or removed, or Thunderbird closes. // We usually do not have to do any cleanup, if Thunderbird is shutting down entirely if (isAppShutdown) { return; } console.log("Goodbye world!"); } }; // Export the api by assigning in to the exports parameter of the anonymous closure // function, which is the global this. exports.ContactAPI = ContactAPI; })(this)

所有回复 (2)

more options

I am not even going to try and help you with the actual issue as I am not a developer of anything these days. I suggest you try asking in the addon developers mailing list where add on developers and even some of the paid folks can be found. https://thunderbird.topicbox.com/groups/addons

Expe4iments are not going to be supported going forward is my understanding, so getting involved with the lest is a must I think.

Perhaps this thread might be related enough to offer some ideas. https://thunderbird.topicbox.com/groups/addons/Ta1ba6e8a2d5a27a3/lazy-loading-alternative-for-getfull-when-using-the-messages-api

more options

Thanks will try those suggestions