App
- App
- App.argv
- App.fullArgv
- App.filteredArgv
- App.startPath
- App.dataPath
- App.manifest
- App.clearCache()
- App.clearAppCache(manifest_url)
- App.closeAllWindows()
- App.crashBrowser()
- App.crashRenderer()
- App.enableComponent(component, callback)
- App.getProxyForURL(url)
- App.setProxyConfig(config, pac_url)
- App.quit()
- App.setCrashDumpDir(dir)
- App.addOriginAccessWhitelistEntry(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains)
- App.removeOriginAccessWhitelistEntry(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains)
- App.registerGlobalHotKey(shortcut)
- App.unregisterGlobalHotKey(shortcut)
- App.updateComponent(component, callback)
- 事件:open(args)
- 事件:reopen
App.argv
在啟動應用程式時取得經過篩選的命令列參數。在 NW.js 中,某些命令列參數會由 NW.js 使用,而您的應用程式不應對這些參數感興趣。App.argv
會過濾掉這些參數,並傳回剩餘的參數。您可以從 App.filteredArgv
取得經過篩選的模式,並從 App.fullArgv
取得完整的參數。
App.fullArgv
在啟動應用程式時取得所有命令列參數。傳回值包含 NW.js 使用的參數,例如 --nwapp
、--remote-debugging-port
等。
App.filteredArgv
取得 App.argv
使用的經過篩選的命令列參數模式清單。預設情況下,會使用下列模式來篩選參數
[ /^--url=/, /^--remote-debugging-port=/, /^--renderer-cmd-prefix=/, /^--nwapp=/ ]
App.startPath
取得應用程式啟動的目錄。應用程式會在啟動後將目前目錄變更為封裝檔案所在的目錄。
App.dataPath
取得使用者目錄中的應用程式資料路徑。
- Windows:
%LOCALAPPDATA%/<name>
- Linux:
~/.config/<name>
- OS X:
~/Library/Application Support/<name>/Default
(在 v0.12.3 及以下版本中為~/Library/Application Support/<name>
)
<name>
是 package.json
清單中的 名稱欄位。
App.manifest
取得清單檔案的 JSON 物件。
App.clearCache()
清除記憶體中的 HTTP 快取和磁碟上的快取。此方法呼叫是同步的。
App.clearAppCache(manifest_url)
將 manifest_url 指定的應用程式快取群組標記為過時。此方法呼叫是同步的。
App.closeAllWindows()
將 close
事件傳送至目前應用程式的所有視窗,如果沒有視窗會封鎖 close
事件,則在所有視窗都已關閉後,應用程式會結束。使用此方法結束應用程式會讓視窗有機會儲存資料。
App.crashBrowser()
App.crashRenderer()
這兩個函式分別讓瀏覽器程序和渲染程序崩潰,以測試崩潰傾印功能。
App.enableComponent(component, callback)
實驗性
此 API 為實驗性質,可能會變更。
component
{字串}
組件 ID;目前僅支援WIDEVINE
。callback
function(version)
在組件啟用後呼叫回;version
字串參數為已啟用組件的版本。‘0.0.0.0’ 表示未安裝。請使用App.updateComponent()
安裝它。
App.getProxyForURL(url)
url
{字串}
要查詢代理伺服器的 URL
查詢要使用在 DOM 中載入 url
的代理伺服器。傳回值格式與 PAC 中使用的一樣(例如「DIRECT」、「PROXY localhost:8080」)。
App.setProxyConfig(config, pac_url)
config
{字串}
代理伺服器規則pac_url
{字串}
PAC URL
設定代理伺服器組態,讓網頁引擎用來要求網路資源或 PAC URL 以自動偵測代理伺服器。
規則(從 net/proxy/proxy_config.h
複製)
// Parses the rules from a string, indicating which proxies to use. // // proxy-uri = [<proxy-scheme>"://"]<proxy-host>[":"<proxy-port>] // // proxy-uri-list = <proxy-uri>[","<proxy-uri-list>] // // url-scheme = "http" | "https" | "ftp" | "socks" // // scheme-proxies = [<url-scheme>"="]<proxy-uri-list> // // proxy-rules = scheme-proxies[";"<scheme-proxies>] // // Thus, the proxy-rules string should be a semicolon-separated list of // ordered proxies that apply to a particular URL scheme. Unless specified, // the proxy scheme for proxy-uris is assumed to be http. // // Some special cases: // * If the scheme is omitted from the first proxy list, that list applies // to all URL schemes and subsequent lists are ignored. // * If a scheme is omitted from any proxy list after a list where a scheme // has been provided, the list without a scheme is ignored. // * If the url-scheme is set to 'socks', that sets a fallback list that // to all otherwise unspecified url-schemes, however the default proxy- // scheme for proxy urls in the 'socks' list is understood to be // socks4:// if unspecified. // // For example: // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http:// // URLs, and HTTP proxy "foopy2:80" for // ftp:// URLs. // "foopy:80" -- use HTTP proxy "foopy:80" for all URLs. // "foopy:80,bar,direct://" -- use HTTP proxy "foopy:80" for all URLs, // failing over to "bar" if "foopy:80" is // unavailable, and after that using no // proxy. // "socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all // URLs. // "http=foop,socks5://bar.com -- use HTTP proxy "foopy" for http URLs, // and fail over to the SOCKS5 proxy // "bar.com" if "foop" is unavailable. // "http=foopy,direct:// -- use HTTP proxy "foopy" for http URLs, // and use no proxy if "foopy" is // unavailable. // "http=foopy;socks=foopy2 -- use HTTP proxy "foopy" for http URLs, // and use socks4://foopy2 for all other // URLs.
App.quit()
結束目前的應用程式。此方法不會傳送 close
事件至視窗,而應用程式會安靜地結束。
App.setCrashDumpDir(dir)
已棄用
此 API 已自 0.11.0 起棄用。
dir
{字串}
產生崩潰傾印的目錄
設定崩潰時會儲存小型傾印檔案的目錄。如需更多資訊,請參閱 崩潰傾印。
App.addOriginAccessWhitelistEntry(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains)
sourceOrigin
{字串}
來源來源。例如http://github.com/
destinationProtocol
{String}
sourceOrigin
可以存取的目標通訊協定。例如:app
destinationHost
{String}
sourceOrigin
可以存取的目標主機。例如:myapp
allowDestinationSubdomains
{Boolean}
如果設為 true,sourceOrigin
可以存取目標的子網域。
新增項目至用於控制跨來源存取的白名單。假設您要允許從 github.com
HTTP 轉址至應用程式頁面,請使用類似以下內容
App.addOriginAccessWhitelistEntry('http://github.com/', 'chrome-extension', location.host, true);
使用 App.removeOriginAccessWhitelistEntry
搭配完全相同的參數,執行相反的動作。
App.removeOriginAccessWhitelistEntry(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains)
sourceOrigin
{字串}
來源來源。例如http://github.com/
destinationProtocol
{String}
sourceOrigin
可以存取的目標通訊協定。例如:app
destinationHost
{String}
sourceOrigin
可以存取的目標主機。例如:myapp
allowDestinationSubdomains
{Boolean}
如果設為 true,sourceOrigin
可以存取目標的子網域。
從用於控制跨來源存取的白名單中移除項目。請參閱上方的 addOriginAccessWhitelistEntry
。
App.registerGlobalHotKey(shortcut)
shortcut
{Shortcut}
要註冊的Shortcut
物件。
在系統中註冊全域鍵盤快速鍵 (也稱為系統範圍熱鍵)。
請參閱 Shortcut 以取得更多資訊。
App.unregisterGlobalHotKey(shortcut)
shortcut
{Shortcut}
要取消註冊的Shortcut
物件。
取消註冊全域鍵盤快速鍵。
請參閱 Shortcut 以取得更多資訊。
App.updateComponent(component, callback)
實驗性
此 API 為實驗性質,可能會變更。
component
{字串}
組件 ID;目前僅支援WIDEVINE
。callback
function(success)
元件更新後的回呼;success
是更新結果的布林參數。
事件:open(args)
args
{String}
程式的完整命令列。
當使用者使用您的應用程式開啟檔案時發出。
事件:reopen
這是 Mac 的特定功能。當使用者按一下已經執行的應用程式的 Dock 圖示時,會傳送此事件。