roElectronEvent
4 min
Events from roElectron are delivered to the supplied message_port as roElectronEvent objects. Call GetData() on the event to retrieve an associative array describing it. The reason key identifies the event type, for example:
- message: A message was sent from the JavaScript side using the MessagePort class; the payload is in the message key.
- process_exit: The Electron process exited. The exit_code contains the exit status.
ifUserData
SetUserData(user_data As Object)
Sets the user data that will be returned when events are raised.
GetUserData() As Object
Returns the user data that has previously been set via SetUserData(). It will return Invalid if no data has been set.
ifElectronEvent
GetData() As roAssociativeArray
Returns the event data as an associative array with the following key/value pairs:
- reason string: The cause of the event, which can be one of the following:
- process_exit: The Electron instance has exited.
- message: The Electron instance has sent a message*.*
- exit_code number: The value of this field is set by the Electron application when it exits (~~~~). The Electron process exit code is only defined in OS 8.2 and later OS versions. Note that the Electron script can also use these codes for its own purposes.
- message string: If the reason field value is message, this field returns the contents of the message.
Example
msgPort = CreateObject("roMessagePort")
electronConfig = {
app_name: "MyApp"
message_port: msgPort
}
electron = CreateObject("roElectron", "file://sd:/app.asar", electronConfig)
electron.PostJsMessage({ command: "start" })
while true
msg = wait(0, msgPort)
if type(msg) = "roElectronEvent" then
data = msg.GetData()
print data.reason
end if
end while