电子从自定义扩展文件中获取数据

我正在使用电子,试图达到一个结果, 用户点击保存的文件打开电子应用程序,并获得文件的数据
到目前为止,我所做的是:
1)创build自定义扩展registry,并使用reg文件添加文件打开命令。

Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.wtpd] @="Water Treatment Plant Design File" [HKEY_CLASSES_ROOT\.wtpd\DefaultIcon] @="C:\\\\Users\\\\user\\\\Downloads\\\\wtpd_file.ico" [HKEY_CLASSES_ROOT\.wtpd\shell] [HKEY_CLASSES_ROOT\.wtpd\shell\open] [HKEY_CLASSES_ROOT\.wtpd\shell\open\command] @="\"C:\\Users\\user\\Desktop\\ENV\\electron.exe\" \"%1\"" 

2)现在它打开电子应用程序,但我想获得.wtpd文件中的数据,以便进行计算。

我试图使用这个,但在这个例子中的链接被打破。 https://www.theodo.fr/blog/2015/12/link-files-to-application-in-windows/

看来,Windows将文件path作为parameter passing给应用程序(在这种情况下,您的电子应用程序)。 所以你可以使用process.argv来获取文件path。

 var filePath = process.argv[1]; var data = fs.readFileSync(openFilePath, 'utf-8'); 

显然你可能想要添加诸如process.argv.length >= 2检查来确保参数被传递(如果应用程序是手动打开的而不是由windows调用的话)。 但是,这通常是如何获得文件内容。