shell
使用默认应用程序管理文件和 URL。
shell
模块提供了与桌面集成相关的函数。
在用户的默认浏览器中打开 URL 的示例
const { shell } = require('electron')
shell.openExternal('https://github.com')
注意:虽然 shell
模块可以在渲染器进程中使用,但在沙盒渲染器中它将无法工作。
方法
shell
模块有以下方法
shell.showItemInFolder(fullPath)
fullPath
字符串
在文件管理器中显示给定的文件。如果可能,则选中该文件。
shell.openPath(path)
path
字符串
返回 Promise<string>
- 如果发生失败,则返回包含与失败对应的错误消息的字符串,否则返回 ""。
以桌面默认方式打开给定的文件。
shell.openExternal(url[, options])
url
字符串 - Windows 上最大 2081 个字符。
返回 Promise<void>
以桌面默认方式打开给定的外部协议 URL。(例如,在用户默认邮件客户端中打开 mailto: URL)。
shell.trashItem(path)
path
字符串 - 要移动到垃圾箱的项目的路径。
返回 Promise<void>
- 操作完成后 resolve。如果删除请求的项目时发生错误则 reject。
此操作将路径移动到操作系统特定的垃圾箱位置 (macOS 上为 Trash,Windows 上为 Recycle Bin,Linux 上为桌面环境特定位置)。
shell.beep()
播放蜂鸣声。
shell.writeShortcutLink(shortcutPath[, operation], options)
Windows
shortcutPath
字符串operation
字符串 (可选) - 默认为create
,可以是以下之一create
- 创建新快捷方式,必要时覆盖。update
- 仅更新现有快捷方式上的指定属性。replace
- 覆盖现有快捷方式,如果快捷方式不存在则失败。
返回 boolean
- 快捷方式是否创建成功。
在 shortcutPath
创建或更新快捷方式链接。
shell.readShortcutLink(shortcutPath)
Windows
shortcutPath
字符串
解析位于 shortcutPath
的快捷方式链接。
发生任何错误时将抛出异常。