Skip to content

Commit 10c16aa

Browse files
committed
Improve render quality of tray icon on monitors with scale=125%
1 parent 7f52619 commit 10c16aa

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

src/UniGetUI.Core.IconStore/IconCacheEngine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
extern alias DrawingCommon;
12
using System.Collections.ObjectModel;
23
using System.Security.Cryptography;
34
using PhotoSauce.MagicScaler;
@@ -238,7 +239,7 @@ private static void DownsizeImage(string cachedIconFile, string extension)
238239
int width, height;
239240

240241
using (var fileStream = new FileStream(cachedIconFile, FileMode.Open, FileAccess.Read, FileShare.Read))
241-
using (var image = System.Drawing.Image.FromStream(fileStream, false, false))
242+
using (var image = DrawingCommon.System.Drawing.Image.FromStream(fileStream, false, false))
242243
{
243244
height = image.Height;
244245
width = image.Width;

src/UniGetUI.Core.IconStore/UniGetUI.Core.IconEngine.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<ItemGroup>
2626
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
27-
<PackageReference Include="System.Drawing.Common" Version="9.0.3" />
27+
<PackageReference Include="System.Drawing.Common" Version="9.0.3" Aliases="DrawingCommon"/>
28+
2829
</ItemGroup>
2930
</Project>

src/UniGetUI/AppOperationHelper.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.ObjectModel;
2+
using System.ComponentModel;
23
using Windows.Storage;
34
using Windows.Storage.Pickers;
45
using Microsoft.UI.Xaml.Controls;
@@ -99,6 +100,7 @@ public static void Remove(AbstractOperation op)
99100
op.OperationSucceeded += (_, _) => TelemetryHandler.DownloadPackage(package, TEL_OP_RESULT.SUCCESS, referral);
100101
op.OperationFailed += (_, _) => TelemetryHandler.DownloadPackage(package, TEL_OP_RESULT.FAILED, referral);
101102
Add(op);
103+
Instance.MainWindow.UpdateSystemTrayStatus();
102104
return op;
103105
}
104106

@@ -123,9 +125,10 @@ public static void Remove(AbstractOperation op)
123125

124126
var options = await InstallationOptions.FromPackageAsync(package, elevated, interactive, no_integrity);
125127
var op = new InstallPackageOperation(package, options, ignoreParallel, req);
126-
Add(op);
127128
op.OperationSucceeded += (_, _) => TelemetryHandler.InstallPackage(package, TEL_OP_RESULT.SUCCESS, referral);
128129
op.OperationFailed += (_, _) => TelemetryHandler.InstallPackage(package, TEL_OP_RESULT.FAILED, referral);
130+
Add(op);
131+
Instance.MainWindow.UpdateSystemTrayStatus();
129132
return op;
130133
}
131134

@@ -146,9 +149,10 @@ public static void Install(IReadOnlyList<IPackage> packages, TEL_InstallReferral
146149

147150
var options = await InstallationOptions.FromPackageAsync(package, elevated, interactive, no_integrity);
148151
var op = new UpdatePackageOperation(package, options, ignoreParallel, req);
149-
Add(op);
150152
op.OperationSucceeded += (_, _) => TelemetryHandler.UpdatePackage(package, TEL_OP_RESULT.SUCCESS);
151153
op.OperationFailed += (_, _) => TelemetryHandler.UpdatePackage(package, TEL_OP_RESULT.FAILED);
154+
Add(op);
155+
Instance.MainWindow.UpdateSystemTrayStatus();
152156
return op;
153157
}
154158

@@ -186,9 +190,10 @@ public static async void ConfirmAndUninstall(IPackage? package, bool? elevated =
186190

187191
var options = await InstallationOptions.FromPackageAsync(package, elevated, interactive, remove_data: remove_data);
188192
var op = new UninstallPackageOperation(package, options, ignoreParallel, req);
189-
Add(op);
190193
op.OperationSucceeded += (_, _) => TelemetryHandler.UninstallPackage(package, TEL_OP_RESULT.SUCCESS);
191194
op.OperationFailed += (_, _) => TelemetryHandler.UninstallPackage(package, TEL_OP_RESULT.FAILED);
195+
Add(op);
196+
Instance.MainWindow.UpdateSystemTrayStatus();
192197
return op;
193198
}
194199

