Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit fdb4096

Browse files
Merge branch 'master' into master
2 parents dd88bbd + 7a663a6 commit fdb4096

33 files changed

+397
-180
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
## Notices
44

5-
### VS 2017 v15.3 users, please read
5+
### If you are having issues with the installer, please read
66

7-
If you need to downgrade or uninstall the extension, **do not use** ***Revert*** in Visual Studio 2017 15.3. Instead, manually uninstall the extension with the steps listed in https://github.com/github/VisualStudio/issues/1206#issuecomment-326558902
8-
9-
If you have a corrupted extension cache, steps for fixing it are in https://github.com/github/VisualStudio/issues/1206#issuecomment-326053090
10-
11-
The Visual Studio 2017 15.3 installer [has a bug](https://github.com/github/VisualStudio/issues/1206) that causes a corruption of the installed extensions data when you revert an installation of the extension (see also [this MS issue](https://developercommunity.visualstudio.com/content/problem/102178/error-installing-github-extension.html)). Until VS 2017 15.4 comes out, **do not use Revert in** ***Extensions and Updates***.
7+
If you need to upgrade, downgrade, or uninstall the extension, and are having problems doing so, refer to this issue: https://github.com/github/VisualStudio/issues/1394 which details common problems and solutions when using the installer.
128

139
### The location of the submodules has changed as of 31-01-2017
1410

scripts/Run-NUnit.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ $xml = Join-Path $rootDirectory "nunit-$Project.xml"
4040
exit -1
4141
}
4242

43-
Run-Process -Fatal $TimeoutDuration $consoleRunner $dll,"--where ""cat != Timings""","--result=$xml;format=AppVeyor"
43+
$args = @()
44+
if ($AppVeyor) {
45+
$args = $dll, "--where", "cat!=Timings", "--result=$xml;format=AppVeyor"
46+
} else {
47+
$args = $dll, "--where", "cat!=Timings", "--result=$xml"
48+
}
49+
50+
Run-Process -Fatal $TimeoutDuration $consoleRunner $args
4451
if (!$?) {
4552
Die 1 "$Project tests failed"
4653
}

scripts/test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if ($Trace) {
3030
Set-PSDebug -Trace 1
3131
}
3232

33-
$env:PATH = "$$PSScriptRoot;$env:PATH"
33+
$env:PATH = "$PSScriptRoot;$env:PATH"
3434

3535
$exitcode = 0
3636

src/GitHub.Api/ApiClientConfiguration.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public static string MachineFingerprint
4949
{
5050
get
5151
{
52-
return GetSha256Hash(Info.ApplicationInfo.ApplicationDescription + ":" + GetMachineIdentifier());
52+
return GetSha256Hash(
53+
Info.ApplicationInfo.ApplicationDescription + ":" +
54+
GetMachineIdentifier() + ":" +
55+
GetMachineNameSafe());
5356
}
5457
}
5558

