Files
seanime-docker/seanime-2.9.10/internal/plugin/ui/notification.go
2025-09-20 14:08:38 +01:00

37 lines
805 B
Go

package plugin_ui
import (
"seanime/internal/notifier"
"github.com/dop251/goja"
)
type NotificationManager struct {
ctx *Context
}
func NewNotificationManager(ctx *Context) *NotificationManager {
return &NotificationManager{
ctx: ctx,
}
}
func (n *NotificationManager) bind(contextObj *goja.Object) {
notificationObj := n.ctx.vm.NewObject()
_ = notificationObj.Set("send", n.jsNotify)
_ = contextObj.Set("notification", notificationObj)
}
func (n *NotificationManager) jsNotify(call goja.FunctionCall) goja.Value {
message, ok := call.Argument(0).Export().(string)
if !ok {
n.ctx.handleTypeError("notification: notify requires a string message")
return goja.Undefined()
}
notifier.GlobalNotifier.Notify(notifier.Notification(n.ctx.ext.Name), message)
return goja.Undefined()
}