Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 78df6b8

Browse files
committed
Add progress reporting
Add a progress bar on all views and progress updates/messages for all tasks
1 parent f861fa5 commit 78df6b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+885
-287
lines changed

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,9 @@ public ApiClient(UriString hostUrl, IKeychain keychain, IProcessManager processM
4040
octorunScript: octorunScriptPath);
4141
}
4242

43-
public async Task Logout(UriString host)
43+
public ITask Logout(UriString host)
4444
{
45-
await LogoutInternal(host);
46-
}
47-
48-
private async Task LogoutInternal(UriString host)
49-
{
50-
await loginManager.Logout(host);
45+
return loginManager.Logout(host);
5146
}
5247

5348
public async Task CreateRepository(string name, string description, bool isPrivate, Action<GitHubRepository, Exception> callback, string organization = null)

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ abstract class ApplicationManagerBase : IApplicationManager
1212
protected static ILogging Logger { get; } = LogHelper.GetLogger<IApplicationManager>();
1313

1414
private RepositoryManager repositoryManager;
15-
private Progress progressReporter;
15+
private ProgressReporter progressReporter = new ProgressReporter();
16+
private Progress progress = new Progress(TaskBase.Default);
1617
protected bool isBusy;
1718
private bool firstRun;
1819
protected bool FirstRun { get { return firstRun; } set { firstRun = value; } }
@@ -27,13 +28,13 @@ public event Action<IProgress> OnProgress
2728

2829
public ApplicationManagerBase(SynchronizationContext synchronizationContext)
2930
{
30-
progressReporter = new Progress();
3131
SynchronizationContext = synchronizationContext;
3232
SynchronizationContext.SetSynchronizationContext(SynchronizationContext);
3333
ThreadingHelper.SetUIThread();
3434
UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();
3535
ThreadingHelper.MainThreadScheduler = UIScheduler;
3636
TaskManager = new TaskManager(UIScheduler);
37+
progress.OnProgress += progressReporter.UpdateProgress;
3738
}
3839

3940
protected void Initialize()
@@ -51,6 +52,7 @@ protected void Initialize()
5152
public void Run()
5253
{
5354
isBusy = true;
55+
progress.UpdateProgress(0, 100, "Initializing...");
5456

5557
var thread = new Thread(() =>
5658
{
@@ -72,8 +74,13 @@ public void Run()
7274
}
7375
}
7476

75-
var installer = new GitInstaller(Environment, ProcessManager, CancellationToken)
76-
{ Progress = progressReporter };
77+
progress.UpdateProgress(20, 100, "Setting up octorun...");
78+
79+
Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager)
80+
.SetupOctorunIfNeeded();
81+
82+
progress.UpdateProgress(50, 100, "Setting up git...");
83+
7784
state = Environment.GitInstallationState;
7885
if (!state.GitIsValid && !state.GitLfsIsValid && FirstRun)
7986
{
@@ -88,6 +95,9 @@ public void Run()
8895
}
8996
}
9097

98+
99+
var installer = new GitInstaller(Environment, ProcessManager, CancellationToken);
100+
installer.Progress.OnProgress += progressReporter.UpdateProgress;
91101
if (state.GitIsValid && state.GitLfsIsValid)
92102
{
93103
if (firstRun)
@@ -100,25 +110,26 @@ public void Run()
100110
}
101111
}
102112

103-
Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager)
104-
.SetupOctorunIfNeeded();
105-
106113
if (!state.GitIsValid || !state.GitLfsIsValid)
107114
{
108115
state = installer.SetupGitIfNeeded();
109116
}
110117

111118
SetupGit(state);
112119

120+
progress.UpdateProgress(80, 100, "Initializing repository...");
121+
113122
if (state.GitIsValid && state.GitLfsIsValid)
114123
{
115124
RestartRepository();
116125
}
117126

127+
progress.UpdateProgress(100, 100, "Initialization failed");
118128
}
119129
catch (Exception ex)
120130
{
121131
Logger.Error(ex, "A problem ocurred setting up Git");
132+
progress.UpdateProgress(90, 100, "Initialization failed");
122133
}
123134

