Skip to content

Commit 8340fab

Browse files
committed
chore: address pr feedback
1 parent d80caae commit 8340fab

File tree

11 files changed

+252
-246
lines changed

11 files changed

+252
-246
lines changed

src/Files.App/Actions/Content/ImageEdition/RotateLeftAction.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Files.App.Extensions;
66
using Files.App.Helpers;
77
using Files.App.ViewModels;
8-
using Files.Backend.Services.Settings;
98
using System.ComponentModel;
109
using System.Linq;
1110
using System.Threading.Tasks;

src/Files.App/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
200200
.AddSingleton<IPageContext, PageContext>()
201201
.AddSingleton<IContentPageContext, ContentPageContext>()
202202
.AddSingleton<IDisplayPageContext, DisplayPageContext>()
203-
.AddSingleton<IWindowContext, WindowContext>()
204-
.AddSingleton<IMultitaskingContext, MultitaskingContext>()
203+
.AddSingleton<IWindowContext, WindowContext>()
204+
.AddSingleton<IMultitaskingContext, MultitaskingContext>()
205205
.AddSingleton(Logger)
206206
.AddSingleton<IDialogService, DialogService>()
207207
.AddSingleton<IImageService, ImagingService>()

src/Files.App/Filesystem/QuickAccessManager.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
using Files.App.DataModels;
44
using Files.App.ServicesImplementation;
55
using Files.App.UserControls.Widgets;
6-
using Files.Shared.Extensions;
76
using System;
8-
using System.Collections.Generic;
97
using System.IO;
10-
using System.Linq;
11-
using System.Text.Json;
128
using System.Threading.Tasks;
13-
using Windows.Storage;
149
using static Files.App.Constants;
1510

1611
namespace Files.App.Filesystem

src/Files.App/Helpers/AppThemeResourcesHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using CommunityToolkit.WinUI.Helpers;
2+
using Files.Backend.Services;
23
using Files.Backend.Services.Settings;
3-
using Files.Shared.Services;
44
using System;
55

66
namespace Files.App.Helpers
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
using CommunityToolkit.Mvvm.DependencyInjection;
2+
using Files.App.UserControls.Widgets;
23
using Files.Shared.Services;
34
using System;
45
using System.Threading.Tasks;
56

6-
namespace Files.App.Helpers;
7-
8-
public sealed class JumpListHelper
7+
namespace Files.App.Helpers
98
{
10-
public static async Task InitializeUpdatesAsync()
9+
public sealed class JumpListHelper
1110
{
12-
var jumpListService = Ioc.Default.GetRequiredService<IJumpListService>();
11+
private static IJumpListService jumpListService = Ioc.Default.GetRequiredService<IJumpListService>();
1312

14-
try
13+
public static async Task InitializeUpdatesAsync()
1514
{
16-
App.QuickAccessManager.UpdateQuickAccessWidget += async (sender, args) => await jumpListService.RefreshPinnedFoldersAsync();
15+
try
16+
{
17+
App.QuickAccessManager.UpdateQuickAccessWidget -= UpdateQuickAccessWidget;
18+
App.QuickAccessManager.UpdateQuickAccessWidget += UpdateQuickAccessWidget;
1719

18-
await jumpListService.RefreshPinnedFoldersAsync();
20+
await jumpListService.RefreshPinnedFoldersAsync();
21+
}
22+
catch (Exception ex)
23+
{
24+
App.Logger.Warn(ex, ex.Message);
25+
}
1926
}
20-
catch (Exception ex)
27+
28+
private static async void UpdateQuickAccessWidget(object? sender, ModifyQuickAccessEventArgs e)
2129
{
22-
App.Logger.Warn(ex, ex.Message);
30+
await jumpListService.RefreshPinnedFoldersAsync();
2331
}
2432
}
2533
}

src/Files.App/ServicesImplementation/JumpListService.cs

Lines changed: 119 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,168 +6,170 @@
66
using System.Collections.Generic;
77
using System.IO;
88
using System.Linq;
9-
using System.Text;
109
using System.Threading.Tasks;
1110
using Windows.Storage;
1211
using Windows.UI.StartScreen;
1312

