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