124135
new ActionTask<bool>(CancellationToken, (s, gitIsValid) =>
@@ -204,6 +215,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
204215
public void InitializeRepository()
205216
{
206217
isBusy = true;
218+
progress.UpdateProgress(0, 100, "Initializing...");
207219
var thread = new Thread(() =>
208220
{
209221
var success = true;
@@ -218,27 +230,37 @@ public void InitializeRepository()
218230
var filesForInitialCommit = new List<string> { gitignore, gitAttrs, assetsGitignore };
219231

220232
GitClient.Init().RunWithReturn(true);
233+
progress.UpdateProgress(10, 100, "Initializing...");
221234

222235
ConfigureMergeSettings();
236+
progress.UpdateProgress(20, 100, "Initializing...");
237+
223238
GitClient.LfsInstall().RunWithReturn(true);
239+
progress.UpdateProgress(30, 100, "Initializing...");
240+
224241
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
225242
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
226243
assetsGitignore.CreateFile();
227244
GitClient.Add(filesForInitialCommit).RunWithReturn(true);
245+
progress.UpdateProgress(60, 100, "Initializing...");
228246
GitClient.Commit("Initial commit", null).RunWithReturn(true);
247+
progress.UpdateProgress(70, 100, "Initializing...");
229248
Environment.InitializeRepository();
230249
UsageTracker.IncrementProjectsInitialized();
231250
}
232251
catch (Exception ex)
233252
{
234253
Logger.Error(ex, "A problem ocurred initializing the repository");
254+
progress.UpdateProgress(90, 100, "Failed to initialize repository");
235255
success = false;
236256
}
237257

238258
if (success)
239259
{
260+
progress.UpdateProgress(90, 100, "Initializing...");
240261
RestartRepository();
241262
TaskManager.RunInUI(InitializeUI);
263+
progress.UpdateProgress(100, 100, "Initialized");
242264
}
243265
isBusy = false;
244266
});

src/GitHub.Api/Application/IApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Task CreateRepository(string name, string description, bool isPrivate,
1212
Task GetOrganizations(Action<Organization[]> onSuccess, Action<Exception> onError = null);
1313
Task Login(string username, string password, Action<LoginResult> need2faCode, Action<bool, string> result);
1414
Task ContinueLogin(LoginResult loginResult, string code);
15-
Task Logout(UriString host);
15+
ITask Logout(UriString host);
1616
Task GetCurrentUser(Action<GitHubUser> onSuccess, Action<Exception> onError = null);
1717
}
1818
}

src/GitHub.Api/Authentication/ILoginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ interface ILoginManager
2525
/// </summary>
2626
/// <param name="hostAddress">The address of the server.</param>
2727
/// <inheritdoc/>
28-
Task Logout(UriString hostAddress);
28+
ITask Logout(UriString hostAddress);
2929
}
3030
}

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ public async Task<LoginResultData> ContinueLogin(LoginResultData loginResultData
134134
}
135135

136136
/// <inheritdoc/>
137-
public async Task Logout(UriString hostAddress)
137+
public ITask Logout(UriString hostAddress)
138138
{
139139
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
140140

141-
await new ActionTask(keychain.Clear(hostAddress, true)).StartAwait();
141+
return new ActionTask(keychain.Clear(hostAddress, true)) { Message = "Signing out" }.Start();
142142
}
143143

144144
private async Task<LoginResultData> TryLogin(

src/GitHub.Api/Cache/CacheContainer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public void InvalidateAll()
3030
{
3131
foreach (var cache in caches.Values)
3232
{
33-
// force an invalidation if the cache is valid, otherwise it will do it on its own
34-
if (cache.Value.ValidateData())
35-
cache.Value.InvalidateData();
33+
cache.Value.InvalidateData();
3634
}
3735
}
3836

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ public interface IRepository : IEquatable<IRepository>, IDisposable
7979
ITask CreateBranch(string branch, string baseBranch);
8080
ITask SwitchBranch(string branch);
8181
void Refresh(CacheType cacheType);
82+
event Action<IProgress> OnProgress;
8283
}
8384
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Diagnostics;
55
using System.Globalization;
66
using System.Linq;
7-
using System.Threading;
87

