App - Hosting-Site/node-webkit GitHub Wiki

Since v0.3.1

Synopsis

// Load native UI library
var gui = require('nw.gui');

// Print arguments
console.log(gui.App.argv);

// Quit current app
gui.App.quit();

// Get the name field in manifest
gui.App.manifest.name

Reference

argv

Get the command line arguments when starting the app.

fullArgv

Get all the command line arguments when starting the app. Because node-webkit itself used switches like --no-sandbox and --process-per-tab, it would confuse the app when the switches were meant to be given to node-webkit, so App.argv just filtered such switches (arguments' precedence were kept). You can get the switches to be filtered with App.filteredArgv.

dataPath

since v0.6.1

Get the application's data path in user's directory. Windows: %LOCALAPPDATA%/<name>; Linux: ~/.config/<name>; OSX: ~/Library/Application Support/<name> where <name> is the field in the manifest.

manifest

since v0.7.0

Get the JSON object of the manifest file.

clearCache()

Since v0.6.0

Clear the HTTP cache in memory and the one on disk. This method call is synchronized.

closeAllWindows()

since v0.3.2

Send the close event to all windows of current app, if no window is blocking the close event, then the app will quit after all windows have done shutdown. Use this method to quit an app will give windows a chance to save data.

crashBrowser(), crashRenderer()

since v0.8.0

These 2 functions crashes the browser process and the renderer process respectively, to test the Crash dump feature.

getProxyForURL(url)

since v0.6.3

Query the proxy to be used for loading url in DOM. The return value is in the same format used in PAC (e.g. "DIRECT", "PROXY localhost:8080").

quit()

Quit current app. This method will not send close event to windows and app will just quit quietly.

setCrashDumpDir(dir)

since v0.8.0

Set the directory where the minidump file will be saved on crash. For more information, see Crash dump

Events

Following events can be listened by using App.on() function, for more information on how to receive events, you can visit EventEmitter.

open

Since v0.3.2

Emitted when users opened a file with your app. There is a single parameter of this event callback: Since v0.7.0, it is the full command line of the program; before that it's the argument in the command line and the event is sent multiple times for each of the arguments. For more on this, see Handling files and arguments.

reopen

since v0.7.3

This is a Mac specific feature. This event is sent when the user clicks the dock icon for an already running application.

⚠️ **GitHub.com Fallback** ⚠️