NWJS access external files on FlashDrive

559 views Asked by At

I have a very particular case and I don't know if this is possible to be done.

I'm using NWJS to run a web app as a desktop app. I need to zip/package the source files because my code should not be available to eavesdroppers. This package will be delivered on a flash drive. And this is were my trouble begins.

There are a lot of .pdf file that must be shipped together with the package. The user can browse which pdf he wants to open, and when he clicks it, the pdf is "downloaded" to his pc. The content of the pdf is NOT available on the application. I have a list with the name of each pdf file.

If I zip/package the .pdf together with the source files it becomes a huge .nw file and it takes forever for my application to load. I need to mantain the pdf on a separate folder and they need to be accessible through the source code. This is easy if i run the application directly without packaging it, as nw uses the relative url to it's root, but when I do package nw uses a temp folder for the source files and I can't use relative url to access the pdf folder.

The only approach i can think of is to write a js script to identify where the flash drive was mounted but i don't know if this is possible.

I have to support Windows and Mac for this case.

1

There are 1 answers

0
pcezar91 On

Searching on NWJS google group i found that the answer was quite simple. These two lines returns the path where the nw bin is running. From there is quite simple to get the pdf folder.

var path = require("path"); 
pathstr = path.dirname(process.execPath);