原文:https://github.com/electron/electron/blob/master/docs/api/shell.md
譯者:Lin
使用文件和URL的默認應用管理文件和URL
shell
模塊提供有關于桌面集成的函數。
一個使用用戶默認瀏覽器打開一個URL的例子:
const {shell} = require('electron')
shell.openExternal('https://github.com')
<h2 id="methods">方法</h2>
shell
模塊有下面的方法:
<h3 id="shell-showItemInFolder"><code>shell.showItemInFolder(fullPath)</code></h3>
-
fullPath
String類型
返回值為Boolean
類型 - 項是否展示成功。
在一個文件管理器中展示要展示的文件。如果可能,將會選中這個文件。
<h3 id="shell-openItem"><code>shell.openItem(fullPath)</code></h3>
-
fullPath
String類型
返回值為Boolean
類型 - 項是否打開成功。
在桌面的默認方式中打開指定文件。
<h3 id="shell-openExternal"><code>shell.openExternal(url[, options, callback])</code></h3>
-
url
String類型 -
options
Object類型(可選參數)MacOS有效-
activate
Boolean類型 -true
將把打開的應用放置在最前方,默認是true
。
-
-
callback
Function類型(可選參數)- 如果指定這個參數將會使用異步打開。MacOS-
error
Error類型
-
返回值為Boolean
類型 - 應用程序是否有效的打開了URL。如果callback
被指定,將總是返回true
。
在桌面的默認打開方式中打開傳入的外部協議URL。(例如,地址:用戶的默認郵件代理的網址)。
<h3 id="shell-moveItemToTrash"><code>shell.moveItemToTrash(fullPath)</code></h3>
-
fullPath
String類型
返回值為Boolean
類型 - 項是否成功的被移除到了垃圾桶中。
移動給定的文件到垃圾桶,并且返回一個boolean
類型的操作狀態。
<h3 id="shell-beep"><code>shell.beep()</code></h3>
播放beep聲音。
<h3 id="shell-writeShortcutLink"><code>shell.writeShortcutLink(shortcutPath[, operation], options)</code> <i>(Windows)</i></h3>
-
shortcutPath
String類型 -
operation
String類型(可選參數)- 默認是create
,可以使用下面中的一個:-
create
- 創建一個新的快捷方式,如果需要將覆蓋。 -
update
- 在現有的快捷方式上只更新指定屬性。 -
replace
- 覆蓋現有的快捷方式,如果快捷方式不存在將報錯。
-
-
options
ShortcutDetails類型
返回值為Boolean
類型 - 快捷方式是否被創建成功。
創建或者更新shortcutPath
下的一個快捷方式的鏈接
<h3 id="shell-"><code>shell.readShortcutLink(shortcutPath) Windows</code><i>(Windows)</i></h3>
-
shortcutPath
String類型
返回值為ShortcutDetails
類型
分解shortcutPath
下的快捷方式的鏈接。
任何錯誤發生時都將會拋出一個意外。