Skip to content

Commit 34da691

Browse files
authored
Fix: Fixed issue where the app would crash when pinning an executable file (#14387)
1 parent a1d0bc7 commit 34da691

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

src/Files.App/Actions/Start/PinToStartAction.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ public async Task ExecuteAsync()
3737
{
3838
foreach (ListedItem listedItem in context.ShellPage.SlimContentPage.SelectedItems)
3939
{
40-
var folder = await StorageService.GetFolderAsync(listedItem.ItemPath);
41-
await StartMenuService.PinAsync(folder, listedItem.Name);
40+
IStorable storable = listedItem.IsFolder switch
41+
{
42+
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
43+
_ => await StorageService.GetFileAsync(listedItem.ItemPath)
44+
};
45+
await StartMenuService.PinAsync(storable, listedItem.Name);
4246
}
4347
}
4448
else if (context.ShellPage?.FilesystemViewModel?.CurrentFolder is not null)

src/Files.App/Actions/Start/UnpinFromStartAction.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ public async Task ExecuteAsync()
3333
{
3434
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems)
3535
{
36-
var folder = await StorageService.GetFolderAsync(listedItem.ItemPath);
37-
await StartMenuService.UnpinAsync(folder);
36+
IStorable storable = listedItem.IsFolder switch
37+
{
38+
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
39+
_ => await StorageService.GetFileAsync(listedItem.ItemPath)
40+
};
41+
await StartMenuService.UnpinAsync(storable);
3842
}
3943
}
4044
else

src/Files.App/Services/StartMenuService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ namespace Files.App.Services
77
internal sealed class StartMenuService : IStartMenuService
88
{
99
[Obsolete("See IStartMenuService for further information.")]
10-
public bool IsPinned(string folderPath)
10+
public bool IsPinned(string itemPath)
1111
{
12-
var tileId = GetNativeTileId(folderPath);
12+
var tileId = GetNativeTileId(itemPath);
1313
return SecondaryTile.Exists(tileId);
1414
}
1515

1616
/// <inheritdoc/>
17-
public Task<bool> IsPinnedAsync(IFolder folder)
17+
public Task<bool> IsPinnedAsync(IStorable storable)
1818
{
19-
var tileId = GetNativeTileId(folder.Id);
19+
var tileId = GetNativeTileId(storable.Id);
2020
var exists = SecondaryTile.Exists(tileId);
2121

2222
return Task.FromResult(exists);
2323
}
2424

2525
/// <inheritdoc/>
26-
public async Task PinAsync(IFolder folder, string? displayName = null)
26+
public async Task PinAsync(IStorable storable, string? displayName = null)
2727
{
28-
var tileId = GetNativeTileId(folder.Id);
29-
displayName ??= folder.Name;
28+
var tileId = GetNativeTileId(storable.Id);
29+
displayName ??= storable.Name;
3030

3131
try
3232
{
@@ -36,7 +36,7 @@ public async Task PinAsync(IFolder folder, string? displayName = null)
3636
var tile = new SecondaryTile(
3737
tileId,
3838
displayName,
39-
folder.Id,
39+
storable.Id,
4040
path150x150,
4141
TileSize.Square150x150)
4242
{
@@ -60,10 +60,10 @@ public async Task PinAsync(IFolder folder, string? displayName = null)
6060
}
6161

6262
/// <inheritdoc/>
63-
public async Task UnpinAsync(IFolder folder)
63+
public async Task UnpinAsync(IStorable storable)
6464
{
6565
var startScreen = StartScreenManager.GetDefault();
66-
var tileId = GetNativeTileId(folder.Id);
66+
var tileId = GetNativeTileId(storable.Id);
6767

6868
await startScreen.TryRemoveSecondaryTileAsync(tileId);
6969
}

src/Files.Core/Services/IStartMenuService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ public interface IStartMenuService
99
{
1010
// TODO(s)
1111
[Obsolete("Use IsPinnedAsync instead. This method is used for a workaround in ListedItem class to avoid major refactoring.")]
12-
bool IsPinned(string folderPath);
12+
bool IsPinned(string itemPath);
1313

1414
/// <summary>
15-
/// Checks if the provided <paramref name="folder"/> is pinned to the Start Menu.
15+
/// Checks if the provided <paramref name="storable"/> is pinned to the Start Menu.
1616
/// </summary>
17-
/// <param name="folder">The folder to check for.</param>
17+
/// <param name="storable">The <see cref="IStorable"/> object to check for.</param>
1818
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If the folder is pinned, returns true; otherwise false.</returns>
19-
Task<bool> IsPinnedAsync(IFolder folder);
19+
Task<bool> IsPinnedAsync(IStorable storable);
2020

2121
/// <summary>
22-
/// Adds the provided <paramref name="folder"/> to the pinned items list in the Start Menu.
22+
/// Adds the provided <paramref name="storable"/> to the pinned items list in the Start Menu.
2323
/// </summary>
24-
/// <param name="folder">The folder to pin.</param>
24+
/// <param name="storable">The <see cref="IStorable"/> object to pin.</param>
2525
/// <param name="displayName">The optional name to use when pinning an item.</param>
2626
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
27-
Task PinAsync(IFolder folder, string? displayName = null);
27+
Task PinAsync(IStorable storable, string? displayName = null);
2828

2929
/// <summary>
30-
/// Removes the provided <paramref name="folder"/> from the pinned items list in the Start Menu.
30+
/// Removes the provided <paramref name="storable"/> from the pinned items list in the Start Menu.
3131
/// </summary>
32-
/// <param name="folder">The folder to unpin.</param>
32+
/// <param name="storable">The <see cref="IStorable"/> object to unpin.</param>
3333
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
34-
Task UnpinAsync(IFolder folder);
34+
Task UnpinAsync(IStorable storable);
3535
}
3636
}

0 commit comments

Comments
 (0)