mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-30 22:01:10 +08:00
feature: async (#1492)
* Async command methods * Async `Task.Run` where possible * Remove redundant `Task.Run` in `Sure` methods * Remove leftover braces and reformat * Async event handlers as needed
This commit is contained in:
@@ -40,56 +40,53 @@ namespace SourceGit.ViewModels
|
||||
GetManagedRepositories(Preferences.Instance.RepositoryNodes, _managed);
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
public override async Task<bool> Sure()
|
||||
{
|
||||
ProgressDescription = $"Scan repositories under '{_selected.Path}' ...";
|
||||
|
||||
return Task.Run(() =>
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
var rootDir = new DirectoryInfo(_selected.Path);
|
||||
var found = new List<string>();
|
||||
GetUnmanagedRepositories(rootDir, found, new EnumerationOptions()
|
||||
{
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
var rootDir = new DirectoryInfo(_selected.Path);
|
||||
var found = new List<string>();
|
||||
GetUnmanagedRepositories(rootDir, found, new EnumerationOptions()
|
||||
{
|
||||
AttributesToSkip = FileAttributes.Hidden | FileAttributes.System,
|
||||
IgnoreInaccessible = true,
|
||||
});
|
||||
|
||||
// Make sure this task takes at least 0.5s to avoid that the popup panel do not disappear very quickly.
|
||||
var remain = 500 - (int)watch.Elapsed.TotalMilliseconds;
|
||||
watch.Stop();
|
||||
if (remain > 0)
|
||||
Task.Delay(remain).Wait();
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
var normalizedRoot = rootDir.FullName.Replace('\\', '/').TrimEnd('/');
|
||||
|
||||
foreach (var f in found)
|
||||
{
|
||||
var parent = new DirectoryInfo(f).Parent!.FullName.Replace('\\', '/').TrimEnd('/');
|
||||
if (parent.Equals(normalizedRoot, StringComparison.Ordinal))
|
||||
{
|
||||
Preferences.Instance.FindOrAddNodeByRepositoryPath(f, null, false, false);
|
||||
}
|
||||
else if (parent.StartsWith(normalizedRoot, StringComparison.Ordinal))
|
||||
{
|
||||
var relative = parent.Substring(normalizedRoot.Length).TrimStart('/');
|
||||
var group = FindOrCreateGroupRecursive(Preferences.Instance.RepositoryNodes, relative);
|
||||
Preferences.Instance.FindOrAddNodeByRepositoryPath(f, group, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
Preferences.Instance.AutoRemoveInvalidNode();
|
||||
Preferences.Instance.Save();
|
||||
|
||||
Welcome.Instance.Refresh();
|
||||
});
|
||||
|
||||
return true;
|
||||
AttributesToSkip = FileAttributes.Hidden | FileAttributes.System,
|
||||
IgnoreInaccessible = true,
|
||||
});
|
||||
|
||||
// Make sure this task takes at least 0.5s to avoid that the popup panel do not disappear very quickly.
|
||||
var remain = 500 - (int)watch.Elapsed.TotalMilliseconds;
|
||||
watch.Stop();
|
||||
if (remain > 0)
|
||||
Task.Delay(remain).Wait();
|
||||
|
||||
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
var normalizedRoot = rootDir.FullName.Replace('\\', '/').TrimEnd('/');
|
||||
|
||||
foreach (var f in found)
|
||||
{
|
||||
var parent = new DirectoryInfo(f).Parent!.FullName.Replace('\\', '/').TrimEnd('/');
|
||||
if (parent.Equals(normalizedRoot, StringComparison.Ordinal))
|
||||
{
|
||||
Preferences.Instance.FindOrAddNodeByRepositoryPath(f, null, false, false);
|
||||
}
|
||||
else if (parent.StartsWith(normalizedRoot, StringComparison.Ordinal))
|
||||
{
|
||||
var relative = parent.Substring(normalizedRoot.Length).TrimStart('/');
|
||||
var group = FindOrCreateGroupRecursive(Preferences.Instance.RepositoryNodes, relative);
|
||||
Preferences.Instance.FindOrAddNodeByRepositoryPath(f, group, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
Preferences.Instance.AutoRemoveInvalidNode();
|
||||
Preferences.Instance.Save();
|
||||
|
||||
Welcome.Instance.Refresh();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void GetManagedRepositories(List<RepositoryNode> group, HashSet<string> repos)
|
||||
|
||||
Reference in New Issue
Block a user