Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Files.App/Data/Contracts/IStorageTrashBinService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Files Community
// Copyright (c) Files Community
// Licensed under the MIT License.

namespace Files.App.Data.Contracts
Expand Down Expand Up @@ -63,5 +63,10 @@ public interface IStorageTrashBinService
/// </summary>
/// <returns>True if succeeded; otherwise, false</returns>
Task<bool> RestoreAllTrashesAsync();

/// <summary>
/// Refreshes the desktop Recycle Bin icon to reflect the current bin state.
/// </summary>
void UpdateDesktopRecycleBinIcon();
}
}
23 changes: 20 additions & 3 deletions src/Files.App/Services/Storage/StorageTrashBinService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -106,6 +107,9 @@ public bool EmptyTrashBin()
0x00000001 | 0x00000002 /* SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI */)
.Succeeded;

if (fRes)
UpdateDesktopRecycleBinIcon();

return fRes;
}

Expand Down Expand Up @@ -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;
/// <inheritdoc/>
public void UpdateDesktopRecycleBinIcon()
{
try
{
PInvoke.SHUpdateRecycleBinIcon();
}
catch (Exception ex)
{
App.Logger?.LogWarning(ex, "Failed to update the Recycle Bin desktop icon.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ await _associatedInstance.ShellViewModel.GetFileFromPathAsync(iFilePath, cancell

if (!permanently)
{
StorageTrashBinService.UpdateDesktopRecycleBinIcon();

// Enumerate Recycle Bin
IEnumerable<ShellFileItem> nameMatchItems, items = await StorageTrashBinService.GetAllRecycleBinFoldersAsync();

Expand All @@ -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
Expand Down Expand Up @@ -784,6 +789,8 @@ public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath so

await _associatedInstance.ShellViewModel.GetFileFromPathAsync(iFilePath, cancellationToken)
.OnSuccess(iFile => iFile.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask());

StorageTrashBinService.UpdateDesktopRecycleBinIcon();
}

fsProgress.ReportStatus(fsResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
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();

Expand All @@ -403,6 +405,9 @@ public async Task<IStorageHistory> DeleteItemsAsync(IList<IStorageItemWithPath>
.Select(item => StorageHelpers.FromPathAndType(item.rSrc.Destination, item.oSrc.ItemType)).ToListAsync());
}

if (deleteFromRecycleBin)
StorageTrashBinService.UpdateDesktopRecycleBinIcon();

return new StorageHistory(FileOperationType.Delete, source, null);
}
else
Expand Down Expand Up @@ -781,6 +786,8 @@ public async Task<IStorageHistory> RestoreItemsFromTrashAsync(IList<IStorageItem
Path.Combine(Path.GetDirectoryName(src.rSrc.Source), Path.GetFileName(src.rSrc.Source).Replace("$R", "$I", StringComparison.Ordinal)),
src.oSrc.ItemType)).ToListAsync(), null, true, cancellationToken);

StorageTrashBinService.UpdateDesktopRecycleBinIcon();

return new StorageHistory(FileOperationType.Restore,
sourceMatch,
await movedSources.Zip(sourceMatch, (rSrc, oSrc) => new { rSrc, oSrc })
Expand Down