Skip to content

Commit

Permalink
Fix: Fixed issue where the app would crash when pinning an executable…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu authored Jan 8, 2024
1 parent a1d0bc7 commit 34da691
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
8 changes: 6 additions & 2 deletions src/Files.App/Actions/Start/PinToStartAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public async Task ExecuteAsync()
{
foreach (ListedItem listedItem in context.ShellPage.SlimContentPage.SelectedItems)
{
var folder = await StorageService.GetFolderAsync(listedItem.ItemPath);
await StartMenuService.PinAsync(folder, listedItem.Name);
IStorable storable = listedItem.IsFolder switch
{
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
_ => await StorageService.GetFileAsync(listedItem.ItemPath)
};
await StartMenuService.PinAsync(storable, listedItem.Name);
}
}
else if (context.ShellPage?.FilesystemViewModel?.CurrentFolder is not null)
Expand Down
8 changes: 6 additions & 2 deletions src/Files.App/Actions/Start/UnpinFromStartAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ public async Task ExecuteAsync()
{
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems)
{
var folder = await StorageService.GetFolderAsync(listedItem.ItemPath);
await StartMenuService.UnpinAsync(folder);
IStorable storable = listedItem.IsFolder switch
{
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
_ => await StorageService.GetFileAsync(listedItem.ItemPath)
};
await StartMenuService.UnpinAsync(storable);
}
}
else
Expand Down
20 changes: 10 additions & 10 deletions src/Files.App/Services/StartMenuService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ namespace Files.App.Services
internal sealed class StartMenuService : IStartMenuService
{
[Obsolete("See IStartMenuService for further information.")]
public bool IsPinned(string folderPath)
public bool IsPinned(string itemPath)
{
var tileId = GetNativeTileId(folderPath);
var tileId = GetNativeTileId(itemPath);
return SecondaryTile.Exists(tileId);
}

/// <inheritdoc/>
public Task<bool> IsPinnedAsync(IFolder folder)
public Task<bool> IsPinnedAsync(IStorable storable)
{
var tileId = GetNativeTileId(folder.Id);
var tileId = GetNativeTileId(storable.Id);
var exists = SecondaryTile.Exists(tileId);

return Task.FromResult(exists);
}

/// <inheritdoc/>
public async Task PinAsync(IFolder folder, string? displayName = null)
public async Task PinAsync(IStorable storable, string? displayName = null)
{
var tileId = GetNativeTileId(folder.Id);
displayName ??= folder.Name;
var tileId = GetNativeTileId(storable.Id);
displayName ??= storable.Name;

try
{
Expand All @@ -36,7 +36,7 @@ public async Task PinAsync(IFolder folder, string? displayName = null)
var tile = new SecondaryTile(
tileId,
displayName,
folder.Id,
storable.Id,
path150x150,
TileSize.Square150x150)
{
Expand All @@ -60,10 +60,10 @@ public async Task PinAsync(IFolder folder, string? displayName = null)
}

/// <inheritdoc/>
public async Task UnpinAsync(IFolder folder)
public async Task UnpinAsync(IStorable storable)
{
var startScreen = StartScreenManager.GetDefault();
var tileId = GetNativeTileId(folder.Id);
var tileId = GetNativeTileId(storable.Id);

await startScreen.TryRemoveSecondaryTileAsync(tileId);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Files.Core/Services/IStartMenuService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ public interface IStartMenuService
{
// TODO(s)
[Obsolete("Use IsPinnedAsync instead. This method is used for a workaround in ListedItem class to avoid major refactoring.")]
bool IsPinned(string folderPath);
bool IsPinned(string itemPath);

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

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

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

0 comments on commit 34da691

Please sign in to comment.