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

Commit 7f3236f

Browse files
committed
Factor knowledge of full extension into FullExtensionUtilities
1 parent 982bb5d commit 7f3236f

File tree

7 files changed

+85
-108
lines changed

7 files changed

+85
-108
lines changed

src/GitHub.VisualStudio.16/ExtensionServicesFactory.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
using Microsoft;
5+
using Microsoft.VisualStudio.Shell;
6+
using Microsoft.VisualStudio.Shell.Interop;
7+
using ICodeContainerProvider = Microsoft.VisualStudio.Shell.CodeContainerManagement.ICodeContainerProvider;
8+
9+
namespace GitHub.VisualStudio
10+
{
11+
public static class FullExtensionUtilities
12+
{
13+
const string GitHubPackageId = "c3d3dc68-c977-411f-b3e8-03b0dccf7dfc";
14+
15+
public static bool IsInstalled(IServiceProvider serviceProvider)
16+
{
17+
ThreadHelper.ThrowIfNotOnUIThread();
18+
19+
return FindGitHubPackage(serviceProvider) != null;
20+
}
21+
22+
public static ICodeContainerProvider FindGitHubContainerProvider(IServiceProvider serviceProvide)
23+
{
24+
ThreadHelper.ThrowIfNotOnUIThread();
25+
26+
if (FindGitHubPackage(serviceProvide) is IVsPackage package)
27+
{
28+
var baseDirectory = Path.GetDirectoryName(package.GetType().Assembly.Location);
29+
var assemblyFile = Path.Combine(baseDirectory, "GitHub.StartPage.dll");
30+
var assembly = Assembly.LoadFrom(assemblyFile);
31+
var type = assembly.GetType("GitHub.StartPage.GitHubContainerProvider", true);
32+
return (ICodeContainerProvider)Activator.CreateInstance(type);
33+
}
34+
35+
return null;
36+
}
37+
38+
public static IVsPackage FindGitHubPackage(IServiceProvider serviceProvider)
39+
{
40+
ThreadHelper.ThrowIfNotOnUIThread();
41+
42+
var shell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
43+
Assumes.Present(shell);
44+
shell.LoadPackage(new Guid(GitHubPackageId), out var package);
45+
return package;
46+
}
47+
}
48+
}

src/GitHub.VisualStudio.16/GitHub.VisualStudio.16.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,14 @@
6666
<Compile Include="Base\TeamExplorerBasePage.cs" />
6767
<Compile Include="Base\TeamExplorerBaseSection.cs" />
6868
<Compile Include="CompositionServices.cs" />
69-
<Compile Include="ExtensionServicesFactory.cs" />
69+
<Compile Include="FullExtensionUtilities.cs" />
7070
<Compile Include="Home\GitHubHomeContent.xaml.cs">
7171
<DependentUpon>GitHubHomeContent.xaml</DependentUpon>
7272
</Compile>
7373
<Compile Include="Home\HomeSection.cs" />
7474
<Compile Include="IExtensionServices.cs" />
7575
<Compile Include="Images.imagemanifest.cs" />
76-
<Compile Include="InBoxExtensionServices.cs" />
77-
<Compile Include="InstalledExtensionServices.cs" />
76+
<Compile Include="InBoxGitHubContainerProvider.cs" />
7877
<Compile Include="Properties\AssemblyInfo.cs" />
7978
<Compile Include="Resources.Designer.cs">
8079
<AutoGen>True</AutoGen>

src/GitHub.VisualStudio.16/InBoxExtensionServices.cs renamed to src/GitHub.VisualStudio.16/InBoxGitHubContainerProvider.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313

