diff --git a/cmd/syncthing/summaryservice.go b/cmd/syncthing/summaryservice.go index 19bb2fa9b..3382a45fc 100644 --- a/cmd/syncthing/summaryservice.go +++ b/cmd/syncthing/summaryservice.go @@ -10,6 +10,7 @@ import ( "time" "github.com/syncthing/syncthing/lib/events" + "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/sync" "github.com/thejerf/suture" ) @@ -59,7 +60,7 @@ func (c *folderSummaryService) Stop() { // listenForUpdates subscribes to the event bus and makes note of folders that // need their data recalculated. func (c *folderSummaryService) listenForUpdates() { - sub := events.Default.Subscribe(events.LocalIndexUpdated | events.RemoteIndexUpdated | events.StateChanged | events.RemoteDownloadProgress) + sub := events.Default.Subscribe(events.LocalIndexUpdated | events.RemoteIndexUpdated | events.StateChanged | events.RemoteDownloadProgress | events.DeviceConnected) defer events.Default.Unsubscribe(sub) for { @@ -67,8 +68,31 @@ func (c *folderSummaryService) listenForUpdates() { select { case ev := <-sub.C(): - // Whenever the local or remote index is updated for a given - // folder we make a note of it. + if ev.Type == events.DeviceConnected { + // When a device connects we schedule a refresh of all + // folders shared with that device. + + data := ev.Data.(map[string]string) + deviceID, _ := protocol.DeviceIDFromString(data["id"]) + + c.foldersMut.Lock() + nextFolder: + for _, folder := range c.cfg.Folders() { + for _, dev := range folder.Devices { + if dev.DeviceID == deviceID { + c.folders[folder.ID] = struct{}{} + continue nextFolder + } + } + } + c.foldersMut.Unlock() + + continue + } + + // The other events all have a "folder" attribute that they + // affect. Whenever the local or remote index is updated for a + // given folder we make a note of it. data := ev.Data.(map[string]interface{}) folder := data["folder"].(string)