在做一个markdown编辑器,文件拖入dock图标时不能唤醒应用(atom可以)。
请问这种拖拽唤醒应用的功能如何实现?md文件右键打开方式中也无法选中该应用。
类似如下图中的vscode
在做一个markdown编辑器,文件拖入dock图标时不能唤醒应用(atom可以)。
请问这种拖拽唤醒应用的功能如何实现?md文件右键打开方式中也无法选中该应用。
类似如下图中的vscode
https://electron.atom.io/docs...
Event: ‘open-file’ macOS
Emitted when the user wants to open a file with the application. > The open-file event is usually emitted when the application is > already open and the OS wants to reuse the application to open
the file. open-file is also emitted when a file is dropped onto the dock and the application is not yet running. Make sure to listen for the open-file event very early in your application startup to handle this case (even before the ready event is emitted).You should call event.preventDefault() if you want to handle this event.
On Windows, you have to parse process.argv (in the main process) to get the filepath
app 有这个open-file这个事件,应该可以满足你
10 回答11.7k 阅读
2 回答3.2k 阅读✓ 已解决
2 回答4.2k 阅读✓ 已解决
3 回答1.9k 阅读✓ 已解决
2 回答1.7k 阅读✓ 已解决
4 回答2.5k 阅读✓ 已解决
5 回答3.8k 阅读
非常有意思的, 我根据你的问题翻了下 vscode 的源码, 结合了一些网上的资料, 实现了你要的效果.
主要解决思路是这个 issue 给的...
得到了这个实现需要 open-file 事件支持和 Info.plist 支持
通过查看 vscode 的 Info.plist 和苹果开发文档, 以及 electron-packager 的源码得到了实现方法...
主要是要在 electron-packager v8.2.0 加入了 修改 Info.plist 方法...
最后我都集成在了我的这个 electron-webpack 库里...
主要代码在这个 commit 里...
相关代码: electron-packager 的 config 加入
意思就是支持 dat 文件后缀的拖拽功能...
入口文件添加响应 open-file 事件...
大概就是这样, 有问题再交流...
以下是相关代码的地址:
https://github.com/llwslc/ele...