Skip to content

Commit

Permalink
Releasing adb on close
Browse files Browse the repository at this point in the history
  • Loading branch information
PawKanarek committed Feb 26, 2020
1 parent 7c99144 commit 158a216
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
25 changes: 14 additions & 11 deletions src/LogcatOutputVsix/LogcatOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

namespace LogcatOutput
{
/// <summary>
/// Command handler
/// </summary>
internal sealed class LogcatOutput
{
public const int CommandId = 0x0100;
Expand Down Expand Up @@ -71,36 +68,42 @@ private async void Execute(object sender, EventArgs e)
this.pane.Clear();
this.pane.OutputString("State: ADB Active\n");
this.state = State.Active;

this.ReleaseAdbProcess();
this.adb = new Adb();
this.adb.LogReceived += this.Adb_LogReceived;

break;
case State.Active:

this.adb.FilterName = "DevLogger";

this.pane.Clear();
this.pane.OutputString("State: ADB Active with Filter: 'DevLogger'\n");

this.state = State.ActiveWithFilter;

break;
case State.ActiveWithFilter:

this.adb.LogReceived -= this.Adb_LogReceived;
this.adb.Dispose();
this.adb = null;

this.ReleaseAdbProcess();
this.pane.Clear();
this.pane.OutputString("State: ADB Disabled \n");

this.state = State.Disabled;

break;
}
}

public void ReleaseAdbProcess()
{
if (this.adb == null)
{
return;
}

this.adb.LogReceived -= this.Adb_LogReceived;
this.adb.Dispose();
this.adb = null;
}

private async void Adb_LogReceived(object sender, string e)
{
if (this.outputWindow == null)
Expand Down
14 changes: 6 additions & 8 deletions src/LogcatOutputVsix/LogcatOutputPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@ namespace LogcatOutput
[ProvideMenuResource("Menus.ctmenu", 1)]
public sealed class LogcatOutputPackage : AsyncPackage
{
/// <summary>
/// LogcatOutputPackage GUID string.
/// </summary>
public const string PackageGuidString = "03e93c02-9cf9-4aed-a603-aba4d9210d5a";

#region Package Members

/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
Expand All @@ -44,11 +39,14 @@ public sealed class LogcatOutputPackage : AsyncPackage
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// 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 LogcatOutput.InitializeAsync(this);
}
#endregion

protected override int QueryClose(out bool canClose)
{
LogcatOutput.Instance.ReleaseAdbProcess();
return base.QueryClose(out canClose);
}
}
}
35 changes: 18 additions & 17 deletions src/LogcatOutputVsix/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="LogcatOutput.d173c13d-febd-4891-b4fc-8ee02cdfa77e" Version="1.0" Language="en-US" Publisher="paw.kanarek" />
<DisplayName>LogcatOutput</DisplayName>
<Description>Empty VSIX Project.</Description>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[16.0, 17.0)" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.0,17.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
<Metadata>
<Identity Id="LogcatOutput.d173c13d-febd-4891-b4fc-8ee02cdfa77e" Version="1.0" Language="en-US" Publisher="paw.kanarek" />
<DisplayName>LogcatOutput</DisplayName>
<Description xml:space="preserve">Helps with debugging Xamarin. Usage: Toggle Tools: -&gt; LogcatOutput</Description>
<Preview>true</Preview>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[16.0, 17.0)" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.0,17.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
</PackageManifest>

0 comments on commit 158a216

Please sign in to comment.