forked from wailsapp/wails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipc_event.go
40 lines (31 loc) · 871 Bytes
/
ipc_event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package wails
import (
"encoding/json"
)
type eventData struct {
Name string `json:"name"`
Data interface{} `json:"data"`
}
// Register the message handler
func init() {
messageProcessors["event"] = processEventData
}
// This processes the given event message
func processEventData(message *ipcMessage) (*ipcMessage, error) {
// TODO: Is it worth double checking this is actually an event message,
// even though that's done by the caller?
var payload eventData
// Decode event data
payloadMap := message.Payload.(map[string]interface{})
payload.Name = payloadMap["name"].(string)
// decode the payload data
var data []interface{}
err := json.Unmarshal([]byte(payloadMap["data"].(string)), &data)
if err != nil {
return nil, err
}
payload.Data = data
// Reassign payload to decoded data
message.Payload = &payload
return message, nil
}