14-
namespace Files.App.ServicesImplementation;
15-
public class JumpListService : IJumpListService
13+
namespace Files.App.ServicesImplementation
1614
{
17-
private const string JumpListRecentGroupHeader = "ms-resource:///Resources/JumpListRecentGroupHeader";
18-
private const string JumpListPinnedGroupHeader = "ms-resource:///Resources/JumpListPinnedGroupHeader";
19-
20-
public async Task AddFolderAsync(string path)
15+
public class JumpListService : IJumpListService
2116
{
22-
if (JumpList.IsSupported())
23-
{
24-
var instance = await JumpList.LoadCurrentAsync();
25-
// Disable automatic jumplist. It doesn't work.
26-
instance.SystemGroupKind = JumpListSystemGroupKind.None;
17+
private const string JumpListRecentGroupHeader = "ms-resource:///Resources/JumpListRecentGroupHeader";
18+
private const string JumpListPinnedGroupHeader = "ms-resource:///Resources/JumpListPinnedGroupHeader";
2719

28-
// Saving to jumplist may fail randomly with error: ERROR_UNABLE_TO_REMOVE_REPLACED
29-
// In that case app should just catch the error and proceed as usual
30-
try
20+
public async Task AddFolderAsync(string path)
21+
{
22+
if (JumpList.IsSupported())
3123
{
32-
if (instance is not null)
24+
var instance = await JumpList.LoadCurrentAsync();
25+
// Disable automatic jumplist. It doesn't work.
26+
instance.SystemGroupKind = JumpListSystemGroupKind.None;
27+
28+
// Saving to jumplist may fail randomly with error: ERROR_UNABLE_TO_REMOVE_REPLACED
29+
// In that case app should just catch the error and proceed as usual
30+
try
3331
{
34-
AddFolder(path, JumpListRecentGroupHeader, instance);
35-
await instance.SaveAsync();
32+
if (instance is not null)
33+
{
34+
AddFolder(path, JumpListRecentGroupHeader, instance);
35+
await instance.SaveAsync();
36+
}
3637
}
38+
catch { }
3739
}
38-
catch { }
3940
}
40-
}
4141

42-
public async Task<IEnumerable<string>> GetFoldersAsync()
43-
{
44-
if (JumpList.IsSupported())
42+
public async Task<IEnumerable<string>> GetFoldersAsync()
4543
{
46-
try
44+
if (JumpList.IsSupported())
4745
{
48-
var instance = await JumpList.LoadCurrentAsync();
49-
// Disable automatic jumplist. It doesn't work.
50-
instance.SystemGroupKind = JumpListSystemGroupKind.None;
46+
try
47+
{
48+
var instance = await JumpList.LoadCurrentAsync();
49+
// Disable automatic jumplist. It doesn't work.
50+
instance.SystemGroupKind = JumpListSystemGroupKind.None;
5151

52-
return instance.Items.Select(item => item.Arguments).ToList();
52+
return instance.Items.Select(item => item.Arguments).ToList();
53+
}
54+
catch
55+
{
56+
return Enumerable.Empty<string>();
57+
}
5358
}
54-
catch
59+
else
5560
{
5661
return Enumerable.Empty<string>();
5762
}
5863
}
59-
else
60-
{
61-
return Enumerable.Empty<string>();
62-
}
63-
}
6464

65-
public async Task RefreshPinnedFoldersAsync()
66-
{
67-
try
65+
public async Task RefreshPinnedFoldersAsync()
6866
{
69-
if (JumpList.IsSupported())
67+
try
7068
{
71-
var instance = await JumpList.LoadCurrentAsync();
72-
// Disable automatic jumplist. It doesn't work with Files UWP.
73-
instance.SystemGroupKind = JumpListSystemGroupKind.None;
69+
if (JumpList.IsSupported())
70+
{
71+
var instance = await JumpList.LoadCurrentAsync();
72+
// Disable automatic jumplist. It doesn't work with Files UWP.
73+
instance.SystemGroupKind = JumpListSystemGroupKind.None;
7474

75-
if (instance is null)
76-
return;
75+
if (instance is null)
76+
return;
7777

78-
var itemsToRemove = instance.Items.Where(x => string.Equals(x.GroupName, JumpListPinnedGroupHeader, StringComparison.OrdinalIgnoreCase)).ToList();
79-
itemsToRemove.ForEach(x => instance.Items.Remove(x));
80-
App.QuickAccessManager.Model.FavoriteItems.ForEach(x => AddFolder(x, JumpListPinnedGroupHeader, instance));
81-
await instance.SaveAsync();
78+
var itemsToRemove = instance.Items.Where(x => string.Equals(x.GroupName, JumpListPinnedGroupHeader, StringComparison.OrdinalIgnoreCase)).ToList();
79+
itemsToRemove.ForEach(x => instance.Items.Remove(x));
80+
App.QuickAccessManager.Model.FavoriteItems.ForEach(x => AddFolder(x, JumpListPinnedGroupHeader, instance));
81+
await instance.SaveAsync();
82+
}
8283
}
83-
}
84-
catch {
85-
}
86-
}
87-
88-
public async Task RemoveFolderAsync(string path)
89-
{
90-
if (JumpList.IsSupported())
91-
{
92-
try
84+
catch
9385
{
94-
var instance = await JumpList.LoadCurrentAsync();
95-
// Disable automatic jumplist. It doesn't work.
96-
instance.SystemGroupKind = JumpListSystemGroupKind.None;
97-
98-
var itemToRemove = instance.Items.Where(x => x.Arguments == path).Select(x => x).FirstOrDefault();
99-
instance.Items.Remove(itemToRemove);
100-
await instance.SaveAsync();
10186
}
102-
catch { }
10387
}
104-
}
10588

106-
private void AddFolder(string path, string group, JumpList instance)
107-
{
108-
if (instance is not null)
89+
public async Task RemoveFolderAsync(string path)
10990
{
110-
string displayName = null;
111-
if (path.EndsWith("\\"))
91+
if (JumpList.IsSupported())
11292
{
113-
// Jumplist item argument can't end with a slash so append a character that can't exist in a directory name to support listing drives.
114-
var drive = App.DrivesManager.Drives.Where(drive => drive.Path == path).FirstOrDefault();
115-
if (drive is null)
116-
return;
93+
try
94+
{
95+
var instance = await JumpList.LoadCurrentAsync();
96+
// Disable automatic jumplist. It doesn't work.
97+
instance.SystemGroupKind = JumpListSystemGroupKind.None;
11798

118-
displayName = drive.Text;
119-
path += '?';
99+
var itemToRemove = instance.Items.Where(x => x.Arguments == path).Select(x => x).FirstOrDefault();
100+
instance.Items.Remove(itemToRemove);
101+
await instance.SaveAsync();
102+
}
103+
catch { }
120104
}
105+
}
121106

122-
if (displayName is null)
107+
private void AddFolder(string path, string group, JumpList instance)
108+
{
109+
if (instance is not null)
123110
{
124-
if (path.Equals(CommonPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
125-
displayName = "ms-resource:///Resources/Desktop";
126-
else if (path.Equals(CommonPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase))
127-
displayName = "ms-resource:///Resources/Downloads";
128-
else if (path.Equals(CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
111+
string displayName = null;
112+
if (path.EndsWith("\\"))
129113
{
130-
var localSettings = ApplicationData.Current.LocalSettings;
131-
displayName = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin");
114+
// Jumplist item argument can't end with a slash so append a character that can't exist in a directory name to support listing drives.
115+
var drive = App.DrivesManager.Drives.Where(drive => drive.Path == path).FirstOrDefault();
116+
if (drive is null)
117+
return;
118+
119+
displayName = drive.Text;
120+
path += '?';
132121
}
133-
else if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library))
122+
123+
if (displayName is null)
134124
{
135-
var libName = Path.GetFileNameWithoutExtension(library.Path);
136-
switch (libName)
125+
if (path.Equals(CommonPaths.DesktopPath, StringComparison.OrdinalIgnoreCase))
126+
displayName = "ms-resource:///Resources/Desktop";
127+
else if (path.Equals(CommonPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase))
128+
displayName = "ms-resource:///Resources/Downloads";
129+
else if (path.Equals(CommonPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
137130
{
138-
case "Documents":
139-
case "Pictures":
140-
case "Music":
141-
case "Videos":
142-
// Use localized name
143-
displayName = $"ms-resource:///Resources/{libName}";
144-
break;
145-
146-
default:
147-
// Use original name
148-
displayName = library.Text;
149-
break;
131+
var localSettings = ApplicationData.Current.LocalSettings;
132+
displayName = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin");
150133
}
134+
else if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library))
135+
{
136+
var libName = Path.GetFileNameWithoutExtension(library.Path);
137+
switch (libName)
138+
{
139+
case "Documents":
140+
case "Pictures":
141+
case "Music":
142+
case "Videos":
143+
// Use localized name
144+
displayName = $"ms-resource:///Resources/{libName}";
145+
break;
146+
147+
default:
148+
// Use original name
149+
displayName = library.Text;
150+
break;
151+
}
152+
}
153+
else
154+
displayName = Path.GetFileName(path);
151155
}
152-
else
153-
displayName = Path.GetFileName(path);
154-
}
155156

156-
var jumplistItem = JumpListItem.CreateWithArguments(path, displayName);
157-
jumplistItem.Description = jumplistItem.Arguments;
158-
jumplistItem.GroupName = group;
159-
jumplistItem.Logo = new Uri("ms-appx:///Assets/FolderIcon.png");
157+
var jumplistItem = JumpListItem.CreateWithArguments(path, displayName);
158+
jumplistItem.Description = jumplistItem.Arguments;
159+
jumplistItem.GroupName = group;
160+
jumplistItem.Logo = new Uri("ms-appx:///Assets/FolderIcon.png");
160161

161-
if (string.Equals(group, JumpListRecentGroupHeader, StringComparison.OrdinalIgnoreCase))
162-
{
163-
// Keep newer items at the top.
164-
instance.Items.Remove(instance.Items.FirstOrDefault(x => x.Arguments.Equals(path, StringComparison.OrdinalIgnoreCase)));
165-
instance.Items.Insert(0, jumplistItem);
166-
}
167-
else
168-
{
169-
var pinnedItemsCount = instance.Items.Where(x => x.GroupName == JumpListPinnedGroupHeader).Count();
170-
instance.Items.Insert(pinnedItemsCount, jumplistItem);
162+
if (string.Equals(group, JumpListRecentGroupHeader, StringComparison.OrdinalIgnoreCase))
163+
{
164+
// Keep newer items at the top.
165+
instance.Items.Remove(instance.Items.FirstOrDefault(x => x.Arguments.Equals(path, StringComparison.OrdinalIgnoreCase)));
166+
instance.Items.Insert(0, jumplistItem);
167+
}
168+
else
169+
{
170+
var pinnedItemsCount = instance.Items.Where(x => x.GroupName == JumpListPinnedGroupHeader).Count();
171+
instance.Items.Insert(pinnedItemsCount, jumplistItem);
172+
}
171173
}
172174
}
173175
}

0 commit comments

Comments
 (0)