Skip to content

Commit f88f920

Browse files
committed
enhance: limit the rate to call UpdateStatusAsync and add hotkey F5 to call it forcely
Signed-off-by: leo <longshuang@msn.cn>
1 parent 20ff55f commit f88f920

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/ViewModels/Welcome.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@ public void Refresh()
5252
Rows.AddRange(rows);
5353
}
5454

55-
public async Task UpdateStatusAsync()
55+
public async Task UpdateStatusAsync(bool force)
5656
{
57+
if (!force)
58+
{
59+
var passed = DateTime.Now - _lastUpdateStatus;
60+
if (passed.TotalSeconds < 10.0)
61+
return;
62+
}
63+
64+
_lastUpdateStatus = DateTime.Now;
5765
foreach (var node in Preferences.Instance.RepositoryNodes)
5866
await node.UpdateStatusAsync();
5967
}
@@ -275,6 +283,7 @@ private void MakeTreeRows(List<RepositoryNode> rows, List<RepositoryNode> nodes,
275283
}
276284
}
277285

286+
private DateTime _lastUpdateStatus = DateTime.UnixEpoch.ToLocalTime();
278287
private string _searchFilter = string.Empty;
279288
}
280289
}

src/Views/Launcher.axaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ protected override async void OnKeyDown(KeyEventArgs e)
266266
e.Handled = true;
267267
return;
268268
}
269+
else if (vm.ActivePage.Data is ViewModels.Welcome welcome)
270+
{
271+
e.Handled = true;
272+
await welcome.UpdateStatusAsync(true);
273+
return;
274+
}
269275
}
270276

271277
base.OnKeyDown(e);

src/Views/Welcome.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Welcome()
6464
protected override async void OnLoaded(RoutedEventArgs e)
6565
{
6666
base.OnLoaded(e);
67-
await ViewModels.Welcome.Instance.UpdateStatusAsync();
67+
await ViewModels.Welcome.Instance.UpdateStatusAsync(false);
6868
}
6969

7070
protected override void OnKeyDown(KeyEventArgs e)

0 commit comments

Comments
 (0)