shell
使用默认应用程序管理文件和 url。
Process: Main, Renderer (non-sandboxed only)
shell
模块提供与桌面集成相关的功能。
在用户的默认浏览器中打开 URL 的示例:
const { shell } = require('electron')
shell.openExternal('https://github.com')
Note: While the shell
module can be used in the renderer process, it will not function in a sandboxed renderer.
方法
shell
模块具有以下方法:
shell.showItemInFolder(fullPath)
fullPath
String
Show the given file in a file manager. If possible, select the file.
shell.openPath(path)
path
String
Returns Promise<String>
- Resolves with an string containing the error message corresponding to the failure if a failure occurred, otherwise “”.
以桌面的默认方式打开给定的文件。
shell.openExternal(url[, options])
url
String - Max 2081 characters on windows.options
Object (optional)activate
Boolean (optional) macOS -true
to bring the opened application to the foreground. 默认值为true
。workingDirectory
String (optional) Windows - The working directory.
Returns Promise<void>
Open the given external protocol URL in the desktop’s default manner. (For example, mailto: URLs in the user’s default mail agent).
shell.moveItemToTrash(fullPath[, deleteOnFail])
fullPath
StringdeleteOnFail
Boolean (optional) - Whether or not to unilaterally remove the item if the Trash is disabled or unsupported on the volume. macOS
Returns Boolean
- Whether the item was successfully moved to the trash or otherwise deleted.
将给定的文件移动到垃圾箱,并返回操作的布尔状态。
shell.beep()
播放哔哔的声音.
shell.writeShortcutLink(shortcutPath[, operation], options)
Windows
shortcutPath
Stringoperation
String (optional) - Default iscreate
, can be one of following:create
- 创建一个新的快捷方式, 如有必要可以覆盖。update
- 仅更新现有快捷方式上的指定属性。replace
- 覆盖现有快捷方式, 如果快捷方式不存在将会失败。
options
ShortcutDetails
返回 Boolean
- 快捷方式是否被成功创建。
在shortcutPath
位置创建或更新一个快捷连接
shell.readShortcutLink(shortcutPath)
Windows
shortcutPath
String
解析shortcutPath
中的快捷链接。
发生任何错误时将引发异常。