Skip to content

Commit ff852fc

Browse files
committed
add desktop notifications
1 parent 83f7a10 commit ff852fc

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ require (
1818
github.com/davecgh/go-spew v1.1.1 // indirect
1919
github.com/dustin/go-humanize v1.0.1 // indirect
2020
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
21+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
22+
github.com/godbus/dbus/v5 v5.1.0 // indirect
2123
github.com/google/uuid v1.3.0 // indirect
2224
github.com/gorilla/websocket v1.5.0 // indirect
2325
github.com/json-iterator/go v1.1.12 // indirect
@@ -32,13 +34,15 @@ require (
3234
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3335
github.com/modern-go/reflect2 v1.0.2 // indirect
3436
github.com/nikoksr/notify v0.41.0 // indirect
37+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
3538
github.com/pkg/errors v0.9.1 // indirect
3639
github.com/pmezard/go-difflib v1.0.0 // indirect
3740
github.com/rs/xid v1.5.0 // indirect
3841
github.com/sirupsen/logrus v1.9.3 // indirect
3942
github.com/slack-go/slack v0.12.2 // indirect
4043
github.com/stretchr/objx v0.5.0 // indirect
4144
github.com/stretchr/testify v1.8.4 // indirect
45+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
4246
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
4347
golang.org/x/crypto v0.11.0 // indirect
4448
golang.org/x/net v0.12.0 // indirect
@@ -55,6 +59,7 @@ require (
5559
github.com/AlecAivazis/survey/v2 v2.3.7
5660
github.com/denisbrodbeck/machineid v1.0.1
5761
github.com/emirpasic/gods v1.18.1
62+
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd
5863
github.com/golang-module/carbon/v2 v2.2.3
5964
github.com/kr/pretty v0.3.1 // indirect
6065
github.com/minio/minio-go v6.0.14+incompatible

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 h1:XBBHcIb256gUJ
2424
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203/go.mod h1:E1jcSv8FaEny+OP/5k9UxZVw9YFWGj7eI4KR/iOBqCg=
2525
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
2626
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
27+
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd h1:eVPIv7aXHQYJ5lbhXHoJyfPhivIn+BvH2xPoG62lT2w=
28+
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
2729
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU=
2830
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
2931
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
32+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
33+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
3034
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
35+
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
36+
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
3137
github.com/golang-module/carbon/v2 v2.2.3 h1:WvGIc5+qzq9drNzH+Gnjh1TZ0JgDY/IA+m2Dvk7Qm4Q=
3238
github.com/golang-module/carbon/v2 v2.2.3/go.mod h1:LdzRApgmDT/wt0eNT8MEJbHfJdSqCtT46uZhfF30dqI=
3339
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
@@ -86,6 +92,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
8692
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
8793
github.com/nikoksr/notify v0.41.0 h1:4LGE41GpWdHX5M3Xo6DlWRwS2WLDbOq1Rk7IzY4vjmQ=
8894
github.com/nikoksr/notify v0.41.0/go.mod h1:FoE0UVPeopz1Vy5nm9vQZ+JVmYjEIjQgbFstbkw+cRE=
95+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
96+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
8997
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
9098
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
9199
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -126,6 +134,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
126134
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
127135
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
128136
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
137+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
138+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
129139
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
130140
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
131141
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=

lib/app/scriptNotifications.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ type ScriptNotifications struct {
1111
Vm *otto.Otto
1212
telegramObj *ScriptNotificationsTelegram
1313
slackObj *ScriptNotificationsSlack
14+
desktopObj *DesktopNotification
15+
}
16+
17+
type DesktopNotification struct {
18+
state struct {
19+
title string
20+
message string
21+
}
1422
}
1523

1624
type ScriptNotificationsTelegram struct {
@@ -40,10 +48,41 @@ func CreateScripNotificationsObject(vm *otto.Otto) {
4048
slackObj: &ScriptNotificationsSlack{
4149
WebhookUrl: "",
4250
},
51+
desktopObj: &DesktopNotification{},
4352
}
4453
vm.Set("notifications", obj)
4554
}
4655

56+
func (dn *DesktopNotification) create() *DesktopNotification {
57+
dn.resetState()
58+
59+
return dn
60+
}
61+
62+
func (dn *DesktopNotification) Send() bool {
63+
result := notifications.NewDesktopNotification().
64+
Send(dn.state.title, dn.state.message)
65+
66+
dn.resetState()
67+
return result == nil
68+
}
69+
70+
func (dn *DesktopNotification) resetState() {
71+
dn.state.title = ""
72+
dn.state.message = ""
73+
}
74+
75+
func (dn *DesktopNotification) Message(message string) *DesktopNotification {
76+
dn.state.message = message
77+
dn.state.title = "notification"
78+
79+
return dn
80+
}
81+
82+
func (sn *ScriptNotifications) Desktop() *DesktopNotification {
83+
return sn.desktopObj
84+
}
85+
4786
func (sn *ScriptNotifications) Telegram() *ScriptNotificationsTelegram {
4887
token := App.Workflow.Settings.Notifications.Telegram.APIKey
4988
return sn.telegramObj.create(token)

lib/notifications/desktop.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package notifications
2+
3+
import (
4+
"github.com/gen2brain/beeep"
5+
)
6+
7+
type DesktopNotification struct {
8+
}
9+
10+
// NewDesktopNotification creates a new instance of the DesktopNotification
11+
// struct.
12+
func NewDesktopNotification() *DesktopNotification {
13+
return &DesktopNotification{}
14+
}
15+
16+
func (tn *DesktopNotification) Send(title, message string) error {
17+
return beeep.Notify(title, message, "")
18+
}

0 commit comments

Comments
 (0)