Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Aug 2, 2023
1 parent 9ae5187 commit 5fd51d7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/DiffEngineTray/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Global using directives

global using Microsoft.Win32;
1 change: 1 addition & 0 deletions src/DiffEngineTray/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static async Task Inner()

icon.ContextMenuStrip = menuStrip;

TrayIcon.Promoted();
Application.Run();
tokenSource.Cancel();
await task;
Expand Down
4 changes: 1 addition & 3 deletions src/DiffEngineTray/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.Win32;

public class Startup
public class Startup
{
public static void Add()
{
Expand Down
36 changes: 36 additions & 0 deletions src/DiffEngineTray/TrayIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
public static class TrayIcon
{
public static void Promoted()
{
//C:\Users\SimonCropp\.dotnet\tools\DiffEngineTray.exe
var profileDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var exePath = Path.Combine(profileDirectory, @"dotnet\tools\DiffEngineTray.exe");
using var iconSettingsKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\NotifyIconSettings");
if (iconSettingsKey == null)
{
DiffEngine.Logging.Write(@"NotifyIconSettings reg path returned null. Path: Control Panel\NotifyIconSettings");
return;
}

foreach (var subKeyName in iconSettingsKey.GetSubKeyNames())
{
using var iconKey = iconSettingsKey.OpenSubKey(subKeyName, true);
if (iconKey == null)
{
continue;
}

var valueNames = iconKey.GetValueNames();
if (!valueNames.Contains("ExecutablePath") ||
!string.Equals((string?) iconKey.GetValue("ExecutablePath"), exePath, StringComparison.OrdinalIgnoreCase))
{
continue;
}

iconKey.SetValue("IsPromoted", 1, RegistryValueKind.DWord);
return;
}

DiffEngine.Logging.Write(@"DiffEngineTray.exe not found in NotifyIconSettings. Path: Control Panel\NotifyIconSettings");
}
}

0 comments on commit 5fd51d7

Please sign in to comment.