1414
namespace GitHub.VisualStudio
1515
{
16-
public class InBoxExtensionServices : IExtensionServices
17-
{
18-
public ICodeContainerProvider GetGitHubContainerProvider()
19-
{
20-
return new InBoxGitHubContainerProvider();
21-
}
22-
}
23-
2416
[Guid(Guids.CodeContainerProviderId)]
2517
public class InBoxGitHubContainerProvider : ICodeContainerProvider
2618
{
@@ -37,12 +29,7 @@ public async Task<CodeContainer> AcquireCodeContainerAsync(RemoteCodeContainer o
3729

3830
async Task<CodeContainer> RunAcquisitionAsync(IProgress<ServiceProgressData> downloadProgress, CancellationToken cancellationToken, string url = null)
3931
{
40-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
41-
42-
var componentModel = await ServiceProvider.GetGlobalServiceAsync<SComponentModel, IComponentModel>();
43-
Assumes.Present(componentModel);
44-
45-
var result = await ShowCloneDialogAsync(componentModel, downloadProgress, cancellationToken, url);
32+
var result = await ShowCloneDialogAsync(downloadProgress, cancellationToken, url);
4633
if (result == null)
4734
{
4835
return null;
@@ -69,9 +56,13 @@ async Task<CodeContainer> RunAcquisitionAsync(IProgress<ServiceProgressData> dow
6956
return codeContainer;
7057
}
7158

72-
static async Task<CloneDialogResult> ShowCloneDialogAsync(IComponentModel componentModel,
73-
IProgress<ServiceProgressData> downloadProgress, CancellationToken cancellationToken, string url = null)
59+
async Task<CloneDialogResult> ShowCloneDialogAsync(IProgress<ServiceProgressData> downloadProgress,
60+
CancellationToken cancellationToken, string url = null)
7461
{
62+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
63+
64+
var componentModel = await ServiceProvider.GetGlobalServiceAsync<SComponentModel, IComponentModel>();
65+
Assumes.Present(componentModel);
7566
var compositionServices = componentModel.DefaultExportProvider.GetExportedValue<CompositionServices>();
7667
var exportProvider = compositionServices.GetExportProvider();
7768

src/GitHub.VisualStudio.16/InstalledExtensionServices.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/GitHub.VisualStudio.16/StartPagePackage.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ protected override ICodeContainerProvider CreateCodeContainerProvider(Guid provi
1919
{
2020
ThreadHelper.ThrowIfNotOnUIThread();
2121

22-
var factory = new ExtensionServicesFactory(this);
23-
var services = factory.Create();
24-
return services.GetGitHubContainerProvider();
22+
var codeContainerProvider = FullExtensionUtilities.FindGitHubContainerProvider(this);
23+
if (codeContainerProvider != null)
24+
{
25+
return codeContainerProvider;
26+
}
27+
28+
return new InBoxGitHubContainerProvider();
2529
}
2630
}
2731
}

src/GitHub.VisualStudio.16/Sync/PublishSection.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using GitHub.ViewModels.TeamExplorer;
1111
using GitHub.VisualStudio;
1212
using Microsoft.TeamFoundation.Controls;
13+
using Microsoft.VisualStudio.Shell;
1314
using ReactiveUI;
1415

1516

@@ -27,7 +28,6 @@ public class PublishSection : TeamExplorerBaseSection
2728
public const int Priority = 4;
2829

2930
readonly Guid PushToRemoteSectionId = new Guid("99ADF41C-0022-4C03-B3C2-05047A3F6C2C");
30-
readonly Guid GitHubPublishSectionId = new Guid("92655B52-360D-4BF5-95C5-D9E9E596AC76");
3131

3232
[ImportingConstructor]
3333
public PublishSection(CompositionServices compositionServices)
@@ -58,8 +58,17 @@ protected PublishView View
5858
/// </summary>
5959
public override void Initialize(object sender, SectionInitializeEventArgs e)
6060
{
61+
ThreadHelper.ThrowIfNotOnUIThread();
62+
6163
base.Initialize(sender, e);
6264

65+
// Remain hidden when full GitHub extension is installed
66+
if (FullExtensionUtilities.IsInstalled(ServiceProvider))
67+
{
68+
IsVisible = false;
69+
return;
70+
}
71+
6372
RefreshVisibility();
6473

6574
if (ServiceProvider.GetService(typeof(ITeamExplorerPage)) is ITeamExplorerPage page)
@@ -68,11 +77,6 @@ public override void Initialize(object sender, SectionInitializeEventArgs e)
6877
{
6978
pushToRemoteSection.PropertyChanged += Section_PropertyChanged;
7079
}
71-
72-
if (page.GetSection(GitHubPublishSectionId) is ITeamExplorerSection gitHubPublishSection)
73-
{
74-
gitHubPublishSection.PropertyChanged += Section_PropertyChanged;
75-
}
7680
}
7781

7882
PublishToGitHub = new RelayCommand(o => ShowPublishDialog());
@@ -123,27 +127,27 @@ void Section_PropertyChanged(object sender, PropertyChangedEventArgs e)
123127

124128
void RefreshVisibility()
125129
{
126-
bool IsSectionVisible(ITeamExplorerPage teamExplorerPage, Guid sectionId)
127-
{
128-
if (teamExplorerPage.GetSection(sectionId) is ITeamExplorerSection pushToRemoteSection)
129-
{
130-
return pushToRemoteSection.SectionContent != null && pushToRemoteSection.IsVisible;
131-
}
132-
133-
return false;
134-
}
135-
136130
var visible = false;
137131

138132
if (ServiceProvider.GetService(typeof(ITeamExplorerPage)) is ITeamExplorerPage page)
139133
{
140-
visible = IsSectionVisible(page, PushToRemoteSectionId) && !IsSectionVisible(page, GitHubPublishSectionId);
134+
visible = IsSectionVisible(page, PushToRemoteSectionId);
141135
}
142136

143137
if (IsVisible != visible)
144138
{
145139
IsVisible = visible;
146140
}
147141
}
142+
143+
bool IsSectionVisible(ITeamExplorerPage teamExplorerPage, Guid sectionId)
144+
{
145+
if (teamExplorerPage.GetSection(sectionId) is ITeamExplorerSection pushToRemoteSection)
146+
{
147+
return pushToRemoteSection.SectionContent != null && pushToRemoteSection.IsVisible;
148+
}
149+
150+
return false;
151+
}
148152
}
149153
}

0 commit comments

Comments
 (0)