Add sounds to notifications
This commit is contained in:
parent
b31d968814
commit
e0298521c6
@ -270,18 +270,21 @@ func (c *Container) HandleMembership(evt *gomatrix.Event) {
|
|||||||
c.processOwnMembershipChange(evt)
|
c.processOwnMembershipChange(evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
roomView := c.ui.MainView().GetRoom(evt.RoomID)
|
mainView := c.ui.MainView()
|
||||||
|
roomView := mainView.GetRoom(evt.RoomID)
|
||||||
if roomView == nil {
|
if roomView == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
message := c.ui.MainView().ProcessMembershipEvent(roomView, evt)
|
message := mainView.ProcessMembershipEvent(roomView, evt)
|
||||||
if message != nil {
|
if message != nil {
|
||||||
// TODO this shouldn't be necessary
|
// TODO this shouldn't be necessary
|
||||||
roomView.Room.UpdateState(evt)
|
roomView.Room.UpdateState(evt)
|
||||||
// TODO This should probably also be in a different place
|
// TODO This should probably also be in a different place
|
||||||
roomView.UpdateUserList()
|
roomView.UpdateUserList()
|
||||||
|
|
||||||
|
pushRules := c.PushRules().GetActions(roomView.Room, evt).Should()
|
||||||
|
mainView.NotifyMessage(roomView.Room, message, pushRules)
|
||||||
roomView.AddMessage(message, widget.AppendMessage)
|
roomView.AddMessage(message, widget.AppendMessage)
|
||||||
c.ui.Render()
|
c.ui.Render()
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func init() {
|
|||||||
TerminalNotifierAvailable = true
|
TerminalNotifierAvailable = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func Send(title, text string, critical bool) error {
|
func Send(title, text string, critical, sound bool) error {
|
||||||
if TerminalNotifierAvailable {
|
if TerminalNotifierAvailable {
|
||||||
args := []string{"-title", "gomuks", "-subtitle", title, "-message", text}
|
args := []string{"-title", "gomuks", "-subtitle", title, "-message", text}
|
||||||
if critical {
|
if critical {
|
||||||
@ -39,6 +39,9 @@ func Send(title, text string, critical bool) error {
|
|||||||
} else {
|
} else {
|
||||||
args = append(args, "-timeout", "4")
|
args = append(args, "-timeout", "4")
|
||||||
}
|
}
|
||||||
|
if sound {
|
||||||
|
args = append(args, "-sound", "default")
|
||||||
|
}
|
||||||
// if len(iconPath) > 0 {
|
// if len(iconPath) > 0 {
|
||||||
// args = append(args, "-appIcon", iconPath)
|
// args = append(args, "-appIcon", iconPath)
|
||||||
// }
|
// }
|
||||||
|
@ -18,14 +18,21 @@ package notification
|
|||||||
|
|
||||||
import "os/exec"
|
import "os/exec"
|
||||||
|
|
||||||
func Send(title, text string, critical bool) error {
|
func Send(title, text string, critical, sound bool) error {
|
||||||
args := []string{"-a", "gomuks"}
|
args := []string{"-a", "gomuks"}
|
||||||
if critical {
|
if critical {
|
||||||
args = append(args, "-p", "critical")
|
args = append(args, "-u", "critical")
|
||||||
}
|
}
|
||||||
// if iconPath {
|
// if iconPath {
|
||||||
// args = append(args, "-i", iconPath)
|
// args = append(args, "-i", iconPath)
|
||||||
// }
|
// }
|
||||||
args = append(args, title, text)
|
args = append(args, title, text)
|
||||||
|
if sound {
|
||||||
|
soundName := "message-new-instant"
|
||||||
|
if critical {
|
||||||
|
soundName = "complete"
|
||||||
|
}
|
||||||
|
exec.Command("paplay", "/usr/share/sounds/freedesktop/stereo/"+soundName+".oga").Run()
|
||||||
|
}
|
||||||
return exec.Command("notify-send", args...).Run()
|
return exec.Command("notify-send", args...).Run()
|
||||||
}
|
}
|
||||||
|
23
notification/notify_unsupported.go
Normal file
23
notification/notify_unsupported.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// +build !linux,!darwin,!windows
|
||||||
|
|
||||||
|
// gomuks - A terminal Matrix client written in Go.
|
||||||
|
// Copyright (C) 2018 Tulir Asokan
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package notification
|
||||||
|
|
||||||
|
func Send(title, text string, critical, sound bool) error {
|
||||||
|
return nil
|
||||||
|
}
|
@ -18,15 +18,18 @@ package notification
|
|||||||
|
|
||||||
import "gopkg.in/toast.v1"
|
import "gopkg.in/toast.v1"
|
||||||
|
|
||||||
func Send(title, text string, critical bool) error {
|
func Send(title, text string, critical, sound bool) error {
|
||||||
notification := toast.Notification{
|
notification := toast.Notification{
|
||||||
AppID: "gomuks",
|
AppID: "gomuks",
|
||||||
Title: title,
|
Title: title,
|
||||||
Message: message,
|
Message: message,
|
||||||
Audio: toast.IM,
|
Audio: toast.Silent,
|
||||||
Duration: toast.Short,
|
Duration: toast.Short,
|
||||||
// Icon: ...,
|
// Icon: ...,
|
||||||
}
|
}
|
||||||
|
if sound {
|
||||||
|
notification.Audio = toast.IM
|
||||||
|
}
|
||||||
if critical {
|
if critical {
|
||||||
notification.Duration = toast.Long
|
notification.Duration = toast.Long
|
||||||
}
|
}
|
||||||
|
@ -378,11 +378,11 @@ func (view *MainView) SetTyping(room string, users []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendNotification(room *rooms.Room, sender, text string, critical bool) {
|
func sendNotification(room *rooms.Room, sender, text string, critical, sound bool) {
|
||||||
if room.GetTitle() != sender {
|
if room.GetTitle() != sender {
|
||||||
sender = fmt.Sprintf("%s (%s)", sender, room.GetTitle())
|
sender = fmt.Sprintf("%s (%s)", sender, room.GetTitle())
|
||||||
}
|
}
|
||||||
notification.Send(sender, text, critical)
|
notification.Send(sender, text, critical, sound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (view *MainView) NotifyMessage(room *rooms.Room, message *types.Message, should pushrules.PushActionArrayShould) {
|
func (view *MainView) NotifyMessage(room *rooms.Room, message *types.Message, should pushrules.PushActionArrayShould) {
|
||||||
@ -392,7 +392,8 @@ func (view *MainView) NotifyMessage(room *rooms.Room, message *types.Message, sh
|
|||||||
}
|
}
|
||||||
shouldNotify := (should.Notify || !should.NotifySpecified) && message.Sender != view.config.Session.UserID
|
shouldNotify := (should.Notify || !should.NotifySpecified) && message.Sender != view.config.Session.UserID
|
||||||
if shouldNotify {
|
if shouldNotify {
|
||||||
sendNotification(room, message.Sender, message.Text, should.Highlight)
|
shouldPlaySound := should.PlaySound && should.SoundName == "default"
|
||||||
|
sendNotification(room, message.Sender, message.Text, should.Highlight, shouldPlaySound)
|
||||||
if !isCurrent {
|
if !isCurrent {
|
||||||
room.UnreadMessages++
|
room.UnreadMessages++
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user