Skip to main content

Neutralino.events

Neutralino.events namespace contains methods related to the native events handling. These events are often initiated by the Neutralinojs server based on native state changes.

Event types#

Event idDescriptionAvailable modesAdditional data
readyOccurs when the client library connects with the Neutralino server.allnull
trayMenuItemClickedOccurs when the user clicks on a tray menu item.allTrayMenuItem
windowCloseOccurs when the user closes the window.windownull
windowFocusOccurs when the window gets focused.windownull
windowBlurOccurs when the window focus state is gone.windownull
serverOfflineOccurs when the Neutralino server is offlineallnull
clientConnectOccurs when a new client access the application.allTotal clients
clientDisconnectOccurs when a connected client leaves the application.allTotal clients
appClientConnectOccurs when a new application instance starts.allTotal app clients
appClientDisconnectOccurs when an application instance ends.allTotal app clients
extClientConnectOccurs when a new extension connects.allExtension identifier
extClientDisconnectOccurs when an extension disconnects.allExtension identifer
extensionReadyOccurs when an extension is ready to communicate with the app.allExtension identifier
spawnedProcessOccurs then there is an update in the spawned process.allSpawnedProcess with action (stdOut, stdErr, and exit) and data (Action data)

events.on(eventName, handler)#

Registers a new event handler. 

Parameters#

  • eventName String: Name of the event.
  • handler Function: A function that will be called when the given event occurs. Neutralinojs will call the handler with a CustomEvent instance by attaching additional data to the detail key.
function onTrayMenuItemClicked(event) {
console.log(`Event data: ${event.detail}`);
}
await Neutralino.events.on('trayMenuItemClicked', onTrayMenuItemClicked);

events.off(eventName, handler)#

Unregisters an event handler. 

Parameters#

  • eventName String: Name of the event.
  • handler Function: A function reference.
await Neutralino.events.off('trayMenuItemClicked', onTrayMenuItemClicked);

events.dispatch(eventName, data)#

Dispatches a new event to the current app instance. Neutralinojs client uses this JavaScript function call internally to dispatch native events. 

Parameters#

  • eventName String: Name of the event.
  • data Object (optional): Additional data for the event.
await Neutralino.events.dispatch('myTestEvent', {myData: 'Test data'});

events.broadcast(eventName, data)#

Dispatches a new event to all clients (both app and extension clients).

Parameters#

  • eventName String: Name of the event.
  • data Object (optional): Additional data for the event.
await Neutralino.events.broadcast('myTestEvent', 'Hello');
await Neutralino.events.broadcast('myTestEvent', {myData: 'Test data'});
await Neutralino.events.broadcast('myTestEvent'); // without any data payload