electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.61k stars 1.74k forks source link

File access after building #793

Closed justijndepover closed 7 years ago

justijndepover commented 7 years ago

Inside my app I have a link to open up an external pdf file. For this to work properly I send a message with IPC from my render process to my main process.

inside my main I have

ipcMain.on('open_file', function(event, file){
    shell.openItem(__dirname + file);
})

inside my render process i have

$('.open_file').on('click', function(event){
    event.preventDefault();

    var url = $(this).data('url');
    ipcRenderer.send('open_file', url)
})

When i use npm start to run my application everything works fine. But when i build my app with electron-builder nothing happens when I try to open the file. No errors show up in my console. Am I doing something wrong with my paths? Or could it be that the electon-builder does not include the pdf's to my package? They live inside my app directory

develar commented 7 years ago

Probably it is packed into asar and cannot be accessed externally. Please use https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-extraResources (see #751).

justijndepover commented 7 years ago

Is it also possible to add a rule in my package.json build to unpack the file?

"asar.unpack" : "/app/*/document/*.pdf",

The files are located as following:

/app/nl/document/jaydess-notice.pdf
/app/nl/document/mirena-notice.pdf
/app/fr/document/jaydess-notice.pdf
/app/fr/document/mirena-notice.pdf

Excuse me if I ask stupid questions but i don't really understand the asar packaging.

develar commented 7 years ago

@justijndepover Please do not use asar.unpack. It is supported, but I strongly advice you to use more smart and more user-friendly extraResources or extraFiles.

e.g.:

"build": {
  "extraResources": "app/*/document/*.pdf"
}

Please see https://github.com/electron-userland/electron-builder/issues/751#issuecomment-247590609

justijndepover commented 7 years ago

Thanks, that worked!

develar commented 7 years ago

Solution — pdf files should be not packed to asar automatically.