Reading contents of files inside the XPI.

General discussion, compatibility and contributed extensions.

Moderators: satrow, FranklinDM, Lootyhoof

BobbyBonsaimind
Newbie
Newbie
Posts: 6
Joined: Fri, 08 Dec 2017, 17:58
Contact:

Reading contents of files inside the XPI.

Unread postby BobbyBonsaimind » Fri, 08 Dec 2017, 18:03

I'm currently in the process of recreating my extensions for Palemoon but have hit a wall so far. What I'd like to do is to provide the user with the ability to export all settings into an easily readable JSON file which can also be imported. Additionally I want to provide different defaults which can be loaded at will (and are embedded inside the XPI).

The exporting/importing works by utilizing the FileUtils methods, but for being able to provide different defaults I want to embed the exported JSON files inside the XPI (which means that I can easily change these default settings, I just need to import, tweak, and export them again). I'm unable to find a way to read the content of an embedded file which is accessible through a chrome URI.

Does somebody know how I can do that?

User avatar
JustOff
Localization Coordinator
Localization Coordinator
Posts: 1500
Joined: Thu, 03 Sep 2015, 19:47
Location: UA
Contact:

Re: Reading contents of files inside the XPI.

Unread postby JustOff » Fri, 08 Dec 2017, 20:36

You can try something like this:

Code: Select all

var file = Services.io.newURI("chrome://my-add-on/content/myfile.json", null, null);

NetUtil.asyncFetch(file, function(inputStream) {
  var data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
});
Here are the add-ons I made in a spare time. That was fun!

BobbyBonsaimind
Newbie
Newbie
Posts: 6
Joined: Fri, 08 Dec 2017, 17:58
Contact:

Re: Reading contents of files inside the XPI.

Unread postby BobbyBonsaimind » Fri, 08 Dec 2017, 22:25

That works, thank you very much.

I remember seeing both of these functions, but for some reason never managed to connect the dots that I could use them to read the file.


Return to “Browser extensions”

Who is online

Users browsing this forum: No registered users and 5 guests