Skip to content

Commit 7cf319b

Browse files
committed
1.14.0.0
1 parent 890772b commit 7cf319b

25 files changed

+221
-94
lines changed
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
using System;
22
using System.Collections.Generic;
3+
using WorkspaceLauncherForVSCode.Enums;
34

45
namespace WorkspaceLauncherForVSCode.Classes;
6+
57
public class CountTracker
68
{
79
private readonly Dictionary<CountType, int> _counts = new();
8-
9-
public event EventHandler<CountType>? CountChanged;
10-
10+
private readonly Dictionary<VisualStudioCodeRemoteType, int> _vscodeRemoteCounts = new();
11+
private readonly Dictionary<WorkspaceType, int> _vscodeLocalCounts = new();
1112
public int this[CountType type] => _counts.TryGetValue(type, out var count) ? count : 0;
13+
public int this[VisualStudioCodeRemoteType remoteType] => _vscodeRemoteCounts.TryGetValue(remoteType, out var count) ? count : 0;
14+
public int this[WorkspaceType localType] => _vscodeLocalCounts.TryGetValue(localType, out var count) ? count : 0;
1215

1316
public void Update(CountType type, int value)
1417
{
1518
if (!_counts.TryGetValue(type, out var oldValue) || oldValue != value)
1619
{
1720
_counts[type] = value;
18-
CountChanged?.Invoke(this, type);
21+
}
22+
}
23+
24+
public void Update(VisualStudioCodeRemoteType remoteType, int value)
25+
{
26+
if (!_vscodeRemoteCounts.TryGetValue(remoteType, out var oldValue) || oldValue != value)
27+
{
28+
_vscodeRemoteCounts[remoteType] = value;
29+
}
30+
}
31+
32+
public void Update(WorkspaceType localType, int value)
33+
{
34+
if (!_vscodeLocalCounts.TryGetValue(localType, out var oldValue) || oldValue != value)
35+
{
36+
_vscodeLocalCounts[localType] = value;
1937
}
2038
}
2139
}

WorkspaceLauncherForVSCode/Classes/CountType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
namespace WorkspaceLauncherForVSCode.Classes;
2+
23
public enum CountType
34
{
45
Total,

WorkspaceLauncherForVSCode/Classes/VisualStudioCodeRemoteUri.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System;
2+
using System.Net;
23
using System.Text;
34
using System.Text.Json;
4-
using System.Net;
55
using WorkspaceLauncherForVSCode.Enums;
66
using WorkspaceLauncherForVSCode.Helpers;
7-
using ABI.System;
87

98
namespace WorkspaceLauncherForVSCode.Classes;
109

@@ -13,7 +12,7 @@ public class VisualStudioCodeRemoteUri
1312
public const string Scheme = Constant.VscodeRemoteScheme;
1413
public string Uri { get; }
1514
public string TypeStr { get; }
16-
public VisualStudioCodeRemoteType? Type { get; }
15+
public VisualStudioCodeRemoteType? Type { get; }
1716
public string InfoRaw { get; }
1817
public string InfoDecoded { get; }
1918
public JsonElement? InfoJson { get; }
@@ -38,7 +37,7 @@ public VisualStudioCodeRemoteUri(string uri)
3837
var path = firstSlash == -1 ? "/" : withoutScheme.Substring(firstSlash);
3938

4039
// Handle encoded `+` (for codespaces)
41-
string remoteType = null, remoteInfoRaw = null;
40+
string remoteType = string.Empty, remoteInfoRaw = string.Empty;
4241

4342
if (beforePath.Contains('+'))
4443
{

WorkspaceLauncherForVSCode/Classes/VisualStudioCodeWorkspace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void SetVSCodeMetadata()
137137
/// Gets the details of the workspace.
138138
/// </summary>
139139
/// <returns>An array of details elements containing information about the workspace.</returns>
140-
public void SetVSMetadata()
140+
public static void SetVSMetadata()
141141
{
142142
}
143143
}

WorkspaceLauncherForVSCode/Classes/VisualStudioCodeWorkspaceSerializerContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System.Collections.Generic;
22
using System.Text.Json.Serialization;
3+
using WorkspaceLauncherForVSCode.Services.VisualStudio.Models;
34

45
namespace WorkspaceLauncherForVSCode.Classes
56
{
67
[JsonSerializable(typeof(List<VisualStudioCodeWorkspace>))]
8+
[JsonSerializable(typeof(VisualStudioCodeInstance), TypeInfoPropertyName = "VSCodeInstance")]
9+
[JsonSerializable(typeof(VisualStudioInstance), TypeInfoPropertyName = "VSInstance")]
710
internal sealed partial class VisualStudioCodeWorkspaceSerializerContext : JsonSerializerContext
811
{
912
}

WorkspaceLauncherForVSCode/Commands/OpenSolutionCommand.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public override CommandResult Invoke()
5050
return CommandResult.Dismiss();
5151
}
5252

53+
if (page != null)
54+
{
55+
Task.Run(() => page.UpdateFrequencyAsync(Workspace.Path));
56+
}
57+
5358
OpenWindows.Instance.UpdateVisualStudioWindowsList();
5459
var visualStudioWindows = OpenWindows.Instance.Windows;
5560
var matchedElevatedVisualStudioWindows = new List<Window>();
@@ -65,6 +70,10 @@ public override CommandResult Invoke()
6570
}
6671
else
6772
{
73+
if (window.Process.Process == null)
74+
{
75+
continue;
76+
}
6877
string? commandLine = NativeProcessCommandLine.GetCommandLine(window.Process.Process);
6978
string? solutionPath = NativeProcessCommandLine.ExtractSolutionPath(commandLine);
7079
if (solutionPath == Workspace.WindowsPath)
@@ -77,22 +86,17 @@ public override CommandResult Invoke()
7786

7887
//if (matchedElevatedVisualStudioWindows.Count > 0)
7988
//{
80-
// TODO: Waiting on https://github.com/microsoft/PowerToys/pull/38025 for GotoPage support.
81-
// Since we can't retrieve the command line from elevated processes, we can't determine their solution path.
82-
// If any elevated Visual Studio windows have a title that contains the solution name,
83-
// consider navigating to a selection page to let the user choose which window to switch to or reopen the solution.
89+
// TODO: Waiting on https://github.com/microsoft/PowerToys/pull/38025 for GotoPage support.
90+
// Since we can't retrieve the command line from elevated processes, we can't determine their solution path.
91+
// If any elevated Visual Studio windows have a title that contains the solution name,
92+
// consider navigating to a selection page to let the user choose which window to switch to or reopen the solution.
8493
//}
8594

8695
if (Workspace.VSInstance != null)
8796
{
8897
OpenInShellHelper.OpenInShell(Workspace.VSInstance.InstancePath, Workspace.Path, runAs: _elevated ? OpenInShellHelper.ShellRunAsType.Administrator : OpenInShellHelper.ShellRunAsType.None);
8998
}
9099

91-
if (page != null)
92-
{
93-
Task.Run(() => page.UpdateFrequencyAsync(Workspace.Path));
94-
}
95-
96100
return PageCommandResultHandler.HandleCommandResult(page);
97101
}
98102
}

