Skip to content

Commit

Permalink
fix: use new api for various state tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
plutack committed Oct 30, 2024
1 parent a9f36f2 commit 0b0e146
Show file tree
Hide file tree
Showing 5 changed files with 589 additions and 563 deletions.
36 changes: 18 additions & 18 deletions dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const (
dest = `org.kde.kdeconnect`
path = `/modules/kdeconnect`

signalReachableStatusChanged = dest + `.device.reachableStatusChanged`
signalStateChanged = dest + `.device.stateChanged`
signalTrustedChanged = dest + `.device.trustedChanged`
signalNameChanged = dest + `.device.nameChanged`
signalPluginsChanged = dest + `.device.pluginsChanged`
signalReachableChanged = dest + `.device.reachableChanged`
signalStateChanged = dest + `.device.stateChanged`
signalPairStateChanged = dest + `.device.PairStateChanged`
signalNameChanged = dest + `.device.nameChanged`
signalPluginsChanged = dest + `.device.pluginsChanged`

pluginShare = `kdeconnect_share`
)
Expand Down Expand Up @@ -84,7 +84,7 @@ type Device struct {
IconName string `json:"iconName"`
StatusIconName string `json:"statusIconName"`
IsReachable bool `json:"isReachable"`
IsTrusted bool `json:"isTrusted"`
IsPaired bool `json:"isPaired"`
SupportedPlugins map[string]struct{} `json:"supportedPlugins"`
conn *dbus.Conn
obj dbus.BusObject
Expand All @@ -93,19 +93,19 @@ type Device struct {
}

func (d *Device) watch() error {
// kdeconnect < v1.2
// kdeconnect < v1.2 :(should probably deprecate this entirely)
if err := d.addMatchSignal(`reachableStatusChanged`); err != nil {
return err
}
// kdeconnect >= v1.2
if err := d.addMatchSignal(`reachableChanged`); err != nil {
return err
}

// still trying to find what stateChanged represented and if it the api remains
if err := d.addMatchSignal(`stateChanged`); err != nil {
return err
}
if err := d.addMatchSignal(`trustedChanged`); err != nil {
if err := d.addMatchSignal(`pairStateChanged`); err != nil {
return err
}
if err := d.addMatchSignal(`nameChanged`); err != nil {
Expand All @@ -120,7 +120,7 @@ func (d *Device) watch() error {
for s := range d.signal {
var err error
switch s.Name {
case signalReachableStatusChanged:
case signalReachableChanged:
if err = d.getIsReachable(); err != nil {
log(err)
}
Expand All @@ -132,8 +132,8 @@ func (d *Device) watch() error {
if err = d.getName(); err != nil {
log(err)
}
case signalTrustedChanged:
if err = d.getIsTrusted(); err != nil {
case signalPairStateChanged:
if err = d.getIsPaired(); err != nil {
log(err)
}
case signalStateChanged:
Expand Down Expand Up @@ -218,12 +218,12 @@ func (d *Device) getIsReachable() error {
return nil
}

func (d *Device) getIsTrusted() error {
v, err := d.obj.GetProperty(dest + `.device.isTrusted`)
func (d *Device) getIsPaired() error {
v, err := d.obj.GetProperty(dest + `.device.isPaired`)
if err != nil {
return err
}
d.IsTrusted = v.Value().(bool)
d.IsPaired = v.Value().(bool)

return nil
}
Expand Down Expand Up @@ -257,8 +257,8 @@ func (d *Device) update() error {
if err := d.getStatusIconName(); err != nil {
logBadProp(d.ID, `statusIconName`, err)
}
if err := d.getIsTrusted(); err != nil {
logBadProp(d.ID, `isTrusted`, err)
if err := d.getIsPaired(); err != nil {
logBadProp(d.ID, `isPaired`, err)
}
if err := d.getIsReachable(); err != nil {
logBadProp(d.ID, `isReachable`, err)
Expand Down Expand Up @@ -286,7 +286,7 @@ func (d *Device) supported(plugin string) error {
if !d.IsReachable {
return fmt.Errorf("Device is not reachable")
}
if !d.IsTrusted {
if !d.IsPaired {
return fmt.Errorf("Device is not trusted")
}

Expand Down
Loading

0 comments on commit 0b0e146

Please sign in to comment.