Skip to content

Commit 2a3f53c

Browse files
authored
Merge pull request normen#37 from keegancsmith/terminal-bell
add UseTerminalBell as an alternative to desktop notifications
2 parents b98af9f + cc71c29 commit 2a3f53c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ To configure the used command and its parameters edit the `show_command` paramet
8484

8585
Some commands such as the `/add` and `/remove` require a "user id" as their input. You can copy the user ID of a selected chat or a selected message to the clipboard with `Ctrl-c` (default mapping) and easily append them to the current input using `Ctrl-v`.
8686

87-
### Desktop Notifications
87+
### Notifications
8888

89-
The app supports basic desktop notifications through the `gen2brain/beeep` library, to enable it set `enable_notifications = true` in `whatscli.config`.
89+
The app supports basic desktop notifications through the `gen2brain/beeep` library, to enable it set `enable_notifications = true` in `whatscli.config`. Set `use_terminal_bell = true` to ring your terminal's bell instead of sending a desktop notification.
9090

9191
### Configuration
9292

config/settings.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type General struct {
2525
CmdPrefix string
2626
ShowCommand string
2727
EnableNotifications bool
28+
UseTerminalBell bool
2829
NotificationTimeout int64
2930
}
3031

@@ -76,6 +77,7 @@ var Config = IniFile{
7677
CmdPrefix: "/",
7778
ShowCommand: "jp2a --color",
7879
EnableNotifications: false,
80+
UseTerminalBell: false,
7981
NotificationTimeout: 60,
8082
},
8183
&Keymap{

messages/session_manager.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func (sm *SessionManager) runManager() error {
8989
if int64(msg.Info.Timestamp) > time.Now().Unix()-30 {
9090
if int64(msg.Info.Timestamp) > sm.lastSent.Unix()+config.Config.General.NotificationTimeout {
9191
sm.db.NewUnreadChat(msg.Info.RemoteJid)
92-
if config.Config.General.EnableNotifications && !msg.Info.FromMe {
93-
err := beeep.Notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text, "")
92+
if !msg.Info.FromMe {
93+
err := notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text)
9494
if err != nil {
9595
sm.uiHandler.PrintError(err)
9696
}
@@ -101,8 +101,8 @@ func (sm *SessionManager) runManager() error {
101101
// notify if message is younger than 30 sec and not in focus
102102
if int64(msg.Info.Timestamp) > time.Now().Unix()-30 {
103103
sm.db.NewUnreadChat(msg.Info.RemoteJid)
104-
if config.Config.General.EnableNotifications && !msg.Info.FromMe {
105-
err := beeep.Notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text, "")
104+
if !msg.Info.FromMe {
105+
err := notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text)
106106
if err != nil {
107107
sm.uiHandler.PrintError(err)
108108
}
@@ -985,3 +985,15 @@ func writeSession(session whatsapp.Session) error {
985985
func removeSession() error {
986986
return os.Remove(config.GetSessionFilePath())
987987
}
988+
989+
// notify will send a notification via beeep if EnableNotification is true. If
990+
// UseTerminalBell is true it will send a terminal bell instead.
991+
func notify(title, message string) error {
992+
if !config.Config.General.EnableNotifications {
993+
return nil
994+
} else if config.Config.General.UseTerminalBell {
995+
_, err := fmt.Printf("\a")
996+
return err
997+
}
998+
return beeep.Notify(title, message, "")
999+
}

0 commit comments

Comments
 (0)