shell
使用默认应用程序管理文件和 url。
Process: Main, Renderer (non-sandboxed only)
shell 模块提供与桌面集成相关的功能。
在用户的默认浏览器中打开 URL 的示例:
const { shell } = require('electron')
shell.openExternal('https://github.com')
[!WARNING] While the
shellmodule can be used in the renderer process, it will not function in a sandboxed renderer.
方法
shell 模块具有以下方法:
shell.showItemInFolder(fullPath)
fullPathstring
在文件管理器中显示指定的文件。 如果可能,请选择文件。
shell.openPath(path)
pathstring
返回 Promise<string> - 如若发生故障,则返回一个带有错误信息的字符串,正常则返回空字符串
以桌面的默认方式打开给定的文件。
shell.openExternal(url[, options])
urlstring - Max 2081 characters on Windows.
返回 Promise<void>
以桌面的默认方式打开给定的文件。 (例如,mailto:用户默认邮件代理中的URL)。
shell.trashItem(path)
pathstring - 要移动到回收站的项目路径.
Returns Promise<void> - 操作完成时正常解析。 删除项目错误时拒绝。
这将移动路径到操作系统特定的垃圾位置 (macOS 上的 Trash、Windows 上的 Recycle Bin 以及 Linux 上的桌面环境特定位置) 。
shell.beep()
播放哔哔的声音.
shell.writeShortcutLink(shortcutPath[, operation], options) Windows
shortcutPathstringoperationstring (可选) - 默认是create, 可以是以下之一:create- 创建一个新的快捷方式, 如有必要可以覆盖。update- 仅更新现有快捷方式上的指定属性。replace- 覆盖现有快捷方式, 如果快捷方式不存在将会失败。
返回 boolean - 快捷方式是否被成功创建。
在shortcutPath位置创建或更新一个快捷连接
shell.readShortcutLink(shortcutPath) Windows
shortcutPathstring
Returns ShortcutDetails
解析shortcutPath中的快捷链接。
发生任何错误时将引发异常。