added other dsconnect settings
This commit is contained in:
+28
-8
@@ -33,10 +33,11 @@ type UseManager struct {
|
||||
cfg *config.Config
|
||||
cfgPath string
|
||||
mu sync.RWMutex
|
||||
available map[string][]RemoteDevice // clientID -> devices
|
||||
attached map[string]*AttachedDevice // busID@clientID -> attached info
|
||||
tunnels map[string]*useTunnel // tunnelID -> tunnel
|
||||
pending map[string]chan *protocol.DeviceGranted // requestID -> response channel
|
||||
available map[string][]RemoteDevice // clientID -> devices
|
||||
attached map[string]*AttachedDevice // busID@clientID -> attached info
|
||||
tunnels map[string]*useTunnel // tunnelID -> tunnel
|
||||
pending map[string]chan *protocol.DeviceGranted // requestID -> response channel
|
||||
forceDetachable map[string]bool // clientID -> allow_force_detach
|
||||
}
|
||||
|
||||
type useTunnel struct {
|
||||
@@ -53,10 +54,11 @@ func NewUseManager(client *Client, cfg *config.Config, cfgPath string) *UseManag
|
||||
client: client,
|
||||
cfg: cfg,
|
||||
cfgPath: cfgPath,
|
||||
available: make(map[string][]RemoteDevice),
|
||||
attached: make(map[string]*AttachedDevice),
|
||||
tunnels: make(map[string]*useTunnel),
|
||||
pending: make(map[string]chan *protocol.DeviceGranted),
|
||||
available: make(map[string][]RemoteDevice),
|
||||
attached: make(map[string]*AttachedDevice),
|
||||
tunnels: make(map[string]*useTunnel),
|
||||
pending: make(map[string]chan *protocol.DeviceGranted),
|
||||
forceDetachable: make(map[string]bool),
|
||||
}
|
||||
|
||||
client.OnDeviceList = um.handleDeviceList
|
||||
@@ -284,6 +286,7 @@ func (um *UseManager) handleDeviceList(msg *protocol.DeviceList) {
|
||||
})
|
||||
}
|
||||
um.available[msg.ClientID] = remoteDevs
|
||||
um.forceDetachable[msg.ClientID] = msg.AllowForceDetach
|
||||
|
||||
// Collect devices to auto-connect (while holding the lock to check attached map)
|
||||
var toAutoConnect []RemoteDevice
|
||||
@@ -382,6 +385,22 @@ func (um *UseManager) IsAutoConnect(vendorID, productID string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsForceDetachable checks if a share client allows force-detach
|
||||
func (um *UseManager) IsForceDetachable(clientID string) bool {
|
||||
um.mu.RLock()
|
||||
defer um.mu.RUnlock()
|
||||
return um.forceDetachable[clientID]
|
||||
}
|
||||
|
||||
// ForceDetachDevice sends a force-release request to the share client
|
||||
func (um *UseManager) ForceDetachDevice(clientID, busID string) error {
|
||||
return um.client.SendJSON(&protocol.ForceRelease{
|
||||
Type: protocol.MsgForceRelease,
|
||||
TargetClient: clientID,
|
||||
BusID: busID,
|
||||
})
|
||||
}
|
||||
|
||||
func (um *UseManager) handleDeviceGranted(msg *protocol.DeviceGranted) {
|
||||
um.mu.RLock()
|
||||
ch, exists := um.pending[msg.RequestID]
|
||||
@@ -430,6 +449,7 @@ func (um *UseManager) handleTunnelData(tunnelID string, data []byte) {
|
||||
func (um *UseManager) handleClientLeft(msg *protocol.ClientLeft) {
|
||||
um.mu.Lock()
|
||||
delete(um.available, msg.ClientID)
|
||||
delete(um.forceDetachable, msg.ClientID)
|
||||
|
||||
// Detach any devices from this client
|
||||
for key, dev := range um.attached {
|
||||
|
||||
Reference in New Issue
Block a user