如何获取有关启动我的应用程序的文件的信息?

How can I get information about the file that launched my app?

类似于,但那里的解决方案对我不起作用。

使用:
OS - Windows 10
电子 - https://github.com/castlabs/electron-releases.git#v1.8.7-vmp1010
电子构建 - v20.28.3

我有一个用 electron-builder 构建的 electron 应用程序,使用后者我指定了一个自定义文件关联,.custom

因此,当您双击具有此扩展名 file.custom 的文件时,已安装的应用程序将打开。此文件中包含应用程序需要的一些数据,我想使用我的应用程序读取此数据。

我的应用程序是否可以通过任何方式检测启动它的内容,以便我可以说 "file.custom" launched me, and it's sitting at "C:\Users\Owner\Downloads\,?

文件没有出现在process.argv

您可以使用 process.argv 获取对文件的引用,例如:

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;
});

来源:Source