Skip to content

API Reference / @gtkx/runtime / runApplication

Variable: runApplication

const runApplication: (application, argv) => RunApplicationResult

Defined in: packages/runtime/dist/lifecycle.d.ts:79

Hands argv to GLib's own command line handling, which parses the application's options, prints --help, runs handle-local-options, registers the application, and either activates it or forwards the command line to the process that already owns the application ID. The runtime is held alive while the application is active and released on shutdown.

g_application_run() is not what starts the application, because it would drive its own main loop and freeze Node; only the local command line handling it delegates to runs here. quitApplication calls it once no window holds the application open, to reach the teardown only it performs.

GLib parses a given application's command line at most once, so starting an application that has already run registers and activates it instead of reading argv again.

When another process already owns the application ID, this one registers as a remote instance: no user interface may be built here, because a remote application has no GtkApplicationImpl and attaching a window to it crashes.

The application also claims the process-wide default Gio.Application.getDefault() returns, before its command line is parsed, so an activate handler and anything the host reads afterwards see the application being started rather than an earlier one. That holds whether the start ends registered, remote or unregistered: a refused command line still has to be reportable through the default, which is how gtkx dev learns which application its entry mounted. quitApplication gives the default back up, since GLib drops it only at finalize.

Parameters

application

ApplicationLike

The application to start.

argv

string[]

The command line, whose first entry names the program as --help should print it.

Returns

RunApplicationResult

Whether this process may build a user interface, and the status to exit with.

Released under the MPL-2.0 License.