Skip to content

Commit

Permalink
Converted to use AsyncPackage and updated autoload
Browse files Browse the repository at this point in the history
Fixed #5
  • Loading branch information
madskristensen committed Dec 1, 2016
1 parent 903880e commit f1102af
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 257 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
os: Visual Studio 2017 RC
os: Visual Studio 2015

install:
- ps: (new-object Net.WebClient).DownloadString("https://raw.github.com/madskristensen/ExtensionScripts/master/AppVeyor/vsix.ps1") | iex
Expand Down
463 changes: 231 additions & 232 deletions src/BrowserReloadOnSave.csproj

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions src/Commands/EnableReloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@ sealed class EnableReloadCommand
{
readonly Package _package;

EnableReloadCommand(Package package)
EnableReloadCommand(Package package, OleMenuCommandService commandService)
{
_package = package;

var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var id = new CommandID(PackageGuids.guidBrowserReloadCmdSet, PackageIds.EnableReloadCommandId);
var cmd = new OleMenuCommand(Execute, id);
cmd.BeforeQueryStatus += BeforeQueryStatus;
commandService.AddCommand(cmd);
}
var id = new CommandID(PackageGuids.guidBrowserReloadCmdSet, PackageIds.EnableReloadCommandId);
var cmd = new OleMenuCommand(Execute, id);
cmd.BeforeQueryStatus += BeforeQueryStatus;
commandService.AddCommand(cmd);
}

public static EnableReloadCommand Instance { get; private set; }

public static void Initialize(Package package)
public static void Initialize(Package package, OleMenuCommandService commandService)
{
Instance = new EnableReloadCommand(package);
Instance = new EnableReloadCommand(package, commandService);
}

IServiceProvider ServiceProvider
Expand Down
7 changes: 3 additions & 4 deletions src/Helpers/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

public static class Logger
{
static IVsOutputWindowPane pane;
static object _syncRoot = new object();
static IServiceProvider _provider;
static string _name;

public static void Initialize(IServiceProvider provider, string name)
public static void Initialize(string name)
{
_provider = provider;
_name = name;
}

Expand Down Expand Up @@ -47,7 +46,7 @@ static bool EnsurePane()
if (pane == null)
{
Guid guid = Guid.NewGuid();
var output = (IVsOutputWindow)_provider.GetService(typeof(SVsOutputWindow));
var output = (IVsOutputWindow)Package.GetGlobalService(typeof(SVsOutputWindow));
output.CreatePane(ref guid, _name, 1, 1);
output.GetPane(ref guid, out pane);
}
Expand Down
38 changes: 30 additions & 8 deletions src/VSPackage.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
using System;
using System.ComponentModel.Design;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

namespace BrowserReloadOnSave
{
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", Vsix.Version, IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideOptionPage(typeof(Options), "Web", Vsix.Name, 101, 102, true, new string[0], ProvidesLocalizedCategoryName = false)]
[ProvideAutoLoad("{349C5852-65DF-11dA-9384-00065B846F21}", PackageAutoLoadFlags.BackgroundLoad)] // WAP
[ProvideAutoLoad("{E24C65DC-7377-472b-9ABA-BC803B73C61A}", PackageAutoLoadFlags.BackgroundLoad)] // WebSite
[ProvideAutoLoad("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}", PackageAutoLoadFlags.BackgroundLoad)] // ProjectK
[ProvideAutoLoad(ActivationContextGuid)]
[ProvideUIContextRule(ActivationContextGuid, "Load Package",
"WAP | WebSite | ProjectK | DotNetCoreWeb",
new string[] {
"WAP",
"WebSite",
"ProjectK",
"DotNetCoreWeb"
},
new string[] {
"SolutionHasProjectFlavor:{349C5851-65DF-11DA-9384-00065B846F21}",
"SolutionHasProjectFlavor:{E24C65DC-7377-472B-9ABA-BC803B73C61A}",
"SolutionHasProjectFlavor:{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}",
"SolutionHasProjectCapability:DotNetCoreWeb"
})]
[Guid(PackageGuids.guidBrowserReloadPackageString)]
public sealed class VSPackage : Package
public sealed class VSPackage : AsyncPackage
{
private const string ActivationContextGuid = "{4b6c8d76-4918-45aa-9b26-8f246c1773aa}";

public static Options Options
{
get;
private set;
}

protected override void Initialize()
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
Logger.Initialize(Vsix.Name);

Options = (Options)GetDialogPage(typeof(Options));
var commandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

Logger.Initialize(this, Vsix.Name);
EnableReloadCommand.Initialize(this);
if (commandService != null)
{
EnableReloadCommand.Initialize(this, commandService);
}
}
}
}
2 changes: 1 addition & 1 deletion src/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<packages>
<package id="Microsoft.VisualStudio.Imaging" version="14.3.25407" targetFramework="net451" />
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net451" />
<package id="Microsoft.VisualStudio.Sdk.BuildTasks.14.0" version="14.0.12-pre" targetFramework="net451" developmentDependency="true" />
<package id="Microsoft.VisualStudio.Shell.14.0" version="14.3.25407" targetFramework="net451" />
<package id="Microsoft.VisualStudio.Shell.Immutable.10.0" version="10.0.30319" targetFramework="net451" />
<package id="Microsoft.VisualStudio.Shell.Immutable.11.0" version="11.0.50727" targetFramework="net451" />
Expand All @@ -18,5 +19,4 @@
<package id="Microsoft.VisualStudio.Threading" version="14.1.131" targetFramework="net451" />
<package id="Microsoft.VisualStudio.Utilities" version="14.3.25407" targetFramework="net451" />
<package id="Microsoft.VisualStudio.Validation" version="14.1.111" targetFramework="net451" />
<package id="Microsoft.VSSDK.BuildTools" version="14.3.25420" targetFramework="net451" developmentDependency="true" />
</packages>

0 comments on commit f1102af

Please sign in to comment.