shell
Manage files and URLs using their default applications.使用默认应用程序管理文件和URL。
Process:进程:Main, Renderer (non-sandboxed only)(仅限非沙盒)
The shell
module provides functions related to desktop integration.shell
模块提供与桌面集成相关的功能。
An example of opening a URL in the user's default browser:在用户的默认浏览器中打开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
模块可以在渲染器过程中使用,但它在沙盒渲染器中不会起作用。
Methods方法
The shell
module has the following methods: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 a string containing the error message corresponding to the failure if a failure occurred, otherwise "".如果发生故障,则使用包含与故障对应的错误消息的字符串进行解析,否则为“”。
Open the given file in the desktop's default manner.以桌面的默认方式打开给定的文件。
shell.openExternal(url[, options])
url
string -Max 2081 characters on windows.窗口上最多2081个字符。
Returns返回Promise<void>
Open the given external protocol URL in the desktop's default manner. 以桌面的默认方式打开给定的外部协议URL。(For example, mailto: URLs in the user's default mail agent).(例如,mailto:URL在用户的默认邮件代理中)。
shell.trashItem(path)
path
string -path to the item to be moved to the trash.要移动到垃圾桶的项目的路径。
Returns返回Promise<void>
- Resolves when the operation has been completed. 在操作完成时解析。Rejects if there was an error while deleting the requested item.如果在删除请求的项目时出现错误,则拒绝。
This moves a path to the OS-specific trash location (Trash on macOS, Recycle Bin on Windows, and a desktop-environment-specific location on Linux).这会将路径移动到操作系统特定的垃圾箱位置(macOS上的垃圾箱、Windows上的回收站和Linux上的桌面环境特定位置)。
shell.beep()
Play the beep sound.播放嘟嘟声。
shell.writeShortcutLink(shortcutPath[, operation], options)
Windows
shortcutPath
stringoperation
string (optional) -Default is默认为create
, can be one of following:create
,可以是以下其中一种:create
-Creates a new shortcut, overwriting if necessary.创建一个新的快捷方式,必要时进行覆盖。update
-Updates specified properties only on an existing shortcut.仅在现有快捷方式上更新指定的属性。replace
-Overwrites an existing shortcut, fails if the shortcut doesn't exist.覆盖现有的快捷方式,如果该快捷方式不存在则会失败。
Returns返回boolean
- Whether the shortcut was created successfully.快捷方式是否已成功创建。
Creates or updates a shortcut link at 在shortcutPath
.shortcutPath
处创建或更新快捷方式链接。
shell.readShortcutLink(shortcutPath)
Windows
shortcutPath
string
Returns 返回ShortcutDetails
Resolves the shortcut link at 解析shortcutPath
.shortcutPath
处的快捷方式链接。
An exception will be thrown when any error happens.发生任何错误时都会引发异常。