WorkspaceLauncherForVSCode/Commands/SwitchWindowCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace WorkspaceLauncherForVSCode.Commands;
1616

17-
internal partial class SwitchWindowCommand : InvokableCommand
17+
internal sealed partial class SwitchWindowCommand : InvokableCommand
1818
{
1919
private readonly Window _window;
2020

WorkspaceLauncherForVSCode/Components/OpenWindows.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ private bool VisualStudioWindowEnumerationCallBack(IntPtr hwnd, IntPtr lParam)
4747
newWindow.ClassName != "Windows.UI.Core.CoreWindow" &&
4848
!newWindow.IsCloaked)
4949
{
50-
if (string.Equals(newWindow.Process?.Process.ProcessName, "devenv", StringComparison.OrdinalIgnoreCase))
50+
if (newWindow.Process?.Process != null && string.Equals(newWindow.Process.Process.ProcessName, "devenv", StringComparison.OrdinalIgnoreCase))
5151
{
52-
if (newWindow.Process?.Process is Process proc && IsProcessElevated(proc.Id))
52+
if (newWindow.Process.Process is Process proc && IsProcessElevated(proc.Id))
5353
{
5454
newWindow.IsProcessElevated = true;
5555
}
@@ -60,7 +60,7 @@ private bool VisualStudioWindowEnumerationCallBack(IntPtr hwnd, IntPtr lParam)
6060
return true;
6161
}
6262

63-
private bool IsProcessElevated(int processId)
63+
private static bool IsProcessElevated(int processId)
6464
{
6565
IntPtr hProcess = NativeMethods.OpenProcess(0x1000 /* PROCESS_QUERY_INFORMATION */, false, processId);
6666
if (hProcess == IntPtr.Zero)
@@ -72,7 +72,7 @@ private bool IsProcessElevated(int processId)
7272
if (!NativeMethods.OpenProcessToken(hProcess, 0x0008 /* TOKEN_QUERY */, out hToken))
7373
return false;
7474

75-
uint tokenInfoLength = (uint)Marshal.SizeOf(typeof(int));
75+
uint tokenInfoLength = (uint)Marshal.SizeOf<int>();
7676
IntPtr elevationPtr = Marshal.AllocHGlobal((int)tokenInfoLength);
7777
try
7878
{

WorkspaceLauncherForVSCode/Components/Window.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ internal void SwitchToWindow()
7272

7373
public override string ToString()
7474
{
75-
return Title + " (" + processInfo.Process.ProcessName?.ToUpper(CultureInfo.CurrentCulture) + ")";
75+
var processName = processInfo.Process?.ProcessName?.ToUpper(CultureInfo.CurrentCulture) ?? "N/A";
76+
return Title + " (" + processName + ")";
7677
}
7778

7879
internal WindowSizeState GetWindowSizeState()

WorkspaceLauncherForVSCode/Components/WindowProcess.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ namespace WorkspaceLauncherForVSCode.Components
99
{
1010
internal sealed class WindowProcess
1111
{
12-
private uint processId;
12+
private readonly uint processId;
1313
private readonly Process? process;
1414
internal uint ProcessId => processId;
1515
internal Process? Process => process;
1616
internal WindowProcess(IntPtr hwnd)
1717
{
18-
_ = NativeMethods.GetWindowThreadProcessId(hwnd, out var processId);
18+
_ = NativeMethods.GetWindowThreadProcessId(hwnd, out var pid);
19+
processId = pid;
1920
process = Process.GetProcessById((int)processId);
2021
}
2122
}

0 commit comments

Comments
 (0)