diff --git a/src/Files.App/Data/Contracts/IStorageTrashBinService.cs b/src/Files.App/Data/Contracts/IStorageTrashBinService.cs
index 477d75f5348e..174c7408ea35 100644
--- a/src/Files.App/Data/Contracts/IStorageTrashBinService.cs
+++ b/src/Files.App/Data/Contracts/IStorageTrashBinService.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
namespace Files.App.Data.Contracts
@@ -63,5 +63,10 @@ public interface IStorageTrashBinService
///
/// True if succeeded; otherwise, false
Task RestoreAllTrashesAsync();
+
+ ///
+ /// Refreshes the desktop Recycle Bin icon to reflect the current bin state.
+ ///
+ void UpdateDesktopRecycleBinIcon();
}
}
diff --git a/src/Files.App/Services/Storage/StorageTrashBinService.cs b/src/Files.App/Services/Storage/StorageTrashBinService.cs
index cfbbc32e19b4..bdcae8e4ffe4 100644
--- a/src/Files.App/Services/Storage/StorageTrashBinService.cs
+++ b/src/Files.App/Services/Storage/StorageTrashBinService.cs
@@ -1,6 +1,7 @@
// Copyright (c) Files Community
// Licensed under the MIT License.
+using Microsoft.Extensions.Logging;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Principal;
@@ -106,6 +107,9 @@ public bool EmptyTrashBin()
0x00000001 | 0x00000002 /* SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI */)
.Succeeded;
+ if (fRes)
+ UpdateDesktopRecycleBinIcon();
+
return fRes;
}
@@ -163,10 +167,23 @@ private unsafe bool RestoreAllTrashesInternal()
// Perform
hr = pFileOperation.Get()->PerformOperations();
- // Reset the icon
- PInvoke.SHUpdateRecycleBinIcon();
+ if (hr == HRESULT.S_OK)
+ UpdateDesktopRecycleBinIcon();
+
+ return hr == HRESULT.S_OK;
+ }
- return true;
+ ///
+ public void UpdateDesktopRecycleBinIcon()
+ {
+ try
+ {
+ PInvoke.SHUpdateRecycleBinIcon();
+ }
+ catch (Exception ex)
+ {
+ App.Logger?.LogWarning(ex, "Failed to update the Recycle Bin desktop icon.");
+ }
}
}
}
diff --git a/src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs b/src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs
index 72e49351393d..c96e82203533 100644
--- a/src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs
+++ b/src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs
@@ -550,6 +550,8 @@ await _associatedInstance.ShellViewModel.GetFileFromPathAsync(iFilePath, cancell
if (!permanently)
{
+ StorageTrashBinService.UpdateDesktopRecycleBinIcon();
+
// Enumerate Recycle Bin
IEnumerable nameMatchItems, items = await StorageTrashBinService.GetAllRecycleBinFoldersAsync();
@@ -565,6 +567,9 @@ await _associatedInstance.ShellViewModel.GetFileFromPathAsync(iFilePath, cancell
return new StorageHistory(FileOperationType.Recycle, source, StorageHelpers.FromPathAndType(item?.RecyclePath, source.ItemType));
}
+ if (deleteFromRecycleBin)
+ StorageTrashBinService.UpdateDesktopRecycleBinIcon();
+
return new StorageHistory(FileOperationType.Delete, source, null);
}
else
@@ -784,6 +789,8 @@ public async Task RestoreFromTrashAsync(IStorageItemWithPath so
await _associatedInstance.ShellViewModel.GetFileFromPathAsync(iFilePath, cancellationToken)
.OnSuccess(iFile => iFile.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask());
+
+ StorageTrashBinService.UpdateDesktopRecycleBinIcon();
}
fsProgress.ReportStatus(fsResult);
diff --git a/src/Files.App/Utils/Storage/Operations/ShellFilesystemOperations.cs b/src/Files.App/Utils/Storage/Operations/ShellFilesystemOperations.cs
index c89155f375e3..1ce4392e3a95 100644
--- a/src/Files.App/Utils/Storage/Operations/ShellFilesystemOperations.cs
+++ b/src/Files.App/Utils/Storage/Operations/ShellFilesystemOperations.cs
@@ -393,6 +393,8 @@ public async Task DeleteItemsAsync(IList
var recycledSources = deleteResult.Items.Where(x => x.Succeeded && x.Destination is not null && x.Source != x.Destination);
if (recycledSources.Any())
{
+ StorageTrashBinService.UpdateDesktopRecycleBinIcon();
+
var sourceMatch = await recycledSources.Select(x => source.DistinctBy(x => x.Path)
.SingleOrDefault(s => s.Path.Equals(x.Source, StringComparison.OrdinalIgnoreCase))).Where(x => x is not null).ToListAsync();
@@ -403,6 +405,9 @@ public async Task DeleteItemsAsync(IList
.Select(item => StorageHelpers.FromPathAndType(item.rSrc.Destination, item.oSrc.ItemType)).ToListAsync());
}
+ if (deleteFromRecycleBin)
+ StorageTrashBinService.UpdateDesktopRecycleBinIcon();
+
return new StorageHistory(FileOperationType.Delete, source, null);
}
else
@@ -781,6 +786,8 @@ public async Task RestoreItemsFromTrashAsync(IList new { rSrc, oSrc })