Skip to content

Commit f9617b8

Browse files
authored
Servicing v2.4.69 (#12206)
1 parent e657db5 commit f9617b8

33 files changed

+137
-82
lines changed

src/Files.App (Package)/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
1111
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
1212
IgnorableNamespaces="uap uap5 mp rescap desktop6 desktop4 desktop">
13-
<Identity Name="FilesDev" Publisher="CN=Files" Version="2.4.68.0" />
13+
<Identity Name="FilesDev" Publisher="CN=Files" Version="2.4.69.0" />
1414
<Properties>
1515
<DisplayName>Files - Dev</DisplayName>
1616
<PublisherDisplayName>Yair A</PublisherDisplayName>

src/Files.App/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void OnActivated(AppActivationArguments activatedEventArgs)
268268
var data = activatedEventArgs.Data;
269269

270270
// InitializeApplication accesses UI, needs to be called on UI thread
271-
_ = Window.DispatcherQueue.EnqueueAsync(() => Window.InitializeApplication(data));
271+
_ = Window.DispatcherQueue.EnqueueOrInvokeAsync(() => Window.InitializeApplication(data));
272272
}
273273

274274
/// <summary>
@@ -473,7 +473,7 @@ private static void AppUnhandledException(Exception ex, bool shouldShowNotificat
473473
userSettingsService.AppSettingsService.RestoreTabsOnStartup = true;
474474
userSettingsService.GeneralSettingsService.LastCrashedTabList = lastSessionTabList;
475475

476-
Window.DispatcherQueue.EnqueueAsync(async () =>
476+
Window.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
477477
{
478478
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
479479
}).Wait(1000);

src/Files.App/BaseLayout.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ internal set
241241
if (selectedItems.Count == 1)
242242
{
243243
SelectedItemsPropertiesViewModel.SelectedItemsCountString = $"{selectedItems.Count} {"ItemSelected/Text".GetLocalizedResource()}";
244-
DispatcherQueue.EnqueueAsync(async () =>
244+
DispatcherQueue.EnqueueOrInvokeAsync(async () =>
245245
{
246246
// Tapped event must be executed first
247247
await Task.Delay(50);
@@ -1339,7 +1339,7 @@ protected async Task ValidateItemNameInputText(TextBox textBox, TextBoxBeforeTex
13391339
{
13401340
args.Cancel = true;
13411341

1342-
await DispatcherQueue.EnqueueAsync(() =>
1342+
await DispatcherQueue.EnqueueOrInvokeAsync(() =>
13431343
{
13441344
var oldSelection = textBox.SelectionStart + textBox.SelectionLength;
13451345
var oldText = textBox.Text;

src/Files.App/DataModels/NavigationControlItems/DriveItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
178178
item.DeviceID = deviceId;
179179
item.Root = root;
180180

181-
_ = App.Window.DispatcherQueue.EnqueueAsync(() => item.UpdatePropertiesAsync());
181+
_ = App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => item.UpdatePropertiesAsync());
182182

183183
return item;
184184
}

src/Files.App/DataModels/NavigationControlItems/LocationItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public ulong SpaceUsed
9292
{
9393
SetProperty(ref spaceUsed, value);
9494

95-
App.Window.DispatcherQueue.EnqueueAsync(() => OnPropertyChanged(nameof(ToolTipText)));
95+
App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => OnPropertyChanged(nameof(ToolTipText)));
9696
}
9797
}
9898

src/Files.App/DataModels/SidebarPinnedModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
107107
{
108108
var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 96u, ThumbnailMode.ListView);
109109
locationItem.IconData = iconData;
110-
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync());
110+
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => locationItem.IconData.ToBitmapAsync());
111111
}
112112

113113
if (locationItem.IconData is null)
114114
{
115115
locationItem.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(path, 96u);
116116

117117
if (locationItem.IconData is not null)
118-
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync());
118+
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => locationItem.IconData.ToBitmapAsync());
119119
}
120120
}
121121
else
122122
{
123-
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetSidebarIconResource(Constants.ImageRes.Folder));
123+
locationItem.Icon = await App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => UIHelpers.GetSidebarIconResource(Constants.ImageRes.Folder));
124124
locationItem.IsInvalid = true;
125125
Debug.WriteLine($"Pinned item was invalid {res.ErrorCode}, item: {path}");
126126
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using CommunityToolkit.WinUI;
2+
using Microsoft.UI.Dispatching;
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
namespace Files.App.Extensions
7+
{
8+
// Window.DispatcherQueue seems to be null sometimes.
9+
// We don't know why, but as a workaround, we invoke the function directly if DispatcherQueue is null.
10+
public static class DispatcherQueueExtensions
11+
{
12+
public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Func<Task> function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal)
13+
{
14+
if (dispatcher is not null)
15+
return dispatcher.EnqueueAsync(function, priority);
16+
else
17+
return function();
18+
}
19+
20+
public static Task<T> EnqueueOrInvokeAsync<T>(this DispatcherQueue? dispatcher, Func<Task<T>> function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal)
21+
{
22+
if (dispatcher is not null)
23+
return dispatcher.EnqueueAsync(function, priority);
24+
else
25+
return function();
26+
}
27+
28+
public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Action function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal)
29+
{
30+
if (dispatcher is not null)
31+
return dispatcher.EnqueueAsync(function, priority);
32+
else
33+
{
34+
function();
35+
return Task.CompletedTask;
36+
}
37+
}
38+
39+
public static Task<T> EnqueueOrInvokeAsync<T>(this DispatcherQueue? dispatcher, Func<T> function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal)
40+
{
41+
if (dispatcher is not null)
42+
return dispatcher.EnqueueAsync(function, priority);
43+
else
44+
return Task.FromResult(function());
45+
}
46+
47+
}
48+
}

