Skip to content

Commit 5781671

Browse files
authored
Merge origin/main to resolve PR conflicts
2 parents d2a7ce7 + 6c4dd33 commit 5781671

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

pscommander/Services/ConfigService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public async Task LoadAsync()
8989
var configPath = Path.Combine(GetFolder(), "config.ps1");
9090
if (!File.Exists(configPath))
9191
{
92+
_menuService.UpdateToolbar(Configuration.ToolbarIcon);
9293
return;
9394
}
9495

@@ -167,4 +168,4 @@ public static void Debounce(Func<Task> action, int milliseconds = 1000)
167168
Task.Delay(milliseconds).ContinueWith(async task => { await action(); }, tokenSrc.Token);
168169
}
169170
}
170-
}
171+
}

pscommander/Services/MenuService.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System.Windows.Controls;
22
using WPFMenuItem = System.Windows.Controls.MenuItem;
33
using Hardcodet.Wpf.TaskbarNotification;
4-
using System.Windows.Media;
5-
using System.Windows.Media.Imaging;
64
using System;
75
using System.Management.Automation;
86
using System.IO;
97
using System.Drawing;
8+
using System.Windows;
109

1110
namespace pscommander
1211
{
@@ -38,7 +37,7 @@ public void UpdateToolbar(ToolbarIcon icon)
3837

3938
if (string.IsNullOrWhiteSpace(icon.Icon))
4039
{
41-
_taskbarIcon.IconSource = new BitmapImage(new Uri("pack://application:,,,/pscommander;component/Resources/icon.ico"));
40+
_taskbarIcon.Icon = LoadDefaultIcon();
4241
}
4342
else
4443
{
@@ -119,6 +118,17 @@ private static string EscapePowerShellSingleQuotedString(string value)
119118
return value.Replace("'", "''");
120119
}
121120

121+
private static Icon LoadDefaultIcon()
122+
{
123+
var resourceInfo = Application.GetResourceStream(new Uri("pack://application:,,,/Resources/icon.ico"));
124+
if (resourceInfo == null)
125+
{
126+
throw new FileNotFoundException("The default tray icon resource could not be found.", "Resources/icon.ico");
127+
}
128+
using var icon = new Icon(resourceInfo.Stream);
129+
return (Icon)icon.Clone();
130+
}
131+
122132
private void AddMenuItem(ItemCollection items, MenuItem item)
123133
{
124134
var wpfMenuItem = new WPFMenuItem();

0 commit comments

Comments
 (0)