当前位置: 首页 > 文档资料 > Electron 中文文档 >

shell

优质
小牛编辑
162浏览
2023-12-01

使用默认应用程序管理文件和 url。

进程: Main, Renderer

shell 模块提供与桌面集成相关的功能。

在用户的默认浏览器中打开 URL 的示例:

const { shell } = require('electron')
shell.openExternal('https://github.com')

Manage files and URLs using their default applications.

Process: Main, Renderer

The shell module provides functions related to desktop integration.

An example of opening a URL in the user's default browser:

const { shell } = require('electron')
shell.openExternal('https://github.com')

方法

shell 模块具有以下方法:

Methods

The shell module has the following methods:

shell.showItemInFolder(fullPath)

  • fullPath String

在文件管理器中显示给定的文件。如果可以, 选中该文件。

shell.showItemInFolder(fullPath)

  • fullPath String

Show the given file in a file manager. If possible, select the file.

shell.openItem(fullPath)

  • fullPath String

返回 Boolean - 文件是否成功打开

以桌面的默认方式打开给定的文件。

shell.openItem(fullPath)

  • fullPath String

Returns Boolean - Whether the item was successfully opened.

Open the given file in the desktop's default manner.

shell.openExternalSync(url[, options])

  • url String - Max 2081 characters on Windows, or the function returns false.
  • 选项 Object (可选)

    • activate Boolean (optional) - true to bring the opened application to the foreground. The default is true. macOS
    • workingDirectory String (optional) - The working directory. Windows

Returns Boolean - Whether an application was available to open the URL.

Open the given external protocol URL in the desktop's default manner. (For example, mailto: URLs in the user's default mail agent).

过时的

shell.openExternalSync(url[, options])

  • url String - Max 2081 characters on Windows, or the function returns false.
  • options Object (optional)

    • activate Boolean (optional) - true to bring the opened application to the foreground. The default is true. macOS
    • workingDirectory String (optional) - The working directory. Windows

Returns Boolean - Whether an application was available to open the URL.

Open the given external protocol URL in the desktop's default manner. (For example, mailto: URLs in the user's default mail agent).

Deprecated

shell.openExternal(url[, options])

  • url String - Max 2081 characters on windows.
  • options Object (可选)

    • activate Boolean (optional) - true to bring the opened application to the foreground. The default is true. macOS
    • workingDirectory String (optional) - The working directory. Windows

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.openExternal(url[, options])

  • url String - Max 2081 characters on windows.
  • options Object (optional)

    • activate Boolean (optional) - true to bring the opened application to the foreground. The default is true. macOS
    • workingDirectory String (optional) - The working directory. Windows

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)

  • fullPath String

返回 Boolean - 该对象是否成功移至垃圾箱。

将给定的文件移动到垃圾箱,并返回操作的布尔状态。

shell.moveItemToTrash(fullPath)

  • fullPath String

Returns Boolean - Whether the item was successfully moved to the trash.

Move the given file to trash and returns a boolean status for the operation.

shell.beep()

播放哔哔的声音.

shell.beep()

Play the beep sound.

shell.writeShortcutLink(shortcutPath[, operation], options) Windows

  • shortcutPath String
  • operation String (optional) - 默认值为 create可为下列之一:

    • create - 创建一个新的快捷方式, 如有必要可以覆盖。
    • update - 仅更新现有快捷方式上的指定属性。
    • replace - 覆盖现有快捷方式, 如果快捷方式不存在将会失败。
  • options ShortcutDetails

返回 Boolean - 快捷方式是否被成功创建。

shortcutPath位置创建或更新一个快捷连接

shell.writeShortcutLink(shortcutPath[, operation], options) Windows

  • shortcutPath String
  • operation String (optional) - Default is create, can be one of following:

    • 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.
  • options ShortcutDetails

Returns Boolean - Whether the shortcut was created successfully.

Creates or updates a shortcut link at shortcutPath.

shell.readShortcutLink(shortcutPath) Windows

  • shortcutPath String

返回 ShortcutDetails

解析shortcutPath中的快捷链接。

发生任何错误时将引发异常。

shell.readShortcutLink(shortcutPath) Windows

  • shortcutPath String

Returns ShortcutDetails

Resolves the shortcut link at shortcutPath.

An exception will be thrown when any error happens.