98
namespace GitHub.Unity
109
{
@@ -20,6 +19,7 @@ sealed class Repository : IEquatable<Repository>, IRepository
2019
private string name;
2120
private HashSet<CacheType> cacheInvalidationRequests = new HashSet<CacheType>();
2221
private Dictionary<CacheType, Action<CacheUpdateEvent>> cacheUpdateEvents;
22+
private ProgressReporter progressReporter = new ProgressReporter();
2323

2424
public event Action<CacheUpdateEvent> LogChanged;
2525
public event Action<CacheUpdateEvent> TrackingStatusChanged;
@@ -31,6 +31,11 @@ sealed class Repository : IEquatable<Repository>, IRepository
3131
public event Action<CacheUpdateEvent> LocksChanged;
3232
public event Action<CacheUpdateEvent> RemoteBranchListChanged;
3333
public event Action<CacheUpdateEvent> LocalAndRemoteBranchListChanged;
34+
public event Action<IProgress> OnProgress
35+
{
36+
add { progressReporter.OnProgress += value; }
37+
remove { progressReporter.OnProgress -= value; }
38+
}
3439

3540
/// <summary>
3641
/// Initializes a new instance of the <see cref="Repository"/> class.
@@ -85,6 +90,15 @@ public void Initialize(IRepositoryManager theRepositoryManager, ITaskManager the
8590
this.repositoryManager.LocalBranchesUpdated += RepositoryManagerOnLocalBranchesUpdated;
8691
this.repositoryManager.RemoteBranchesUpdated += RepositoryManagerOnRemoteBranchesUpdated;
8792
this.repositoryManager.DataNeedsRefreshing += RefreshCache;
93+
try
94+
{
95+
this.taskManager.OnProgress += progressReporter.UpdateProgress;
96+
}
97+
catch (Exception ex)
98+
{
99+
LogHelper.Error(ex);
100+
}
101+
88102
}
89103

90104
public void Start()
@@ -166,12 +180,9 @@ private void RefreshCache(CacheType cacheType)
166180
}
167181

168182
public void Refresh(CacheType cacheType)
169-
{
170-
var cache = cacheContainer.GetCache(cacheType);
171-
// if the cache has valid data, we need to force an invalidation to refresh it
172-
// if it doesn't have valid data, it will trigger an invalidation automatically
173-
if (cache.ValidateData())
174-
cache.InvalidateData();
183+
{
184+
var cache = cacheContainer.GetCache(cacheType);
185+
cache.InvalidateData();
175186
}
176187

177188
private void CacheHasBeenInvalidated(CacheType cacheType)
@@ -186,32 +197,32 @@ private void CacheHasBeenInvalidated(CacheType cacheType)
186197
switch (cacheType)
187198
{
188199
case CacheType.Branches:
189-
repositoryManager?.UpdateBranches();
200+
repositoryManager?.UpdateBranches().Start();
190201
break;
191202

192203
case CacheType.GitLog:
193-
repositoryManager?.UpdateGitLog();
204+
repositoryManager?.UpdateGitLog().Start();
194205
break;
195206

196207
case CacheType.GitAheadBehind:
197-
repositoryManager?.UpdateGitAheadBehindStatus();
208+
repositoryManager?.UpdateGitAheadBehindStatus().Start();
198209
break;
199210

200211
case CacheType.GitLocks:
201212
if (CurrentRemote != null)
202-
repositoryManager?.UpdateLocks();
213+
repositoryManager?.UpdateLocks().Start();
203214
break;
204215

205216
case CacheType.GitUser:
206217
// user handles its own invalidation event
207218
break;
208219

209220
case CacheType.RepositoryInfo:
210-
repositoryManager?.UpdateRepositoryInfo();
221+
repositoryManager?.UpdateRepositoryInfo().Start();
211222
break;
212223

213224
case CacheType.GitStatus:
214-
repositoryManager?.UpdateGitStatus();
225+
repositoryManager?.UpdateGitStatus().Start();
215226
break;
216227

217228
default:

0 commit comments

Comments
 (0)