diff --git a/bin/usb-client b/bin/usb-client index cb73d07..9ae0787 100755 Binary files a/bin/usb-client and b/bin/usb-client differ diff --git a/bin/usb-client.exe b/bin/usb-client.exe index 6de8db5..33ace47 100755 Binary files a/bin/usb-client.exe and b/bin/usb-client.exe differ diff --git a/bin/usb-relay b/bin/usb-relay index fbfeff8..9996fca 100755 Binary files a/bin/usb-relay and b/bin/usb-relay differ diff --git a/internal/client/share.go b/internal/client/share.go index 16ea06b..23698a8 100644 --- a/internal/client/share.go +++ b/internal/client/share.go @@ -49,6 +49,7 @@ func NewShareManager(client *Client) *ShareManager { client.OnRequestDevice = sm.handleRequestDevice client.OnReleaseDevice = sm.handleReleaseDevice client.OnTunnelData = sm.handleTunnelData + client.OnClientLeft = sm.handleClientLeft return sm } @@ -311,6 +312,22 @@ func (sm *ShareManager) handleReleaseDevice(busID, fromClient string) { sm.broadcastDeviceList() } +func (sm *ShareManager) handleClientLeft(msg *protocol.ClientLeft) { + sm.mu.RLock() + var toRelease []string + for busID, share := range sm.active { + if share.usedBy == msg.ClientID { + toRelease = append(toRelease, busID) + } + } + sm.mu.RUnlock() + + for _, busID := range toRelease { + log.Printf("[share] auto-releasing %s (client %s left)", busID, msg.ClientID[:8]) + sm.handleReleaseDevice(busID, msg.ClientID) + } +} + func (sm *ShareManager) handleTunnelData(tunnelID string, data []byte) { sm.mu.RLock() tunnel, exists := sm.tunnels[tunnelID]