src/Files.App/Filesystem/Cloud/CloudDrivesManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using CommunityToolkit.Mvvm.DependencyInjection;
55
using CommunityToolkit.WinUI;
66
using Files.App.DataModels.NavigationControlItems;
7+
using Files.App.Extensions;
78
using Files.App.Helpers;
89
using Files.Shared;
910
using Files.Shared.Cloud;
@@ -56,7 +57,7 @@ public async Task UpdateDrivesAsync()
5657
try
5758
{
5859
cloudProviderItem.Root = await StorageFolder.GetFolderFromPathAsync(cloudProviderItem.Path);
59-
_ = App.Window.DispatcherQueue.EnqueueAsync(() => cloudProviderItem.UpdatePropertiesAsync());
60+
_ = App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => cloudProviderItem.UpdatePropertiesAsync());
6061
}
6162
catch (Exception ex)
6263
{
@@ -75,7 +76,7 @@ public async Task UpdateDrivesAsync()
7576
{
7677
cloudProviderItem.IconData = iconData;
7778
await App.Window.DispatcherQueue
78-
.EnqueueAsync(async () => cloudProviderItem.Icon = await iconData.ToBitmapAsync());
79+
.EnqueueOrInvokeAsync(async () => cloudProviderItem.Icon = await iconData.ToBitmapAsync());
7980
}
8081

8182
lock (drives)

src/Files.App/Filesystem/Search/FolderSearch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ private ListedItem GetListedItemAsync(string itemPath, WIN32_FIND_DATA findData)
397397
{
398398
if (t.IsCompletedSuccessfully && t.Result is not null)
399399
{
400-
_ = FilesystemTasks.Wrap(() => App.Window.DispatcherQueue.EnqueueAsync(async () =>
400+
_ = FilesystemTasks.Wrap(() => App.Window.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
401401
{
402402
listedItem.FileImage = await t.Result.ToBitmapAsync();
403403
}, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low));

src/Files.App/Helpers/DynamicDialogFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static DynamicDialog GetFor_RenameDialog()
101101
inputText.Loaded += (s, e) =>
102102
{
103103
// dispatching to the ui thread fixes an issue where the primary dialog button would steal focus
104-
_ = inputText.DispatcherQueue.EnqueueAsync(() => inputText.Focus(FocusState.Programmatic));
104+
_ = inputText.DispatcherQueue.EnqueueOrInvokeAsync(() => inputText.Focus(FocusState.Programmatic));
105105
};
106106

107107
dialog = new DynamicDialog(new DynamicDialogViewModel()

src/Files.App/Helpers/MenuFlyoutHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using CommunityToolkit.WinUI;
5+
using Files.App.Extensions;
56
using Microsoft.UI.Xaml;
67
using Microsoft.UI.Xaml.Controls;
78
using System;
@@ -105,7 +106,7 @@ private static async Task SetupItems(MenuFlyout menu)
105106
return;
106107
}
107108

108-
await menu.DispatcherQueue.EnqueueAsync(() =>
109+
await menu.DispatcherQueue.EnqueueOrInvokeAsync(() =>
109110
{
110111
menu.Items.Clear();
111112
AddItems(menu.Items, itemSource);

src/Files.App/Helpers/ThemeHelper.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static void Initialize()
5353

5454
// Set TitleBar background color
5555
if (currentApplicationWindow is not null)
56-
titleBar = App.GetAppWindow(currentApplicationWindow).TitleBar;
56+
titleBar = App.GetAppWindow(currentApplicationWindow)?.TitleBar;
5757

5858
// Apply the desired theme based on what is set in the application settings
5959
ApplyTheme();
@@ -70,14 +70,15 @@ private static async void UiSettings_ColorValuesChanged(UISettings sender, objec
7070
{
7171
currentApplicationWindow = App.Window;
7272

73-
if (currentApplicationWindow is not null)
74-
titleBar = App.GetAppWindow(currentApplicationWindow).TitleBar;
75-
else
73+
if (currentApplicationWindow is null)
7674
return;
7775
}
7876

77+
if (titleBar is null)
78+
titleBar = App.GetAppWindow(currentApplicationWindow)?.TitleBar;
79+
7980
// Dispatch on UI thread so that we have a current appbar to access and change
80-
await currentApplicationWindow.DispatcherQueue.EnqueueAsync(ApplyTheme);
81+
await currentApplicationWindow.DispatcherQueue.EnqueueOrInvokeAsync(ApplyTheme);
8182
}
8283

8384
private static void ApplyTheme()

src/Files.App/Interacts/BaseLayoutCommandImplementationModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public virtual async Task OpenDirectoryInNewTab(RoutedEventArgs e)
103103
{
104104
foreach (ListedItem listedItem in SlimContentPage.SelectedItems)
105105
{
106-
await App.Window.DispatcherQueue.EnqueueAsync(async () =>
106+
await App.Window.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
107107
{
108108
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
109109
},

src/Files.App/ServicesImplementation/RemovableDrivesService.cs

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

44
using CommunityToolkit.WinUI;
55
using Files.App.DataModels.NavigationControlItems;
6+
using Files.App.Extensions;
67
using Files.App.Filesystem;
78
using Files.App.Helpers;
89
using Files.App.Storage.WindowsStorage;
@@ -69,7 +70,7 @@ public async Task UpdateDrivePropertiesAsync(ILocatableFolder drive)
6970
var rootModified = await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(drive.Path).AsTask());
7071
if (rootModified && drive is DriveItem matchingDriveEjected)
7172
{
72-
_ = App.Window.DispatcherQueue.EnqueueAsync(() =>
73+
_ = App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() =>
7374
{
7475
matchingDriveEjected.Root = rootModified.Result;
7576
matchingDriveEjected.Text = rootModified.Result.DisplayName;

src/Files.App/ServicesImplementation/ThreadingService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using CommunityToolkit.WinUI;
5+
using Files.App.Extensions;
56
using Files.Backend.Services;
67
using Microsoft.UI.Dispatching;
78
using System;
@@ -20,12 +21,12 @@ public ThreadingService()
2021

2122
public Task ExecuteOnUiThreadAsync(Action action)
2223
{
23-
return _dispatcherQueue.EnqueueAsync(action);
24+
return _dispatcherQueue.EnqueueOrInvokeAsync(action);
2425
}
2526

2627
public Task<TResult?> ExecuteOnUiThreadAsync<TResult>(Func<TResult?> func)
2728
{
28-
return _dispatcherQueue.EnqueueAsync<TResult?>(func);
29+
return _dispatcherQueue.EnqueueOrInvokeAsync<TResult?>(func);
2930
}
3031
}
3132
}

src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public async Task LoadCardThumbnailAsync()
5252

5353
// Thumbnail data is valid, set the item icon
5454
if (thumbnailData is not null && thumbnailData.Length > 0)
55-
Thumbnail = await thumbnailData.ToBitmapAsync(Constants.Widgets.WidgetIconSize);
55+
Thumbnail = await App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => thumbnailData.ToBitmapAsync(Constants.Widgets.WidgetIconSize));
5656
}
5757

5858
public int CompareTo(DriveCardItem? other) => Item.Path.CompareTo(other?.Item?.Path);
@@ -137,9 +137,9 @@ public DrivesWidget()
137137

138138
private async void Drives_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
139139
{
140-
await DispatcherQueue.EnqueueAsync(async () =>
140+
await DispatcherQueue.EnqueueOrInvokeAsync(async () =>
141141
{
142-
foreach (DriveItem drive in drivesViewModel.Drives)
142+
foreach (DriveItem drive in drivesViewModel.Drives.ToList())
143143
{
144144
if (!ItemsAdded.Any(x => x.Item == drive) && drive.Type != DriveType.VirtualDrive)
145145
{

src/Files.App/UserControls/Widgets/QuickAccessWidget.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public async Task LoadCardThumbnailAsync()
100100
}
101101
if (thumbnailData is not null && thumbnailData.Length > 0)
102102
{
103-
Thumbnail = await thumbnailData.ToBitmapAsync(Constants.Widgets.WidgetIconSize);
103+
Thumbnail = await App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => thumbnailData.ToBitmapAsync(Constants.Widgets.WidgetIconSize));
104104
}
105105
}
106106
}
@@ -250,7 +250,7 @@ private async void ModifyItem(object? sender, ModifyQuickAccessEventArgs? e)
250250
if (e is null)
251251
return;
252252

253-
await DispatcherQueue.EnqueueAsync(async () =>
253+
await DispatcherQueue.EnqueueOrInvokeAsync(async () =>
254254
{
255255
if (e.Reset)
256256
{

src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public async Task RefreshWidget()
213213

214214
private async void Manager_RecentFilesChanged(object sender, NotifyCollectionChangedEventArgs e)
215215
{
216-
await DispatcherQueue.EnqueueAsync(async () =>
216+
await DispatcherQueue.EnqueueOrInvokeAsync(async () =>
217217
{
218218
// e.Action can only be Reset right now; naively refresh everything for simplicity
219219
await UpdateRecentsList(e);

0 commit comments

Comments
 (0)