Event-Driven Logic

Using Skylight Application Builder, event-based logic that executes locally on clients can be configured to trigger in response to application, view, and card events. Depending on the event type, you can utilize either pre-built Actions or Custom Actions that execute an Event Script. Event Scripts are written in JavaScript inside of Application Builder and interact with the Skylight Scripting API.

Examples include:

  • When a user opens an application, a previously created session is set so that they see their up-to-date progress.

  • When a user opens a new view, the time is recorded into the session data to track when the user has started the task.

  • When a user selects a card, an update is made to the session data to signify that the task has been completed.

These examples are purposefully generic – the true power of events scripts is that you as a developer can tailor the behavior of your Skylight application to fit your exact needs.

Application Events

To create an event script for an application event, select the button on the left sidebar in Application Builder and select Events. Select the event to open a dialog for authoring the script.

Application Opened

This event occurs when the application is first selected from the list of applications or the user returns to Skylight after exiting Skylight with the application open.

The event object will be accessible in the script with the following properties:

  • event.event: name of the event (i.e. application_opened)

  • event.applicationId: id of the application (e.g. 5e8ce5bfab9f8886b63d318a)

Application Closed

This event occurs when the user exits the application or exits Skylight with the application open.

Application Event

This event occurs for all other events, including application, view, and card events.

The event object will be accessible in the script with any of the properties that would be normally be associated with the event being called.

View Events

To access a particular view's events, select the view from the list on the left. Actions can then be added to the events that appear in the Events & actions section of the Properties panel on the right side.

View Opened

This event occurs when the view is opened, which can occur if:

  • The user selects this application and this view is the root view.

  • This view was opened using skylight.openView in a client-side script.

  • This view was opened using an Open view action.

  • This view was opened as a result of the user re-opening Skylight after exiting Skylight with this view open.

Currently, this event is not triggered if a view is opened as a result of using the back button on the web client, or performing a Navigate Back action on the smart glasses client (e.g. swipe-down on Glass EE2 or a long-press on the select button on Vuzix M400).

The event object is accessible in this script with the following properties:

  • event.event: the name of the event (i.e., view_opened)

  • event.applicationId: the application’s id (e.g., 5e8ce5bfab9f8886b63d318a)

  • event.viewId: the view’s id (e.g., root)

View Closed

This event occurs when the view is closed, which can occur if:

  • The user goes to the previous page.

  • The view was closed using skylight.closeView.

  • The user exited Skylight with this view open.

The event object is accessible in this script with the following properties:

  • event.event: the name of the event (i.e., view_closed)

  • event.applicationId: the application’s id (e.g., 5e8ce5bfab9f8886b63d318a)

  • event.viewId: the view’s id (e.g., root)

Bluetooth Input

This event occurs when a bluetooth input is received.

The event object is accessible in this script with the following properties:

  • event.event: the name of the event (i.e., view_closed)

  • event.applicationId: the application’s id (e.g., 5e8ce5bfab9f8886b63d318a)

  • event.viewId: the view’s id (e.g., root)

  • event.bluetoothInput: the Bluetooth input (e.g., 01429391)

Card Events

To access a particular card's events, select the card in the Workflow area. Actions can then be added to the events that appear in the Events & actions section of the Properties panel on the right side.

On Select

This event occurs when a user selects a card.

The event object is accessible in this script with the following properties:

  • event.event: name of the event (i.e., card_selected)

  • event.applicationId: the application’s id (e.g., 5e8ce5bfab9f8886b63d318a)

  • event.viewId: the view’s id (e.g., root)

  • event.cardId: the card’s id (e.g., a73a32cc-3783-4d02-bb30-7e0ea4ab1ff4)

  • event.data: if there is data that is bound to this card, this will have that data. See Data Binding and Adapters for details.

It is possible to add multiple actions to an On Select event. In this case, an action sheet will appear when the card is selected, allowing the user to select one of the actions (distinguished by the Label and Icon of the action).

Action sheet displayed on smart glasses client

Actions

The following actions can be configured for view and card events:

Open View Action

When triggered, a specified view or card in a view will be displayed and brought into focus.

The Open View action cannot be configured to open collection views or cards with a data binding context that is data bound to an array.

Custom Action

When triggered, a specified event script will be executed.

Application Navigation Menu

The navigation menu allows users to access top-level Skylight features (such as settings, applications, and sign out) from any level of an application. Using Application Builder, developers can also inject custom actions to the navigation menu.

Application navigation menu with custom actions

To add custom actions to the navigation menu, select the button on the left sidebar in Application Builder and select Menu. You can then add actions or custom actions that execute an event script for each menu item.