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

Commit 89748d2

Browse files
authored
Merge branch 'master' into fixes/1240-nullref-diffservice
2 parents 637fd92 + 75ec005 commit 89748d2

File tree

15 files changed

+297
-113
lines changed

15 files changed

+297
-113
lines changed

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.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: 15 additions & 6 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
@@ -402,8 +411,8 @@ static async Task<bool> IsValidRepository(ISimpleApiClient client)
402411

403412
static Regex CreateRoute(string route)
404413
{
405-
// Build RegEx from route (:foo to named group (?<foo>[a-z0-9]+)).
406-
var routeFormat = new Regex("(:([a-z]+))\\b").Replace(route, "(?<$2>[a-z0-9]+)");
414+
// Build RegEx from route (:foo to named group (?<foo>[\w_.-]+)).
415+
var routeFormat = new Regex("(:([a-z]+))\\b").Replace(route, @"(?<$2>[\w_.-]+)");
407416
return new Regex(routeFormat, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
408417
}
409418
}

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
}

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Reactive;
7+
using System.Reactive.Disposables;
78
using System.Reactive.Linq;
89
using System.Reactive.Threading.Tasks;
910
using System.Threading.Tasks;
@@ -47,6 +48,8 @@ public sealed class PullRequestDetailViewModel : PanePageViewModelBase, IPullReq
4748
bool isCheckedOut;
4849
bool isFromFork;
4950
bool isInCheckout;
51+
bool active;
52+
bool refreshOnActivate;
5053
Uri webUrl;
5154

5255
/// <summary>
@@ -489,6 +492,21 @@ public string GetLocalFilePath(IPullRequestFileNode file)
489492
return Path.Combine(LocalRepository.LocalPath, file.DirectoryPath, file.FileName);
490493
}
491494

495+
/// <inheritdoc/>
496+
public override void Activated()
497+
{
498+
active = true;
499+
500+
if (refreshOnActivate)
501+
{
502+
Refresh().Forget();
503+
refreshOnActivate = false;
504+
}
505+
}
506+
507+
/// <inheritdoc/>
508+
public override void Deactivated() => active = false;
509+
492510
/// <inheritdoc/>
493511
protected override void Dispose(bool disposing)
494512
{
@@ -504,8 +522,15 @@ async void ActiveRepositoriesChanged()
504522
{
505523
try
506524
{
507-
await ThreadingHelper.SwitchToMainThreadAsync();
508-
await Refresh();
525+
if (active)
526+
{
527+
await ThreadingHelper.SwitchToMainThreadAsync();
528+
await Refresh();
529+
}
530+
else
531+
{
532+
refreshOnActivate = true;
533+
}
509534
}
510535
catch (Exception ex)
511536
{

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,15 @@ void UpdateFilter(PullRequestState state, IAccount ass, IAccount aut, string fil
197197
filterTextIsString = hasText && !filterTextIsNumber;
198198
}
199199

200-
pullRequests.Filter = (pullRequest, index, list) =>
201-
(!state.IsOpen.HasValue || state.IsOpen == pullRequest.IsOpen) &&
202-
(ass == null || ass.Equals(pullRequest.Assignee)) &&
203-
(aut == null || aut.Equals(pullRequest.Author)) &&
204-
(filterTextIsNumber == false || pullRequest.Number == filterPullRequestNumber) &&
205-
(filterTextIsString == false || pullRequest.Title.ToUpperInvariant().Contains(filText.ToUpperInvariant()));
200+
if (!pullRequests.Disposed)
201+
{
202+
pullRequests.Filter = (pullRequest, index, list) =>
203+
(!state.IsOpen.HasValue || state.IsOpen == pullRequest.IsOpen) &&
204+
(ass == null || ass.Equals(pullRequest.Assignee)) &&
205+
(aut == null || aut.Equals(pullRequest.Author)) &&
206+
(filterTextIsNumber == false || pullRequest.Number == filterPullRequestNumber) &&
207+
(filterTextIsString == false || pullRequest.Title.ToUpperInvariant().Contains(filText.ToUpperInvariant()));
208+
}
206209
}
207210

208211
string searchQuery;

0 commit comments

Comments
 (0)