javascript - Electron:app.on 'open-file' 的 Windows 替代方案
问题描述
我正在构建一个 Electron 应用程序,用于在 Windows 计算机上编辑 .txt 文件。我已经使用电子构建器fileAssociations
打开 .txt 文件,但是我无法获取文件的路径。当我查看 Electron 文档时,我发现这正是我想要的,除了它仅适用于 mac ......有没有办法在 Windows 上获得相同的功能?
解决方案
正如 Lucas Roland 提到的,您必须解析process.argv
才能获取文件路径
if (process.argv.length >= 2) { // or electron.remote.process.argv
let filePath = process.argv[1];
//open, read, handle file
}
推荐阅读
- swift - M1 和英特尔 MacBook Pro 之间的 macOS 应用程序的内存使用不同
- python - 无法分配“1”:“Plugins.category”必须是“PluginsCategory”实例。Django 和外键
- javascript - 如何在 reactjs 中下载本地文件?
- c++ - 为什么 Qt 程序在编译为 macOS 捆绑包时看起来不对,但作为未捆绑的可执行文件却很好?
- php - PHP计算建议的价格值
- c++ - 升级到 1.2.162.1 后:vkQueueWaitIdle == VK_ERROR_DEVICE_LOST
- javascript - 试图在 javascript 中为井字游戏连接我的板和 winCombos 数组
- javascript - 有没有办法将字符串数组转换为对象集合?
- asynchronous - asyncio 和 node.js 事件循环真的是异步的吗?
- python - 使用 Heroku、Redis 和 Flask 时出现 UnicodeError 'idna' encoding