Skip to content

Commit

Permalink
Recreate as a VS2019 extension
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdstel committed Dec 12, 2019
1 parent 628f26a commit 8e85161
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 282 deletions.
16 changes: 8 additions & 8 deletions scrcpy-vs.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
# Visual Studio Version 16
VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "scrcpy-vs", "scrcpy-vs\scrcpy-vs.csproj", "{28F1DDE5-CCDF-4121-B369-90519C757951}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "scrcpy-vs", "scrcpy-vs\scrcpy-vs.csproj", "{3B6D9C25-3629-4574-B459-945A05BB8A9C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{28F1DDE5-CCDF-4121-B369-90519C757951}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28F1DDE5-CCDF-4121-B369-90519C757951}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28F1DDE5-CCDF-4121-B369-90519C757951}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28F1DDE5-CCDF-4121-B369-90519C757951}.Release|Any CPU.Build.0 = Release|Any CPU
{3B6D9C25-3629-4574-B459-945A05BB8A9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B6D9C25-3629-4574-B459-945A05BB8A9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B6D9C25-3629-4574-B459-945A05BB8A9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B6D9C25-3629-4574-B459-945A05BB8A9C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D7324178-ED2C-40A2-A2CF-A8B30B08A4BC}
SolutionGuid = {24D73EE2-7B2B-40D6-B777-A6A6A21C0290}
EndGlobalSection
EndGlobal
Binary file modified scrcpy-vs/Key.snk
Binary file not shown.
4 changes: 2 additions & 2 deletions scrcpy-vs/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.1.0")]
[assembly: AssemblyFileVersion("0.5.1.0")]
[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]
Binary file removed scrcpy-vs/UI/Resources/ScrcpyToolWindowPackage.ico
Binary file not shown.
Binary file added scrcpy-vs/UI/Resources/ext-icon.ico
Binary file not shown.
20 changes: 10 additions & 10 deletions scrcpy-vs/UI/ScrcpyToolWindow.cs → scrcpy-vs/UI/ScrcpyWindow.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace scrcpy.VisualStudio.UI
{
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;

namespace scrcpy.VisualStudio.UI
{
/// <summary>
/// This class implements the tool window exposed by this package and hosts a user control.
/// </summary>
Expand All @@ -15,20 +15,20 @@
/// implementation of the IVsUIElementPane interface.
/// </para>
/// </remarks>
[Guid("e4ebc168-7fd1-42b4-9c77-8340a86f8644")]
public class ScrcpyToolWindow : ToolWindowPane
[Guid("f3c9e782-7825-4f77-b696-a53218ca48ad")]
public class ScrcpyWindow : ToolWindowPane
{
/// <summary>
/// Initializes a new instance of the <see cref="ScrcpyToolWindow"/> class.
/// Initializes a new instance of the <see cref="ScrcpyWindow"/> class.
/// </summary>
public ScrcpyToolWindow() : base(null)
public ScrcpyWindow() : base(null)
{
this.Caption = "scrcpy";

// This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
// we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
// the object returned by the Content property.
this.Content = new ScrcpyToolWindowControl();
this.Content = new ScrcpyWindowControl();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace scrcpy.VisualStudio.UI
/// <summary>
/// Command handler
/// </summary>
internal sealed class ScrcpyToolWindowCommand
internal sealed class ScrcpyWindowCommand
{
/// <summary>
/// Command ID.
Expand All @@ -22,20 +22,20 @@ internal sealed class ScrcpyToolWindowCommand
/// <summary>
/// Command menu group (command set GUID).
/// </summary>
public static readonly Guid CommandSet = new Guid("94db034e-bda6-45cc-8f5a-3f278c8068d8");
public static readonly Guid CommandSet = new Guid("f72d56e5-b073-4fcc-9ae0-eb42776b3a3c");

/// <summary>
/// VS Package that provides this command, not null.
/// </summary>
private readonly AsyncPackage package;

/// <summary>
/// Initializes a new instance of the <see cref="ScrcpyToolWindowCommand"/> class.
/// Initializes a new instance of the <see cref="ScrcpyWindowCommand"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
/// <param name="commandService">Command service to add command to, not null.</param>
private ScrcpyToolWindowCommand(AsyncPackage package, OleMenuCommandService commandService)
private ScrcpyWindowCommand(AsyncPackage package, OleMenuCommandService commandService)
{
this.package = package ?? throw new ArgumentNullException(nameof(package));
commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
Expand All @@ -48,7 +48,7 @@ private ScrcpyToolWindowCommand(AsyncPackage package, OleMenuCommandService comm
/// <summary>
/// Gets the instance of the command.
/// </summary>
public static ScrcpyToolWindowCommand Instance
public static ScrcpyWindowCommand Instance
{
get;
private set;
Expand All @@ -71,12 +71,12 @@ private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
/// <param name="package">Owner package, not null.</param>
public static async Task InitializeAsync(AsyncPackage package)
{
// Verify the current thread is the UI thread - the call to AddCommand in ScrcpyToolWindowCommand's constructor requires
// Switch to the main thread - the call to AddCommand in ScrcpyWindowCommand's constructor requires
// the UI thread.
ThreadHelper.ThrowIfNotOnUIThread();
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new ScrcpyToolWindowCommand(package, commandService);
Instance = new ScrcpyWindowCommand(package, commandService);
}

/// <summary>
Expand All @@ -86,19 +86,14 @@ public static async Task InitializeAsync(AsyncPackage package)
/// <param name="e">The event args.</param>
private void Execute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();

// Get the instance number 0 of this tool window. This window is single instance so this instance
// is actually the only one.
// The last flag is set to true so that if the tool window does not exists it will be created.
ToolWindowPane window = this.package.FindToolWindow(typeof(ScrcpyToolWindow), 0, true);
if ((null == window) || (null == window.Frame))
this.package.JoinableTaskFactory.RunAsync(async delegate
{
throw new NotSupportedException("Cannot create tool window");
}

IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
ToolWindowPane window = await this.package.ShowToolWindowAsync(typeof(ScrcpyWindow), 0, true, this.package.DisposalToken);
if ((null == window) || (null == window.Frame))
{
throw new NotSupportedException("Cannot create tool window");
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<UserControl
x:Class="scrcpy.VisualStudio.UI.ScrcpyToolWindowControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<UserControl x:Class="scrcpy.VisualStudio.UI.ScrcpyWindowControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:model="clr-namespace:scrcpy.VisualStudio.Model"
xmlns:ui="clr-namespace:scrcpy.VisualStudio.UI"
xmlns:v="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
d:DesignHeight="300"
d:DesignWidth="300"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// <summary>
/// Interaction logic for ScrcpyToolWindowControl.
/// </summary>
public partial class ScrcpyToolWindowControl : UserControl, IDisposable
public partial class ScrcpyWindowControl : UserControl, IDisposable
{
/// <summary>
/// The delay introduced before refreshing devices.
Expand Down Expand Up @@ -45,14 +45,14 @@ public partial class ScrcpyToolWindowControl : UserControl, IDisposable
/// <summary>
/// Initializes a new instance of the <see cref="ScrcpyToolWindowControl"/> class.
/// </summary>
public ScrcpyToolWindowControl()
public ScrcpyWindowControl()
{
_viewModel = new ScrcpyViewModel();
_viewModel.ScrcpyStartRequested += ScrcpyStartRequested;
_viewModel.ScrcpyStopRequested += (s, e) => windowHost.CleanUp();
DataContext = _viewModel;

jtf = new JoinableTaskFactory(new JoinableTaskContext());
jtf = new JoinableTaskFactory(Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskContext);
_deviceWatcher = new DeviceWatcher();
async void deviceChangedHandler(object s, EventArgs e) => await DevicesChangedEventAsync();
_deviceWatcher.DeviceChanged += deviceChangedHandler;
Expand Down Expand Up @@ -120,7 +120,7 @@ protected virtual void Dispose(bool disposing)
}
}

~ScrcpyToolWindowControl()
~ScrcpyWindowControl()
{
Dispose(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@ namespace scrcpy.VisualStudio.UI
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideToolWindow(typeof(ScrcpyToolWindow))]
[Guid(ScrcpyToolWindowPackage.PackageGuidString)]
[ProvideToolWindow(typeof(ScrcpyWindow))]
[Guid(ScrcpyWindowPackage.PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
public sealed class ScrcpyToolWindowPackage : AsyncPackage
public sealed class ScrcpyWindowPackage : AsyncPackage
{
/// <summary>
/// ScrcpyToolWindowPackage GUID string.
/// ScrcpyWindowPackage GUID string.
/// </summary>
public const string PackageGuidString = "c672548b-255d-438c-91b9-b18acadfac63";
public const string PackageGuidString = "9e042473-074b-4938-a921-c3c1b8c6429d";

/// <summary>
/// Initializes a new instance of the <see cref="ScrcpyToolWindow"/> class.
/// Initializes a new instance of the <see cref="ScrcpyWindowPackage"/> class.
/// </summary>
public ScrcpyToolWindowPackage()
public ScrcpyWindowPackage()
{
// Inside this method you can place any initialization code that does not require
// any Visual Studio service because at this point the package object is created but
// not sited yet inside Visual Studio environment. The place to do all the other
// initialization is the Initialize method.
}
}

#region Package Members

Expand All @@ -70,7 +70,28 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
await ScrcpyToolWindowCommand.InitializeAsync(this);
await ScrcpyWindowCommand.InitializeAsync(this);
}

public override IVsAsyncToolWindowFactory GetAsyncToolWindowFactory(Guid toolWindowType)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (toolWindowType == typeof(ScrcpyWindow).GUID)
{
return this;
}

return base.GetAsyncToolWindowFactory(toolWindowType);
}

protected override string GetToolWindowTitle(Type toolWindowType, int id)
{
if (toolWindowType == typeof(ScrcpyWindow))
{
return "ScrcpyWindow loading";
}

return base.GetToolWindowTitle(toolWindowType, id);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!--The Commands section is where commands, menus, and menu groups are defined.
This section uses a Guid to identify the package that provides the command defined inside it. -->
<Commands package="guidScrcpyToolWindowPackage">
<Commands package="guidScrcpyWindowPackage">
<!-- Inside this section we have different sub-sections: one for the menus, another
for the menu groups, one for the buttons (the actual commands), one for the combos
and the last one for the bitmaps used. Each element is identified by a command id that
Expand All @@ -42,7 +42,7 @@
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
If you do not want an image next to your command, remove the Icon node /> -->
<Button guid="guidScrcpyToolWindowPackageCmdSet" id="ScrcpyToolWindowCommandId" priority="0x0100" type="Button">
<Button guid="guidScrcpyWindowPackageCmdSet" id="ScrcpyWindowCommandId" priority="0x0100" type="Button">
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1"/>
<Icon guid="guidImages" id="scrcpyCommand" />
<Strings>
Expand All @@ -64,11 +64,11 @@

<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="guidScrcpyToolWindowPackage" value="{c672548b-255d-438c-91b9-b18acadfac63}" />
<GuidSymbol name="guidScrcpyWindowPackage" value="{9e042473-074b-4938-a921-c3c1b8c6429d}" />

<!-- This is the guid used to group the menu commands together -->
<GuidSymbol name="guidScrcpyToolWindowPackageCmdSet" value="{94db034e-bda6-45cc-8f5a-3f278c8068d8}">
<IDSymbol name="ScrcpyToolWindowCommandId" value="0x0100" />
<GuidSymbol name="guidScrcpyWindowPackageCmdSet" value="{f72d56e5-b073-4fcc-9ae0-eb42776b3a3c}">
<IDSymbol name="ScrcpyWindowCommandId" value="0x0100" />
</GuidSymbol>

<GuidSymbol name="guidImages" value="{dde70bda-5cfb-4bfa-bfb9-887750e2e93f}" >
Expand Down
Loading

0 comments on commit 8e85161

Please sign in to comment.