首页 > 解决方案 > Electron:app.on 'open-file' 的 Windows 替代方案

问题描述

我正在构建一个 Electron 应用程序,用于在 Windows 计算机上编辑 .txt 文件。我已经使用电子构建器fileAssociations打开 .txt 文件,但是我无法获取文件的路径。当我查看 Electron 文档时,我发现正是我想要的,除了它仅适用于 mac ......有没有办法在 Windows 上获得相同的功能?

标签: javascriptnode.jswindowselectronelectron-builder

解决方案


正如 Lucas Roland 提到的,您必须解析process.argv才能获取文件路径

if (process.argv.length >= 2) { // or electron.remote.process.argv
    let filePath = process.argv[1];
    //open, read, handle file
}

推荐阅读