如何获取有关启动我的应用程序的文件的信息?
类似于如何获取参数用电子应用程序打开文件,但该解决方案对我不起作用。
Similar to How to get the arguments for opening file with electron app but the solution there is not working for me.
使用:
操作系统-Windows 10
电子- https://github.com/castlabs /electron-releases.git#v1.8.7-vmp1010
电子构建体-v20.28.3
Using:
OS - Windows 10
Electron - https://github.com/castlabs/electron-releases.git#v1.8.7-vmp1010
electron-builde - v20.28.3
我有一个电子使用electronic-builder构建应用程序,并使用后者,我指定了一个自定义文件关联, .custom
。
I have a an electron app build with electron-builder, and using the latter I have specified a custom file association, .custom
.
因此,当您双击具有此扩展名的文件 file.custom
时,将打开已安装的应用程序。该文件中将包含应用程序所需的一些数据,我想使用我的应用程序读取此数据。
So when you double-click on a file with this extension, file.custom
, the installed app opens. This file would have some data in it that the app needs, and I'd like to read this data using my app.
我的应用程序可以通过任何方式检测到是什么启动的,所以我可以说 file.custom启动了我,它位于 C:\Users\Owner\Downloads\
?
Is there any way that my app can detect what launched it, so that I can say "file.custom" launched me, and it's sitting at "C:\Users\Owner\Downloads\
,?
文件未显示在 process.argv
您可以使用process.argv获得对该文件的引用,例如:
You can get a reference to the file using process.argv, example:
var ipc = require('ipc');
var fs = require('fs');
// read the file and send data to the render process
ipc.on('get-file-data', function(event) {
var data = null;
if (process.platform == 'win32' && process.argv.length >= 2) {
var openFilePath = process.argv[1];
data = fs.readFileSync(openFilePath, 'utf-8');
}
event.returnValue = data;
});
来源:来源