mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
fixed the refresh issue that appeared
This commit is contained in:
parent
85d1376d94
commit
4301b44416
1 changed files with 33 additions and 1 deletions
|
|
@ -506,7 +506,8 @@ func (r *LibpodRuntime) RemovePod(ctx context.Context, id string, force bool) er
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events streams container runtime events using native libpod event streaming.
|
// Events streams container runtime events using native libpod event streaming.
|
||||||
// This provides real-time event delivery with <100ms latency instead of polling.
|
// This provides real-time event delivery with <100ms latency for actual events,
|
||||||
|
// plus an initial synthetic event to trigger UI load and periodic heartbeat refreshes.
|
||||||
func (r *LibpodRuntime) Events(ctx context.Context) (<-chan Event, <-chan error) {
|
func (r *LibpodRuntime) Events(ctx context.Context) (<-chan Event, <-chan error) {
|
||||||
eventChan := make(chan Event)
|
eventChan := make(chan Event)
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
|
|
@ -515,6 +516,18 @@ func (r *LibpodRuntime) Events(ctx context.Context) (<-chan Event, <-chan error)
|
||||||
defer close(eventChan)
|
defer close(eventChan)
|
||||||
defer close(errChan)
|
defer close(errChan)
|
||||||
|
|
||||||
|
// Send initial synthetic event immediately to trigger UI load
|
||||||
|
// This ensures the UI displays containers/pods even before any real events occur
|
||||||
|
select {
|
||||||
|
case eventChan <- Event{
|
||||||
|
Type: "system",
|
||||||
|
Action: "refresh",
|
||||||
|
Time: time.Now().Unix(),
|
||||||
|
}:
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Create libpod event channel (buffered to prevent blocking during bursts)
|
// Create libpod event channel (buffered to prevent blocking during bursts)
|
||||||
libpodEventChan := make(chan events.ReadResult, 10)
|
libpodEventChan := make(chan events.ReadResult, 10)
|
||||||
|
|
||||||
|
|
@ -539,12 +552,31 @@ func (r *LibpodRuntime) Events(ctx context.Context) (<-chan Event, <-chan error)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Periodic heartbeat ticker for UI refresh when no events occur
|
||||||
|
// This is much less frequent than the old 2-second polling (now 10 seconds)
|
||||||
|
// because real events provide immediate updates
|
||||||
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
// Convert libpod events to ContainerRuntime Event format
|
// Convert libpod events to ContainerRuntime Event format
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
case <-ticker.C:
|
||||||
|
// Send periodic heartbeat to ensure UI updates even without real events
|
||||||
|
// This handles edge cases like containers dying without generating events
|
||||||
|
select {
|
||||||
|
case eventChan <- Event{
|
||||||
|
Type: "system",
|
||||||
|
Action: "refresh",
|
||||||
|
Time: time.Now().Unix(),
|
||||||
|
}:
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
case result, ok := <-libpodEventChan:
|
case result, ok := <-libpodEventChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
// Channel closed, exit
|
// Channel closed, exit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue