简体   繁体   English

NodeJS +电子路径

[英]NodeJS + electron paths

I'm trying to figure out how to predict paths within the code in an electron packaged app with asar flag. 我试图弄清楚如何在带有asar标志的电子封装应用程序中预测代码内的路径。

Using windows (one exe file) and mac (one .app package folder) - each finally includes an asar file, to contain the node scripts. 使用Windows(一个exe文件)和mac(一个.app软件包文件夹)-每个最终都包含一个asar文件,以包含节点脚本。

I want to access the folder where the exe is on windows, and the current package app parent folder. 我想访问exe在Windows上的文件夹,以及当前程序包应用程序的父文件夹。

/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. 使用__dirname并向下遍历无济于事,因为win和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())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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