mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-10 12:52:57 +08:00
update example
This commit is contained in:
parent
bf4222c9cc
commit
c904433ff3
@ -1,7 +1,6 @@
|
|||||||
import * as Notifications from "./bindings/github.com/wailsapp/wails/v3/pkg/services/notifications/service";
|
import * as Notifications from "./bindings/github.com/wailsapp/wails/v3/pkg/services/notifications/service";
|
||||||
import { Events, System } from "@wailsio/runtime";
|
import { Events, System } from "@wailsio/runtime";
|
||||||
|
|
||||||
const timeElement = document.getElementById('time');
|
|
||||||
const notificationsElement = document.getElementById('notifications');
|
const notificationsElement = document.getElementById('notifications');
|
||||||
|
|
||||||
window.sendNotification = async () => {
|
window.sendNotification = async () => {
|
||||||
@ -51,10 +50,6 @@ window.sendComplexNotification = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Events.On('time', (time) => {
|
|
||||||
timeElement.innerText = time.data;
|
|
||||||
});
|
|
||||||
|
|
||||||
Events.On("notificationResponse", (response) => {
|
Events.On("notificationResponse", (response) => {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
notificationsElement.innerText += JSON.stringify(response.data[0].data);
|
notificationsElement.innerText += JSON.stringify(response.data[0].data);
|
||||||
|
@ -60,52 +60,69 @@ func main() {
|
|||||||
URL: "/",
|
URL: "/",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.OnEvent("notificationResponse", func(event *application.CustomEvent) {
|
||||||
|
data, _ := json.Marshal(event.Data)
|
||||||
|
fmt.Printf("%s\n", string(data))
|
||||||
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
app.OnEvent("notificationResponse", func(event *application.CustomEvent) {
|
granted, err := NotificationService.RequestUserNotificationAuthorization()
|
||||||
data, _ := json.Marshal(event.Data)
|
if err != nil {
|
||||||
fmt.Printf("%s\n", string(data))
|
log.Default().Printf("WARNING: %s\n", err)
|
||||||
})
|
return
|
||||||
|
}
|
||||||
|
|
||||||
NotificationService.RequestUserNotificationAuthorization()
|
if granted {
|
||||||
NotificationService.CheckNotificationAuthorization()
|
time.Sleep(time.Second * 2)
|
||||||
|
|
||||||
time.Sleep(time.Second * 2)
|
var uuid1 string = "Wails Notification Demo"
|
||||||
NotificationService.SendNotification(notifications.NotificationOptions{
|
if application.Get().Environment().OS == "darwin" {
|
||||||
ID: "Wails Notification Demo",
|
uuid1 = "uuid1"
|
||||||
Title: "Title!",
|
}
|
||||||
Body: "Body!",
|
|
||||||
Data: map[string]interface{}{
|
|
||||||
"messageId": "msg-123",
|
|
||||||
"senderId": "user-123",
|
|
||||||
"timestamp": time.Now().String(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
time.Sleep(time.Second * 2)
|
NotificationService.SendNotification(notifications.NotificationOptions{
|
||||||
NotificationService.RegisterNotificationCategory(notifications.NotificationCategory{
|
ID: uuid1,
|
||||||
ID: "BACKEND_NOTIF",
|
Title: "Title!",
|
||||||
Actions: []notifications.NotificationAction{
|
Body: "Body!",
|
||||||
{ID: "VIEW_ACTION", Title: "View"},
|
Data: map[string]interface{}{
|
||||||
{ID: "MARK_READ_ACTION", Title: "Mark as Read"},
|
"messageId": "msg-123",
|
||||||
{ID: "DELETE_ACTION", Title: "Delete", Destructive: true},
|
"senderId": "user-123",
|
||||||
},
|
"timestamp": time.Now().String(),
|
||||||
HasReplyField: true,
|
},
|
||||||
ReplyButtonTitle: "Reply",
|
})
|
||||||
ReplyPlaceholder: "Reply to backend...",
|
|
||||||
})
|
|
||||||
|
|
||||||
NotificationService.SendNotificationWithActions(notifications.NotificationOptions{
|
time.Sleep(time.Second * 2)
|
||||||
ID: "Wails Notification Demo",
|
|
||||||
Title: "Complex Backend Notification",
|
var uuid2 string = "Wails Notification Demo"
|
||||||
Subtitle: "Should not show on Windows",
|
if application.Get().Environment().OS == "darwin" {
|
||||||
Body: "Is it raining today where you are?",
|
uuid2 = "uuid2"
|
||||||
CategoryID: "BACKEND_NOTIF",
|
}
|
||||||
Data: map[string]interface{}{
|
|
||||||
"messageId": "msg-456",
|
NotificationService.RegisterNotificationCategory(notifications.NotificationCategory{
|
||||||
"senderId": "user-456",
|
ID: "BACKEND_NOTIF",
|
||||||
"timestamp": time.Now().String(),
|
Actions: []notifications.NotificationAction{
|
||||||
},
|
{ID: "VIEW_ACTION", Title: "View"},
|
||||||
})
|
{ID: "MARK_READ_ACTION", Title: "Mark as Read"},
|
||||||
|
{ID: "DELETE_ACTION", Title: "Delete", Destructive: true},
|
||||||
|
},
|
||||||
|
HasReplyField: true,
|
||||||
|
ReplyButtonTitle: "Reply",
|
||||||
|
ReplyPlaceholder: "Reply to backend...",
|
||||||
|
})
|
||||||
|
|
||||||
|
NotificationService.SendNotificationWithActions(notifications.NotificationOptions{
|
||||||
|
ID: uuid2,
|
||||||
|
Title: "Complex Backend Notification",
|
||||||
|
Subtitle: "Should not show on Windows",
|
||||||
|
Body: "Is it raining today where you are?",
|
||||||
|
CategoryID: "BACKEND_NOTIF",
|
||||||
|
Data: map[string]interface{}{
|
||||||
|
"messageId": "msg-456",
|
||||||
|
"senderId": "user-456",
|
||||||
|
"timestamp": time.Now().String(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Run the application. This blocks until the application has been exited.
|
// Run the application. This blocks until the application has been exited.
|
||||||
|
Loading…
Reference in New Issue
Block a user