Allow multiple call notification responses
This commit is contained in:
parent
d86216ef74
commit
3eb93cdb35
44
calls.go
44
calls.go
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.arsenm.dev/infinitime"
|
||||
@ -46,13 +48,16 @@ func initCallNotifs(dev *infinitime.Device) error {
|
||||
// Notify channel upon received message
|
||||
monitorConn.Eavesdrop(callCh)
|
||||
|
||||
var respHandlerOnce sync.Once
|
||||
var callObj dbus.BusObject
|
||||
|
||||
go func() {
|
||||
// For every message received
|
||||
for event := range callCh {
|
||||
// Get path to call object
|
||||
callPath := event.Body[0].(dbus.ObjectPath)
|
||||
// Get call object
|
||||
callObj := conn.Object("org.freedesktop.ModemManager1", callPath)
|
||||
callObj = conn.Object("org.freedesktop.ModemManager1", callPath)
|
||||
|
||||
// Get phone number from call object using method call connection
|
||||
phoneNum, err := getPhoneNum(conn, callObj)
|
||||
@ -67,27 +72,28 @@ func initCallNotifs(dev *infinitime.Device) error {
|
||||
continue
|
||||
}
|
||||
|
||||
go func() {
|
||||
go respHandlerOnce.Do(func() {
|
||||
// Wait for PineTime response
|
||||
res := <-resCh
|
||||
switch res {
|
||||
case infinitime.CallStatusAccepted:
|
||||
// Attempt to accept call
|
||||
err = acceptCall(conn, callObj)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Error accepting call")
|
||||
for res := range resCh {
|
||||
switch res {
|
||||
case infinitime.CallStatusAccepted:
|
||||
// Attempt to accept call
|
||||
err = acceptCall(conn, callObj)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Error accepting call")
|
||||
}
|
||||
case infinitime.CallStatusDeclined:
|
||||
// Attempt to decline call
|
||||
err = declineCall(conn, callObj)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Error declining call")
|
||||
}
|
||||
case infinitime.CallStatusMuted:
|
||||
// Warn about unimplemented muting
|
||||
log.Warn().Msg("Muting calls is not implemented")
|
||||
}
|
||||
case infinitime.CallStatusDeclined:
|
||||
// Attempt to decline call
|
||||
err = declineCall(conn, callObj)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Error declining call")
|
||||
}
|
||||
case infinitime.CallStatusMuted:
|
||||
// Warn about unimplemented muting
|
||||
log.Warn().Msg("Muting calls is not implemented")
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
}()
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -25,7 +25,7 @@ require (
|
||||
github.com/srwiley/oksvg v0.0.0-20210519022825-9fc0c575d5fe // indirect
|
||||
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect
|
||||
github.com/yuin/goldmark v1.4.1 // indirect
|
||||
go.arsenm.dev/infinitime v0.0.0-20211125004156-e9a611aec8a6
|
||||
go.arsenm.dev/infinitime v0.0.0-20211125012112-9966880bc8be
|
||||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
|
||||
golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0 // indirect
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
|
||||
|
4
go.sum
4
go.sum
@ -367,8 +367,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
|
||||
github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM=
|
||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.arsenm.dev/infinitime v0.0.0-20211125004156-e9a611aec8a6 h1:pAwb4Z2LY+RD3I1VxklG8Vv8CV6szfikc9L/qM8nQmc=
|
||||
go.arsenm.dev/infinitime v0.0.0-20211125004156-e9a611aec8a6/go.mod h1:TzAhsz7TAqEm/vWhgMvmIxHS5jt46hqKkPvr6cqvVyA=
|
||||
go.arsenm.dev/infinitime v0.0.0-20211125012112-9966880bc8be h1:WBD4szNWt5o9z/qEAPKZsTrk9j9uSeNxC0hjw0fQgWc=
|
||||
go.arsenm.dev/infinitime v0.0.0-20211125012112-9966880bc8be/go.mod h1:TzAhsz7TAqEm/vWhgMvmIxHS5jt46hqKkPvr6cqvVyA=
|
||||
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
|
||||
|
Loading…
Reference in New Issue
Block a user