@@ -60,13 +63,13 @@ static string GetMachineIdentifier()
6063
try
6164
{
6265
// adapted from http://stackoverflow.com/a/1561067
63-
var fastedValidNetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
64-
.OrderBy(nic => nic.Speed)
66+
var fastestValidNetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
67+
.OrderByDescending(nic => nic.Speed)
6568
.Where(nic => nic.OperationalStatus == OperationalStatus.Up)
6669
.Select(nic => nic.GetPhysicalAddress().ToString())
67-
.FirstOrDefault(address => address.Length > 12);
70+
.FirstOrDefault(address => address.Length >= 12);
6871

69-
return fastedValidNetworkInterface ?? GetMachineNameSafe();
72+
return fastestValidNetworkInterface ?? GetMachineNameSafe();
7073
}
7174
catch (Exception)
7275
{

src/GitHub.Api/LoginManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class LoginManager : ILoginManager
1414
{
1515
readonly string[] scopes = { "user", "repo", "gist", "write:public_key" };
1616
readonly IKeychain keychain;
17-
readonly ITwoFactorChallengeHandler twoFactorChallengeHandler;
17+
readonly Lazy<ITwoFactorChallengeHandler> twoFactorChallengeHandler;
1818
readonly string clientId;
1919
readonly string clientSecret;
2020
readonly string authorizationNote;
@@ -31,7 +31,7 @@ public class LoginManager : ILoginManager
3131
/// <param name="fingerprint">The machine fingerprint.</param>
3232
public LoginManager(
3333
IKeychain keychain,
34-
ITwoFactorChallengeHandler twoFactorChallengeHandler,
34+
Lazy<ITwoFactorChallengeHandler> twoFactorChallengeHandler,
3535
string clientId,
3636
string clientSecret,
3737
string authorizationNote = null,
@@ -194,7 +194,7 @@ async Task<ApplicationAuthorization> HandleTwoFactorAuthorization(
194194
{
195195
for (;;)
196196
{
197-
var challengeResult = await twoFactorChallengeHandler.HandleTwoFactorException(exception);
197+
var challengeResult = await twoFactorChallengeHandler.Value.HandleTwoFactorException(exception);
198198

199199
if (challengeResult == null)
200200
{
@@ -218,7 +218,7 @@ async Task<ApplicationAuthorization> HandleTwoFactorAuthorization(
218218
}
219219
catch (Exception e)
220220
{
221-
await twoFactorChallengeHandler.ChallengeFailed(e);
221+
await twoFactorChallengeHandler.Value.ChallengeFailed(e);
222222
await keychain.Delete(hostAddress).ConfigureAwait(false);
223223
throw;
224224
}

src/GitHub.App/Factories/ViewViewModelFactory.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ public class ViewViewModelFactory : IViewViewModelFactory
2020

2121
[ImportingConstructor]
2222
public ViewViewModelFactory(
23-
IGitHubServiceProvider serviceProvider,
24-
ICompositionService cc)
23+
IGitHubServiceProvider serviceProvider)
2524
{
2625
this.serviceProvider = serviceProvider;
27-
cc.SatisfyImportsOnce(this);
2826
}
2927

30-
[ImportMany(AllowRecomposition = true)]
28+
[ImportMany]
3129
IEnumerable<ExportFactory<FrameworkElement, IViewModelMetadata>> Views { get; set; }
3230

3331
/// <inheritdoc/>
@@ -45,7 +43,7 @@ public FrameworkElement CreateView<TViewModel>() where TViewModel : IViewModel
4543
/// <inheritdoc/>
4644
public FrameworkElement CreateView(Type viewModel)
4745
{
48-
var f = Views.FirstOrDefault(x => x.Metadata.ViewModelType.Contains(viewModel));
46+
var f = Views.FirstOrDefault(x => x.Metadata.ViewModelType.Contains(viewModel.FullName));
4947
return f?.CreateExport().Value;
5048
}
5149
}

src/GitHub.App/ViewModels/GitHubPane/GitHubPaneViewModel.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public sealed class GitHubPaneViewModel : ViewModelBase, IGitHubPaneViewModel, I
4646
readonly ReactiveCommand<Unit> refresh;
4747
readonly ReactiveCommand<Unit> showPullRequests;
4848
readonly ReactiveCommand<object> openInBrowser;
49+
bool initialized;
4950
IViewModel content;
5051
ILocalRepositoryModel localRepository;
5152
string searchQuery;
@@ -199,7 +200,7 @@ public void Dispose()
199200
public async Task InitializeAsync(IServiceProvider paneServiceProvider)
200201
{
201202
await UpdateContent(teServiceHolder.ActiveRepo);
202-
teServiceHolder.Subscribe(this, x => UpdateContent(x).Forget());
203+
teServiceHolder.Subscribe(this, x => UpdateContentIfRepositoryChanged(x).Forget());
203204
connectionManager.Connections.CollectionChanged += (_, __) => UpdateContent(LocalRepository).Forget();
204205

205206
BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.pullRequestCommand, showPullRequests);
@@ -343,10 +344,11 @@ async Task NavigateTo<TViewModel>(Func<TViewModel, Task> initialize, Func<TViewM
343344

344345
async Task UpdateContent(ILocalRepositoryModel repository)
345346
{
347+
initialized = true;
346348
LocalRepository = repository;
347349
Connection = null;
348-
349350
Content = null;
351+
navigator.Clear();
350352

351353
if (repository == null)
352354
{
@@ -370,9 +372,8 @@ async Task UpdateContent(ILocalRepositoryModel repository)
370372

371373
Connection = await connectionManager.GetConnection(hostAddress);
372374

373-
if (Connection != null)
375+
if (Connection?.IsLoggedIn == true)
374376
{
375-
navigator.Clear();
376377
Content = navigator;
377378
await ShowDefaultPage();
378379
}
@@ -387,6 +388,14 @@ async Task UpdateContent(ILocalRepositoryModel repository)
387388
}
388389
}
389390

391+
async Task UpdateContentIfRepositoryChanged(ILocalRepositoryModel repository)
392+
{
393+
if (!initialized || !Equals(repository, LocalRepository))
394+
{
395+
await UpdateContent(repository);
396+
}
397+
}
398+
390399
static async Task<bool> IsValidRepository(ISimpleApiClient client)
391400
{
392401
try

src/GitHub.App/ViewModels/GitHubPane/NavigationViewModel.cs

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Collections.Specialized;
43
using System.ComponentModel.Composition;
54
using System.Linq;
6-
using System.Reactive.Disposables;
75
using System.Reactive.Linq;
86
using GitHub.Extensions;
97
using ReactiveUI;
@@ -19,7 +17,6 @@ public class NavigationViewModel : ViewModelBase, INavigationViewModel
1917
{
2018
readonly ReactiveList<IPanePageViewModel> history;
2119
readonly ObservableAsPropertyHelper<IPanePageViewModel> content;
22-
Dictionary<IPanePageViewModel, CompositeDisposable> pageDispose;
2320
int index = -1;
2421

2522
/// <summary>
@@ -42,6 +39,13 @@ public NavigationViewModel()
4239
.StartWith((IPanePageViewModel)null)
4340
.ToProperty(this, x => x.Content);
4441

42+
this.WhenAnyValue(x => x.Content)
43+
.Buffer(2, 1)
44+
.Subscribe(x => {
45+
if (x[0] != null && history.Contains(x[0])) x[0].Deactivated();
46+
x[1]?.Activated();
47+
});
48+
4549
NavigateBack = ReactiveCommand.Create(pos.Select(x => x.Index > 0));
4650
NavigateBack.Subscribe(_ => Back());
4751
NavigateForward = ReactiveCommand.Create(pos.Select(x => x.Index < x.Count - 1));
@@ -72,13 +76,13 @@ public void NavigateTo(IPanePageViewModel page)
7276
{
7377
Guard.ArgumentNotNull(page, nameof(page));
7478

79+
history.Insert(index + 1, page);
80+
++Index;
81+
7582
if (index < history.Count - 1)
7683
{
7784
history.RemoveRange(index + 1, history.Count - (index + 1));
7885
}
79-
80-
history.Add(page);
81-
++Index;
8286
}
8387

8488
/// <inheritdoc/>
@@ -103,7 +107,7 @@ public bool Forward()
103107
public void Clear()
104108
{
105109
Index = -1;
106-
history.Clear();
110+
history.RemoveRange(0, history.Count);
107111
}
108112

109113
public int RemoveAll(IPanePageViewModel page)
@@ -113,31 +117,11 @@ public int RemoveAll(IPanePageViewModel page)
113117
return count;
114118
}
115119

116-
public void RegisterDispose(IPanePageViewModel page, IDisposable dispose)
117-
{
118-
if (pageDispose == null)
119-
{
120-
pageDispose = new Dictionary<IPanePageViewModel, CompositeDisposable>();
121-
}
122-
123-
CompositeDisposable item;
124-
125-
if (!pageDispose.TryGetValue(page, out item))
126-
{
127-
item = new CompositeDisposable();
128-
pageDispose.Add(page, item);
129-
}
130-
131-
item.Add(dispose);
132-
}
133-
134120
void BeforeItemAdded(IPanePageViewModel page)
135121
{
136-
if (page.CloseRequested != null && !history.Contains(page))
122+
if (!history.Contains(page))
137123
{
138-
RegisterDispose(
139-
page,
140-
page.CloseRequested.Subscribe(_ => RemoveAll(page)));
124+
page.CloseRequested.Subscribe(_ => RemoveAll(page));
141125
}
142126
}
143127

@@ -150,13 +134,8 @@ void ItemRemoved(int removedIndex, IPanePageViewModel page)
150134

151135
if (!history.Contains(page))
152136
{
153-
CompositeDisposable dispose = null;
154-
155-
if (pageDispose?.TryGetValue(page, out dispose) == true)
156-
{
157-
dispose.Dispose();
158-
pageDispose.Remove(page);
159-
}
137+
if (Content == page) page.Deactivated();
138+
page.Dispose();
160139
}
161140
}
162141

@@ -177,16 +156,7 @@ void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
177156
break;
178157

179158
case NotifyCollectionChangedAction.Reset:
180-
if (pageDispose != null)
181-
{
182-
foreach (var dispose in pageDispose.Values)
183-
{
184-
dispose.Dispose();
185-
}
186-
187-
pageDispose.Clear();
188-
}
189-
break;
159+
throw new NotSupportedException();
190160

191161
default:
192162
throw new NotImplementedException();

src/GitHub.App/ViewModels/GitHubPane/PanePageViewModelBase.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace GitHub.ViewModels.GitHubPane
1212
public abstract class PanePageViewModelBase : ViewModelBase, IPanePageViewModel, IDisposable
1313
{
1414
static readonly Uri paneUri = new Uri("github://pane");
15-
Subject<Uri> navigate = new Subject<Uri>();
15+
readonly Subject<Uri> navigate = new Subject<Uri>();
16+
readonly Subject<Unit> close = new Subject<Unit>();
1617
Exception error;
1718
bool isBusy;
1819
bool isLoading;
@@ -59,11 +60,21 @@ public string Title
5960
}
6061

6162
/// <inheritdoc/>
62-
public virtual IObservable<Unit> CloseRequested { get; }
63+
public IObservable<Unit> CloseRequested => close;
6364

6465
/// <inheritdoc/>
6566
public IObservable<Uri> NavigationRequested => navigate;
6667

68+
/// <inheritdoc/>
69+
public virtual void Activated()
70+
{
71+
}
72+
73+
/// <inheritdoc/>
74+
public virtual void Deactivated()
75+
{
76+
}
77+
6778
/// <inheritdoc/>
6879
public void Dispose()
6980
{
@@ -74,6 +85,11 @@ public void Dispose()
7485
/// <inheritdoc/>
7586
public virtual Task Refresh() => Task.CompletedTask;
7687

88+
/// <summary>
89+
/// Sends a request to close the page.
90+
/// </summary>
91+
protected void Close() => close.OnNext(Unit.Default);
92+
7793
/// <summary>
7894
/// Sends a request to navigate to a new page.
7995
/// </summary>
@@ -86,8 +102,8 @@ protected virtual void Dispose(bool disposing)
86102
{
87103
if (disposing)
88104
{
89-
navigate?.Dispose();
90-
navigate = null;
105+
close.Dispose();
106+
navigate.Dispose();
91107
}
92108
}
93109
}

src/GitHub.App/ViewModels/GitHubPane/PullRequestCreationViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public PullRequestCreationViewModel(
9595
});
9696

9797
Cancel = ReactiveCommand.Create();
98+
Cancel.Subscribe(_ => Close());
9899

99100
isExecuting = CreatePullRequest.IsExecuting.ToProperty(this, x => x.IsExecuting);
100101

@@ -298,7 +299,5 @@ ReactivePropertyValidator BranchValidator
298299
get { return branchValidator; }
299300
set { this.RaiseAndSetIfChanged(ref branchValidator, value); }
300301
}
301-
302-
public override IObservable<Unit> CloseRequested => Cancel.SelectUnit();
303302
}
304303
}

0 commit comments

Comments
 (0)