-
Notifications
You must be signed in to change notification settings - Fork 14
/
notificationHandler.go
66 lines (55 loc) · 1.65 KB
/
notificationHandler.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"github.com/0xAX/notificator" //for desktop
"github.com/therecipe/qt/androidextras"
"github.com/therecipe/qt/core"
"runtime"
"fmt"
)
type NotificationHandler struct {
AndroidNotifier *NotificationClient
DesktopNotifier *notificator.Notificator
}
type NotificationClient struct {
core.QObject
_ func() `constructor:"init"`
_ string `property:"notification"`
_ func(string) `slot:"updateAndroidNotification"`
}
func (n *NotificationHandler) Initialise() {
n.AndroidNotifier = NewNotificationClient(nil)
n.AndroidNotifier.ConnectNotificationChanged(n.AndroidNotifier.updateAndroidNotification)
//initialise the notifiers
n.DesktopNotifier = notificator.New(notificator.Options{
DefaultIcon: "",
AppName: "WingIt",
})
}
func (n *NotificationHandler) Push(title, message string) {
switch runtime.GOOS {
case "android":
//in this case, we are notifying on android
// notificationClient = NewNotificationClient(view)
// view.Engine().RootContext().SetContextProperty("notificationClient", notificationClient)
fmt.Println("setting android notification")
n.AndroidNotifier.SetNotification(message)
default:
//notifying on desktop
n.DesktopNotifier.Push(title, message, "", notificator.UR_CRITICAL)
}
}
func (c *NotificationClient) init() {
c.ConnectNotificationChanged(c.updateAndroidNotification)
}
func (c *NotificationClient) updateAndroidNotification(n string) {
fmt.Println("string is ", n)
var err = androidextras.QAndroidJniObject_CallStaticMethodVoid2Caught(
"org/qtproject/example/notification/NotificationClient",
"notify",
"(Ljava/lang/String;)V",
n,
)
if err != nil {
println(err.Error())
}
}