Skip to content

A Swiss Army knife for developers.

Fixed an NRE when generating tile icons. (#121)

Etienne Baudouxad7ec83e1563
diff --git a/src/dev/impl/DevToys/Core/UriActivationProtocolService.cs b/src/dev/impl/DevToys/Core/UriActivationProtocolService.cs
index 13a0c521b..292264672 100644
--- a/src/dev/impl/DevToys/Core/UriActivationProtocolService.cs
+++ b/src/dev/impl/DevToys/Core/UriActivationProtocolService.cs
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Composition;
using System.Globalization;
+using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using DevToys.Api.Core;
@@ -87,20 +88,38 @@ namespace DevToys.Core
{
ThreadHelper.ThrowIfNotOnUIThread();
- var tileIconGenerationTasks = new List<Task>();
+ var tileIconGenerationTasks = new List<Task<TileIconSizeDefinition?>>();
for (int i = 0; i < ToolTileIconSizeDefinitions.Length; i++)
{
- TileIconSizeDefinition? iconDefinition = ToolTileIconSizeDefinitions[i];
- tileIconGenerationTasks.Add(
- GenerateCustomTileIconAsync(
- iconDefinition.Size,
- iconDefinition.ToolIconRatio,
- iconDefinition.IconName,
- toolProvider));
+ TileIconSizeDefinition iconDefinition = ToolTileIconSizeDefinitions[i];
+ tileIconGenerationTasks.Add(GenerateCustomTileIconAsync(iconDefinition, toolProvider));
}
await Task.WhenAll(tileIconGenerationTasks).ConfigureAwait(true);
+ string? smallTileIconName
+ = tileIconGenerationTasks
+ .Where(t => t.Result is not null && t.Result.IconName.StartsWith("SmallTile", StringComparison.Ordinal))
+ .OrderBy(t => t.Result!.Size)
+ .FirstOrDefault()?.Result!.IconName;
+
+ string? square44IconName
+ = tileIconGenerationTasks
+ .Where(t => t.Result is not null && t.Result.IconName.StartsWith("Square44x44Logo", StringComparison.Ordinal))
+ .OrderBy(t => t.Result!.Size)
+ .FirstOrDefault()?.Result!.IconName;
+
+ string? square150IconName
+ = tileIconGenerationTasks
+ .Where(t => t.Result is not null && t.Result.IconName.StartsWith("Square150x150Logo", StringComparison.Ordinal))
+ .OrderBy(t => t.Result!.Size)
+ .FirstOrDefault()?.Result!.IconName;
+
+ if (string.IsNullOrEmpty(smallTileIconName) || string.IsNullOrEmpty(square44IconName) || string.IsNullOrEmpty(square150IconName))
+ {
+ Logger.Log("Pin to start", "Unable to generate one of the required tile icon.");
+ }
+
var tile = new SecondaryTile(
tileId: toolProvider.Metadata.ProtocolName)
{
@@ -109,9 +128,9 @@ namespace DevToys.Core
RoamingEnabled = false
};
tile.VisualElements.ShowNameOnSquare150x150Logo = true;
- tile.VisualElements.Square150x150Logo = new Uri($"ms-appdata:///local/{toolProvider.Metadata.ProtocolName}/Square150x150Logo.scale-100.png");
- tile.VisualElements.Square44x44Logo = new Uri($"ms-appdata:///local/{toolProvider.Metadata.ProtocolName}/Square44x44Logo.scale-100.png");
- tile.VisualElements.Square71x71Logo = new Uri($"ms-appdata:///local/{toolProvider.Metadata.ProtocolName}/SmallTile.scale-100.png");
+ tile.VisualElements.Square150x150Logo = new Uri($"ms-appdata:///local/{toolProvider.Metadata.ProtocolName}/{square150IconName}.png");
+ tile.VisualElements.Square44x44Logo = new Uri($"ms-appdata:///local/{toolProvider.Metadata.ProtocolName}/{square44IconName}.png");
+ tile.VisualElements.Square71x71Logo = new Uri($"ms-appdata:///local/{toolProvider.Metadata.ProtocolName}/{smallTileIconName}.png");
return await tile.RequestCreateForSelectionAsync(Window.Current.Bounds);
}
@@ -148,135 +167,152 @@ namespace DevToys.Core
return uriToLaunch;
}
- private async Task GenerateCustomTileIconAsync(int targetSize, double toolIconRatio, string inputFileName, MatchedToolProvider toolProvider)
+ private async Task<TileIconSizeDefinition?> GenerateCustomTileIconAsync(TileIconSizeDefinition tileIconSizeDefinition, MatchedToolProvider toolProvider)
{
- ThreadHelper.ThrowIfNotOnUIThread();
-
- /*
- * The code below generates the following equivalent:
- * <Canvas HorizontalAlignment="Left" VerticalAlignment="Top">
- * <Grid>
- * <Image Source="image.scale-100.png" Grid.ColumnSpan="3" Grid.RowSpan="3"/>
- * <Viewbox HorizontalAlignment="Center" VerticalAlignment="Center">
- * <IconElement/>
- * </Viewbox>
- * </Grid>
- * </Canvas>
- */
-
- StorageFolder installationFolder = Package.Current.InstalledLocation;
- var backgroundIconImageFile = (StorageFile)await installationFolder.TryGetItemAsync($"Assets\\TileTemplate\\{inputFileName}.png");
-
- using (IRandomAccessStream fileStream = await backgroundIconImageFile.OpenAsync(FileAccessMode.Read, StorageOpenOptions.AllowOnlyReaders))
+ try
{
- var backgroundIconImageSource = new BitmapImage
- {
- DecodePixelWidth = targetSize,
- DecodePixelHeight = targetSize
- };
- await backgroundIconImageSource.SetSourceAsync(fileStream);
+ ThreadHelper.ThrowIfNotOnUIThread();
- var container = new Grid()
+ /*
+ * The code below generates the following equivalent:
+ * <Canvas HorizontalAlignment="Left" VerticalAlignment="Top">
+ * <Grid>
+ * <Image Source="image.scale-100.png" Grid.ColumnSpan="3" Grid.RowSpan="3"/>
+ * <Viewbox HorizontalAlignment="Center" VerticalAlignment="Center">
+ * <IconElement/>
+ * </Viewbox>
+ * </Grid>
+ * </Canvas>
+ */
+
+ StorageFolder installationFolder = Package.Current.InstalledLocation;
+ if (!await installationFolder.FileExistsAsync($"Assets\\TileTemplate\\{tileIconSizeDefinition.IconName}.png", isRecursive: false))
{
- HorizontalAlignment = HorizontalAlignment.Left,
- VerticalAlignment = VerticalAlignment.Top,
- Height = targetSize,
- Width = targetSize,
- MaxHeight = targetSize,
- MaxWidth = targetSize,
- Background = new SolidColorBrush(Colors.Transparent),
- Margin = new Thickness(-1 * targetSize, -1 * targetSize, 0, 0),
- RequestedTheme = ElementTheme.Dark
- };
+ // Tile template file isn't installed.
+ return null;
+ }
+
+ StorageFile? backgroundIconImageFile = await installationFolder.GetFileAsync($"Assets\\TileTemplate\\{tileIconSizeDefinition.IconName}.png");
- var backgroundIcon = new Image
+ using (IRandomAccessStream fileStream = await backgroundIconImageFile.OpenAsync(FileAccessMode.Read, StorageOpenOptions.AllowOnlyReaders))
{
- Height = targetSize,
- Width = targetSize,
- Source = backgroundIconImageSource,
- Stretch = Stretch.UniformToFill
- };
+ var backgroundIconImageSource = new BitmapImage
+ {
+ DecodePixelWidth = tileIconSizeDefinition.Size,
+ DecodePixelHeight = tileIconSizeDefinition.Size
+ };
+ await backgroundIconImageSource.SetSourceAsync(fileStream);
- IconElement toolIcon = await toolProvider.Icon.Task!.ConfigureAwait(true);
- Assumes.NotNull(toolIcon, nameof(toolIcon));
+ var container = new Grid()
+ {
+ HorizontalAlignment = HorizontalAlignment.Left,
+ VerticalAlignment = VerticalAlignment.Top,
+ Height = tileIconSizeDefinition.Size,
+ Width = tileIconSizeDefinition.Size,
+ MaxHeight = tileIconSizeDefinition.Size,
+ MaxWidth = tileIconSizeDefinition.Size,
+ Background = new SolidColorBrush(Colors.Transparent),
+ Margin = new Thickness(-1 * tileIconSizeDefinition.Size, -1 * tileIconSizeDefinition.Size, 0, 0),
+ RequestedTheme = ElementTheme.Dark
+ };
+
+ var backgroundIcon = new Image
+ {
+ Height = tileIconSizeDefinition.Size,
+ Width = tileIconSizeDefinition.Size,
+ Source = backgroundIconImageSource,
+ Stretch = Stretch.UniformToFill
+ };
- toolIcon.Height = targetSize / toolIconRatio;
- toolIcon.Width = targetSize / toolIconRatio;
+ IconElement toolIcon = await toolProvider.Icon.Task!.ConfigureAwait(true);
+ Assumes.NotNull(toolIcon, nameof(toolIcon));
- var toolIconViewBox = new Viewbox
- {
- Height = targetSize / toolIconRatio,
- Width = targetSize / toolIconRatio,
- Margin = new Thickness(0, 3, 0, 0),
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Child = toolIcon
- };
+ toolIcon.Height = tileIconSizeDefinition.Size / tileIconSizeDefinition.ToolIconRatio;
+ toolIcon.Width = tileIconSizeDefinition.Size / tileIconSizeDefinition.ToolIconRatio;
+
+ var toolIconViewBox = new Viewbox
+ {
+ Height = tileIconSizeDefinition.Size / tileIconSizeDefinition.ToolIconRatio,
+ Width = tileIconSizeDefinition.Size / tileIconSizeDefinition.ToolIconRatio,
+ Margin = new Thickness(0, 3, 0, 0),
+ HorizontalAlignment = HorizontalAlignment.Center,
+ VerticalAlignment = VerticalAlignment.Center,
+ Child = toolIcon
+ };
- container.Children.Add(backgroundIcon);
- container.Children.Add(toolIconViewBox);
+ container.Children.Add(backgroundIcon);
+ container.Children.Add(toolIconViewBox);
- ((Grid)((Page)((Frame)Window.Current.Content).Content).Content).Children.Insert(0, container);
+ ((Grid)((Page)((Frame)Window.Current.Content).Content).Content).Children.Insert(0, container);
- container.UpdateLayout();
+ container.UpdateLayout();
- var iconSizeUpdatedTask = new TaskCompletionSource<object?>();
- long registrationToken = 0;
+ var iconSizeUpdatedTask = new TaskCompletionSource<object?>();
+ long registrationToken = 0;
- var imageIcon = toolIcon as ImageIcon;
- if (imageIcon is not null)
- {
- registrationToken = imageIcon.RegisterPropertyChangedCallback(ImageIcon.SourceProperty, (s, e) =>
+ var imageIcon = toolIcon as ImageIcon;
+ if (imageIcon is not null)
+ {
+ registrationToken = imageIcon.RegisterPropertyChangedCallback(ImageIcon.SourceProperty, (s, e) =>
+ {
+ iconSizeUpdatedTask.TrySetResult(null);
+ });
+ }
+ else
{
iconSizeUpdatedTask.TrySetResult(null);
- });
- }
- else
- {
- iconSizeUpdatedTask.TrySetResult(null);
- }
+ }
- // Wait that the icon updates its size and maybe its color theme.
- await Task.WhenAny(iconSizeUpdatedTask.Task, Task.Delay(500)).ConfigureAwait(true);
+ // Wait that the icon updates its size and maybe its color theme.
+ await Task.WhenAny(iconSizeUpdatedTask.Task, Task.Delay(500)).ConfigureAwait(true);
- if (imageIcon is not null)
- {
- imageIcon.UnregisterPropertyChangedCallback(ImageIcon.SourceProperty, registrationToken);
- }
+ if (imageIcon is not null)
+ {
+ imageIcon.UnregisterPropertyChangedCallback(ImageIcon.SourceProperty, registrationToken);
+ }
- ThreadHelper.ThrowIfNotOnUIThread();
+ ThreadHelper.ThrowIfNotOnUIThread();
- // Create an image from the canvas.
- var resultBitmap = new RenderTargetBitmap();
- await resultBitmap.RenderAsync(container);
+ // Create an image from the canvas.
+ var resultBitmap = new RenderTargetBitmap();
+ await resultBitmap.RenderAsync(container);
- ((Grid)((Page)((Frame)Window.Current.Content).Content).Content).Children.Remove(container);
+ ((Grid)((Page)((Frame)Window.Current.Content).Content).Content).Children.Remove(container);
- ThreadHelper.ThrowIfNotOnUIThread();
+ ThreadHelper.ThrowIfNotOnUIThread();
- // Save the image on the hard drive.
- IBuffer pixelBuffer = await resultBitmap.GetPixelsAsync();
- byte[] pixels = pixelBuffer.ToArray();
- var displayInformation = DisplayInformation.GetForCurrentView();
- StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync($"{toolProvider.Metadata.ProtocolName}\\{inputFileName}.png", CreationCollisionOption.ReplaceExisting);
+ // Save the image on the hard drive.
+ IBuffer pixelBuffer = await resultBitmap.GetPixelsAsync();
+ byte[] pixels = pixelBuffer.ToArray();
+ var displayInformation = DisplayInformation.GetForCurrentView();
+ StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync($"{toolProvider.Metadata.ProtocolName}\\{tileIconSizeDefinition.IconName}.png", CreationCollisionOption.ReplaceExisting);
- ThreadHelper.ThrowIfNotOnUIThread();
+ ThreadHelper.ThrowIfNotOnUIThread();
- using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
- {
- BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
- encoder.SetPixelData(
- BitmapPixelFormat.Bgra8,
- BitmapAlphaMode.Straight,
- (uint)resultBitmap.PixelWidth,
- (uint)resultBitmap.PixelHeight,
- displayInformation.RawDpiX,
- displayInformation.RawDpiY,
- pixels);
-
- await encoder.FlushAsync();
+ using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
+ {
+ BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
+ encoder.SetPixelData(
+ BitmapPixelFormat.Bgra8,
+ BitmapAlphaMode.Straight,
+ (uint)resultBitmap.PixelWidth,
+ (uint)resultBitmap.PixelHeight,
+ displayInformation.RawDpiX,
+ displayInformation.RawDpiY,
+ pixels);
+
+ await encoder.FlushAsync();
+ }
}
+
+ return tileIconSizeDefinition;
}
+ catch (Exception ex)
+ {
+ Logger.LogFault("Generate tile icon", ex, $"Target size: {tileIconSizeDefinition.Size}; Tool icon ratio: {tileIconSizeDefinition.ToolIconRatio}; Input file name: {tileIconSizeDefinition.IconName}");
+ }
+
+ return null;
}
}
}
diff --git a/src/dev/impl/DevToys/LanguageManager.cs b/src/dev/impl/DevToys/LanguageManager.cs
index 50ac4a401..73a3d7a2f 100644
--- a/src/dev/impl/DevToys/LanguageManager.cs
+++ b/src/dev/impl/DevToys/LanguageManager.cs
@@ -912,6 +912,11 @@ namespace DevToys
/// </summary>
public string PinToolToStart => _resources.GetString("PinToolToStart");
+ /// <summary>
+ /// Gets the resource PinToolToStartProblem.
+ /// </summary>
+ public string PinToolToStartProblem => _resources.GetString("PinToolToStartProblem");
+
/// <summary>
/// Gets the resource Search.
/// </summary>
diff --git a/src/dev/impl/DevToys/Strings/cs-CZ/Common.resw b/src/dev/impl/DevToys/Strings/cs-CZ/Common.resw
index b4d9e275c..14189c9d3 100644
--- a/src/dev/impl/DevToys/Strings/cs-CZ/Common.resw
+++ b/src/dev/impl/DevToys/Strings/cs-CZ/Common.resw
@@ -162,6 +162,12 @@
<data name="ToggleSwitchOn" xml:space="preserve">
<value>Zapnuto</value>
</data>
+ <data name="UnableOpenFile" xml:space="preserve">
+ <value>Unable to open this file</value>
+ </data>
+ <data name="UnableOpenFileDescription" xml:space="preserve">
+ <value>Unable to load the file '{0}'. For more details, please check the log.</value>
+ </data>
<data name="Undo" xml:space="preserve">
<value>Vrátit zpět</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/cs-CZ/MainPage.resw b/src/dev/impl/DevToys/Strings/cs-CZ/MainPage.resw
index 6fe66fd8c..27b1e04bc 100644
--- a/src/dev/impl/DevToys/Strings/cs-CZ/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/cs-CZ/MainPage.resw
@@ -151,6 +151,9 @@
<data name="PinToolToStart" xml:space="preserve">
<value>Pin tool to Start</value>
</data>
+ <data name="PinToolToStartProblem" xml:space="preserve">
+ <value>Unable to pin the tool to start. For more details, please check the log.</value>
+ </data>
<data name="Search" xml:space="preserve">
<value>Hledat nástroje...</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/en-US/MainPage.resw b/src/dev/impl/DevToys/Strings/en-US/MainPage.resw
index b33f4d116..cd4e2e2c4 100644
--- a/src/dev/impl/DevToys/Strings/en-US/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/en-US/MainPage.resw
@@ -151,6 +151,9 @@
<data name="PinToolToStart" xml:space="preserve">
<value>Pin tool to Start</value>
</data>
+ <data name="PinToolToStartProblem" xml:space="preserve">
+ <value>Unable to pin the tool to start. For more details, please check the log.</value>
+ </data>
<data name="Search" xml:space="preserve">
<value>Type to search for tools...</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/fr-FR/Common.resw b/src/dev/impl/DevToys/Strings/fr-FR/Common.resw
index 299e15d45..7702e91a9 100644
--- a/src/dev/impl/DevToys/Strings/fr-FR/Common.resw
+++ b/src/dev/impl/DevToys/Strings/fr-FR/Common.resw
@@ -162,6 +162,12 @@
<data name="ToggleSwitchOn" xml:space="preserve">
<value>Activé</value>
</data>
+ <data name="UnableOpenFile" xml:space="preserve">
+ <value>Impossible d’ouvrir ce fichier</value>
+ </data>
+ <data name="UnableOpenFileDescription" xml:space="preserve">
+ <value>Impossible de charger le fichier '{0}'. Pour plus de détails, veuillez consulter les logs.</value>
+ </data>
<data name="Undo" xml:space="preserve">
<value>Annuler</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/fr-FR/MainPage.resw b/src/dev/impl/DevToys/Strings/fr-FR/MainPage.resw
index a26a28bb1..398f28319 100644
--- a/src/dev/impl/DevToys/Strings/fr-FR/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/fr-FR/MainPage.resw
@@ -151,6 +151,9 @@
<data name="PinToolToStart" xml:space="preserve">
<value>Épingler à l'écran de démarrage</value>
</data>
+ <data name="PinToolToStartProblem" xml:space="preserve">
+ <value>Impossible d'épingler l'outil à l'écran de démarrage. Pour plus de détails, veuillez consulter les logs.</value>
+ </data>
<data name="Search" xml:space="preserve">
<value>Taper pour recherche un outil...</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/pl-PL/Common.resw b/src/dev/impl/DevToys/Strings/pl-PL/Common.resw
index ec01ade21..54da816cf 100644
--- a/src/dev/impl/DevToys/Strings/pl-PL/Common.resw
+++ b/src/dev/impl/DevToys/Strings/pl-PL/Common.resw
@@ -162,6 +162,12 @@
<data name="ToggleSwitchOn" xml:space="preserve">
<value>Właczone</value>
</data>
+ <data name="UnableOpenFile" xml:space="preserve">
+ <value>Unable to open this file</value>
+ </data>
+ <data name="UnableOpenFileDescription" xml:space="preserve">
+ <value>Unable to load the file '{0}'. For more details, please check the log.</value>
+ </data>
<data name="Undo" xml:space="preserve">
<value>Cofnij</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/pl-PL/MainPage.resw b/src/dev/impl/DevToys/Strings/pl-PL/MainPage.resw
index 65a54d9dc..0be72e46c 100644
--- a/src/dev/impl/DevToys/Strings/pl-PL/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/pl-PL/MainPage.resw
@@ -151,6 +151,9 @@
<data name="PinToolToStart" xml:space="preserve">
<value>Pin tool to Start</value>
</data>
+ <data name="PinToolToStartProblem" xml:space="preserve">
+ <value>Unable to pin the tool to start. For more details, please check the log.</value>
+ </data>
<data name="Search" xml:space="preserve">
<value>Wpisz, aby wyszukać narzędzia...</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/ru-RU/Common.resw b/src/dev/impl/DevToys/Strings/ru-RU/Common.resw
index 3295b99b8..44721fde0 100644
--- a/src/dev/impl/DevToys/Strings/ru-RU/Common.resw
+++ b/src/dev/impl/DevToys/Strings/ru-RU/Common.resw
@@ -162,6 +162,12 @@
<data name="ToggleSwitchOn" xml:space="preserve">
<value>Вкл.</value>
</data>
+ <data name="UnableOpenFile" xml:space="preserve">
+ <value>Unable to open this file</value>
+ </data>
+ <data name="UnableOpenFileDescription" xml:space="preserve">
+ <value>Unable to load the file '{0}'. For more details, please check the log.</value>
+ </data>
<data name="Undo" xml:space="preserve">
<value>Отменить</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/ru-RU/MainPage.resw b/src/dev/impl/DevToys/Strings/ru-RU/MainPage.resw
index 976140d08..b4bb060a7 100644
--- a/src/dev/impl/DevToys/Strings/ru-RU/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/ru-RU/MainPage.resw
@@ -151,6 +151,9 @@
<data name="PinToolToStart" xml:space="preserve">
<value>Pin tool to Start</value>
</data>
+ <data name="PinToolToStartProblem" xml:space="preserve">
+ <value>Unable to pin the tool to start. For more details, please check the log.</value>
+ </data>
<data name="Search" xml:space="preserve">
<value>Найти инструмент</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/zh-CN/Common.resw b/src/dev/impl/DevToys/Strings/zh-CN/Common.resw
index ac55970bb..ff82ae2eb 100644
--- a/src/dev/impl/DevToys/Strings/zh-CN/Common.resw
+++ b/src/dev/impl/DevToys/Strings/zh-CN/Common.resw
@@ -162,6 +162,12 @@
<data name="ToggleSwitchOn" xml:space="preserve">
<value>开</value>
</data>
+ <data name="UnableOpenFile" xml:space="preserve">
+ <value>Unable to open this file</value>
+ </data>
+ <data name="UnableOpenFileDescription" xml:space="preserve">
+ <value>Unable to load the file '{0}'. For more details, please check the log.</value>
+ </data>
<data name="Undo" xml:space="preserve">
<value>撤销</value>
</data>
diff --git a/src/dev/impl/DevToys/Strings/zh-CN/MainPage.resw b/src/dev/impl/DevToys/Strings/zh-CN/MainPage.resw
index 7d52693b0..84abec1e5 100644
--- a/src/dev/impl/DevToys/Strings/zh-CN/MainPage.resw
+++ b/src/dev/impl/DevToys/Strings/zh-CN/MainPage.resw
@@ -151,6 +151,9 @@
<data name="PinToolToStart" xml:space="preserve">
<value>Pin tool to Start</value>
</data>
+ <data name="PinToolToStartProblem" xml:space="preserve">
+ <value>Unable to pin the tool to start. For more details, please check the log.</value>
+ </data>
<data name="Search" xml:space="preserve">
<value>搜索工具…</value>
</data>
diff --git a/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs b/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
index bcd13eb09..18c8bb981 100644
--- a/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
+++ b/src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
@@ -48,6 +48,7 @@ namespace DevToys.ViewModels
private readonly ISettingsProvider _settingsProvider;
private readonly INotificationService _notificationService;
private readonly IMarketingService _marketingService;
+ private readonly IWindowManager _windowManager;
private readonly DisposableSempahore _sempahore = new();
private readonly Task _menuInitializationTask;
@@ -178,7 +179,8 @@ namespace DevToys.ViewModels
IUriActivationProtocolService launchProtocolService,
ISettingsProvider settingsProvider,
INotificationService notificationService,
- IMarketingService marketingService)
+ IMarketingService marketingService,
+ IWindowManager windowManager)
{
_clipboard = clipboard;
_toolProviderFactory = toolProviderFactory;
@@ -186,6 +188,7 @@ namespace DevToys.ViewModels
_settingsProvider = settingsProvider;
_notificationService = notificationService;
_marketingService = marketingService;
+ _windowManager = windowManager;
TitleBar = titleBar;
OpenToolInNewWindowCommand = new AsyncRelayCommand<ToolProviderMetadata>(ExecuteOpenToolInNewWindowCommandAsync);
@@ -234,7 +237,13 @@ namespace DevToys.ViewModels
IEnumerable<MatchedToolProvider> toolProviders = _toolProviderFactory.GetAllTools();
MatchedToolProvider toolProvider = toolProviders.First(tool => tool.Metadata == metadata);
- await _launchProtocolService.PinToolToStart(toolProvider);
+ if (!await _launchProtocolService.PinToolToStart(toolProvider))
+ {
+ if (!await _windowManager.ShowContentDialogAsync(Strings.PinToolToStartProblem, LanguageManager.Instance.Common.Ok, LanguageManager.Instance.Settings.OpenLogs))
+ {
+ await Logger.OpenLogsAsync();
+ }
+ }
}
catch (Exception ex)
{