简体   繁体   中英

NodeJS + electron paths

I'm trying to figure out how to predict paths within the code in an electron packaged app with asar flag.

Using windows (one exe file) and mac (one .app package folder) - each finally includes an asar file, to contain the node scripts.

I want to access the folder where the exe is on windows, and the current package app parent folder.

/Application/my app tools/tool.app   -> path to 'my app tools'
C:\Program Files\my app tools\tool\  -> path to 'my app tools'

Using __dirname and traversing down does not help, since there is a different amount of subfolders on win and mac.

Any help is greatly appreciated.

seems to be related to How to get the original path of a portable Electron app?

Taking a look at the documentation here will provide you the needed opportunity.

Using it from the main process will look like this:

const {app} = require('electron')
console.log('Your App Path: + ' app.getAppPath())

and if you want to use it in a renderer process take a look at this:

const {remote} = require('electron')
console.log('Your App Path: ' + remote.app.getAppPath())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM