Documentation
¶
Overview ¶
Package device manages KDE Connect devices, their connections, state, and routing.
Index ¶
- func ReconnectBackoff(attempt int, maxDuration time.Duration) time.Duration
- func SaveDevices(path string, devices []DeviceInfo) error
- type Device
- func (d *Device) Connect(ctx context.Context, conn *transport.Conn, ...)
- func (d *Device) Disconnect()
- func (d *Device) GetBattery() (int, bool)
- func (d *Device) HasCapability(cap string) bool
- func (d *Device) ID() string
- func (d *Device) IsConnected() bool
- func (d *Device) LastSeen() time.Time
- func (d *Device) Name() string
- func (d *Device) PeerCert() *x509.Certificate
- func (d *Device) RemoteIP() net.IP
- func (d *Device) Send(p *protocol.Packet) error
- func (d *Device) SetBus(bus *events.Bus)
- func (d *Device) SetLastSeen(t time.Time)
- func (d *Device) SetName(n string)
- func (d *Device) SetState(s PairingState)
- func (d *Device) State() PairingState
- func (d *Device) UpdateBattery(charge int, charging bool)
- type DeviceInfo
- type PairingState
- type Registry
- type Sender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReconnectBackoff ¶
ReconnectBackoff calculates exponential backoff duration based on attempts. Caps out at maxDuration.
func SaveDevices ¶
func SaveDevices(path string, devices []DeviceInfo) error
SaveDevices writes the list of known devices to the given JSON file path.
Types ¶
type Device ¶
type Device struct {
Type string
IncomingCaps []string
OutgoingCaps []string
CertFP string
BatteryCharge int
IsCharging bool
// contains filtered or unexported fields
}
Device represents an active KDE Connect remote device.
func (*Device) Connect ¶
func (d *Device) Connect(ctx context.Context, conn *transport.Conn, dispatch func(context.Context, *Device, *protocol.Packet), onConnect func(*Device), onDisconnect func(*Device))
Connect establishes a connection for the device and starts the reader and writer loops.
func (*Device) Disconnect ¶
func (d *Device) Disconnect()
Disconnect terminates the connection and stops the loops.
func (*Device) GetBattery ¶
GetBattery returns the current battery state of the device.
func (*Device) HasCapability ¶
HasCapability checks if the device has a particular capability (incoming or outgoing).
func (*Device) IsConnected ¶
IsConnected returns whether the device currently has an active connection.
func (*Device) PeerCert ¶
func (d *Device) PeerCert() *x509.Certificate
PeerCert returns the validated certificate presented by the remote device. Returns nil if not connected or no certificate was presented.
func (*Device) Send ¶
Send attempts to enqueue a packet for delivery to the device. If the send channel is full, the packet is dropped to avoid blocking.
func (*Device) SetLastSeen ¶
func (*Device) SetState ¶
func (d *Device) SetState(s PairingState)
func (*Device) State ¶
func (d *Device) State() PairingState
func (*Device) UpdateBattery ¶
UpdateBattery updates the battery state of the device.
type DeviceInfo ¶
type DeviceInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
State PairingState `json:"state"`
CertFP string `json:"cert_fp"`
LastSeen time.Time `json:"last_seen"`
Connected bool `json:"connected"`
}
DeviceInfo represents the persistent state of a device.
func LoadDevices ¶
func LoadDevices(path string) ([]DeviceInfo, error)
LoadDevices loads known devices from the given JSON file path.
type PairingState ¶
type PairingState int
PairingState represents the current pairing status with a device.
const ( StateUnknown PairingState = iota StatePairRequested // We sent a pair request, waiting for response StatePairRequestedByPeer // Peer sent a pair request, waiting for user to accept StatePaired StateUnpaired )
func (PairingState) String ¶
func (s PairingState) String() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages the set of known devices in memory.
func NewRegistry ¶
NewRegistry creates a new empty device registry.
func (*Registry) AllPairedDevicesConnected ¶
AllPairedDevicesConnected returns true if there is at least one paired device and all paired devices are currently connected.
func (*Registry) Connected ¶
Connected returns only devices that currently have an active connection.
type Sender ¶
type Sender interface {
ID() string
Name() string
SetName(name string)
State() PairingState
SetState(state PairingState)
Send(p *protocol.Packet) error
IsConnected() bool
RemoteIP() net.IP
PeerCert() *x509.Certificate
HasCapability(cap string) bool
UpdateBattery(charge int, charging bool)
GetBattery() (int, bool)
}
Sender represents a KDE Connect device capable of receiving packets. This interface allows plugins to interact with a device without knowing its internal implementation details.