src/UniGetUI/Controls/OperationWidgets/OperationControl.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ namespace UniGetUI.Controls.OperationWidgets;
2727
public class OperationControl: INotifyPropertyChanged
2828
{
2929
public AbstractOperation Operation;
30-
private bool ErrorTooltipShown;
3130
public BetterMenu OpMenu;
3231
public OperationStatus? MenuStateOnLoaded;
3332
public ObservableCollection<OperationBadge> Badges = [];
33+
private int _errorCount = 0;
3434

3535
public OperationControl(AbstractOperation operation)
3636
{
@@ -123,6 +123,18 @@ private async void OnOperationFinished(object? sender, EventArgs e)
123123
// Remove progress notification (if any)
124124
AppNotificationManager.Default.RemoveByTagAsync(Operation.Metadata.Identifier + "progress");
125125

126+
if (Operation.Status is OperationStatus.Failed)
127+
{
128+
_errorCount++;
129+
MainApp.Tooltip.ErrorsOccurred++;
130+
}
131+
else
132+
{
133+
MainApp.Tooltip.ErrorsOccurred -= _errorCount;
134+
_errorCount = 0;
135+
}
136+
MainApp.Instance.MainWindow.UpdateSystemTrayStatus();
137+
126138
// Generate process output
127139
List<string> rawOutput =
128140
[
@@ -208,18 +220,6 @@ private void OnOperationStatusChanged(object? sender, OperationStatus newStatus)
208220
default:
209221
throw new ArgumentOutOfRangeException(nameof(newStatus), newStatus, null);
210222
}
211-
212-
// Handle error tooltip counter
213-
if (!ErrorTooltipShown && newStatus is OperationStatus.Failed)
214-
{
215-
MainApp.Tooltip.ErrorsOccurred++;
216-
ErrorTooltipShown = true;
217-
}
218-
else if (ErrorTooltipShown && newStatus is not OperationStatus.Failed)
219-
{
220-
MainApp.Tooltip.ErrorsOccurred--;
221-
ErrorTooltipShown = false;
222-
}
223223
}
224224

225225
public async Task LiveLineClick()
@@ -321,11 +321,9 @@ private async Task TimeoutAndClose()
321321

322322
public void Close()
323323
{
324-
if (ErrorTooltipShown && Operation.Status is OperationStatus.Failed)
325-
{
326-
MainApp.Tooltip.ErrorsOccurred--;
327-
ErrorTooltipShown = false;
328-
}
324+
MainApp.Tooltip.ErrorsOccurred -= _errorCount;
325+
_errorCount = 0;
326+
MainApp.Instance.MainWindow.UpdateSystemTrayStatus();
329327

330328
MainApp.Operations._operationList.Remove(this);
331329
while(AbstractOperation.OperationQueue.Remove(Operation));

src/UniGetUI/MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
extern alias DrawingCommon;
12
using System.Runtime.InteropServices;
23
using System.Text.RegularExpressions;
34
using System.Web;
@@ -7,7 +8,6 @@
78
using Microsoft.UI.Xaml;
89
using Microsoft.UI.Xaml.Controls;
910
using Microsoft.UI.Xaml.Input;
10-
using Microsoft.UI.Xaml.Media.Imaging;
1111
using Microsoft.Win32;
1212
using UniGetUI.Core.Data;
1313
using UniGetUI.Core.Logging;
@@ -626,7 +626,7 @@ public void UpdateSystemTrayStatus()
626626
LastTrayIcon = FullIconPath;
627627
if (File.Exists(FullIconPath))
628628
{
629-
TrayIcon.SetValue(TaskbarIcon.IconSourceProperty, new BitmapImage { UriSource = new Uri(FullIconPath) });
629+
TrayIcon.Icon = new DrawingCommon.System.Drawing.Icon(FullIconPath, 32, 32);
630630
}
631631
}
632632

src/UniGetUI/UniGetUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
8888
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
8989
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.15.0" />
90+
<PackageReference Include="System.Drawing.Common" Version="9.0.3" Aliases="DrawingCommon"/>
9091
<PackageReference Include="System.Net.Http" Version="4.3.4" />
9192
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
9293
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />

0 commit comments

Comments
 (0)