如何获取有关启动我的应用程序的文件的信息? [英] How can I get information about the file that launched my app?

查看:107
本文介绍了如何获取有关启动我的应用程序的文件的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于如何获取参数用电子应用程序打开文件,但该解决方案对我不起作用。

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

来源:来源

这篇关于如何获取有关启动我的应用程序的文件的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