'show the browser notification
Sub ShowBrowserNotification(Title As String, Desc As String, Url As String, Icon As String, Vibrate As Boolean, Seconds As Int) 'ignoreDeadCode
'get the notification oject
Dim notif As BANanoObject = BANano.Window.GetField("Notification")
'check the permission
Dim permission As String = notif.GetField("permission").Result
If permission <> "granted" Then
'requestPermission
Dim resp As String = BANano.Await(notif.RunMethod("requestPermission", Null))
If resp <> "granted" Then Return
End If
Dim Options As Map = CreateMap()
Options.Put("icon", Icon)
Options.Put("body", Desc)
Options.Put("vibrate", Vibrate)
'
Dim n As BANanoObject
n.Initialize2("Notification", Array(Title, Options))
Dim showEvent As String = "notification_show"
Dim closeEvent As String = "notification_close"
Dim errorEvent As String = "notification_error"
Dim clickEvent As String = "notification_click"
If SubExists(EventHandler, showEvent) Then
n.AddEventListener("show", BANano.CallBack(EventHandler, showEvent, Null), False)
End If
If SubExists(EventHandler, clickEvent) Then
n.AddEventListener("click", BANano.CallBack(EventHandler, clickEvent, Null), False)
End If
If SubExists(EventHandler, errorEvent) Then
n.AddEventListener("error", BANano.CallBack(EventHandler, errorEvent, Null), False)
End If
If SubExists(EventHandler, closeEvent) Then
n.AddEventListener("close", BANano.CallBack(EventHandler, closeEvent, Null), False)
End If
'close after
Dim cbClose As BANanoObject = BANano.callback(Me, "CloseNotification", Array(n))
Dim Sec As Int = Seconds * 1000
BANano.Window.SetTimeout(cbClose, Sec)
End Sub
private Sub CloseNotification(n As BANanoObject) 'ignoreDeadCode
n.RunMethod("close", Null)
End Sub