Skip to content

Portable Tool for an Ideal Windows Setup

upd. toolsetcard (squareIcon for web)

Greedeks0a97dba0e48c
diff --git a/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml b/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml
index ba864e53..fdc1f315 100644
--- a/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml
+++ b/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml
@@ -25,18 +25,53 @@
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<Grid Width="25" Height="25" Margin="0,5,0,0">
- <Border BorderBrush="{StaticResource Brush_Separator}" CornerRadius="50" Width="25" Height="25" HorizontalAlignment="Left" VerticalAlignment="Center">
- <Border CornerRadius="50">
- <Border.Background>
- <ImageBrush ImageSource="{Binding AuthorIcon, RelativeSource={RelativeSource AncestorType=local:ToolsetCard}}" Stretch="Fill"/>
- </Border.Background>
- </Border>
+ <Border BorderBrush="{StaticResource Brush_Separator}" BorderThickness="0.5" Width="25" Height="25" HorizontalAlignment="Left" VerticalAlignment="Center">
+ <Border.Style>
+ <Style TargetType="Border">
+ <Setter Property="CornerRadius" Value="50"/>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding IsSquareIcon, RelativeSource={RelativeSource AncestorType=local:ToolsetCard}}" Value="True">
+ <Setter Property="CornerRadius" Value="0"/>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </Border.Style>
+ <Border.Background>
+ <ImageBrush ImageSource="{Binding AuthorIcon, RelativeSource={RelativeSource AncestorType=local:ToolsetCard}}" Stretch="Uniform"/>
+ </Border.Background>
</Border>
+
<Path Stroke="{StaticResource Brush_Separator}" StrokeThickness="0.5" Stretch="Uniform">
+ <Path.Style>
+ <Style TargetType="Path">
+ <Setter Property="Visibility" Value="Visible"/>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding IsSquareIcon, RelativeSource={RelativeSource AncestorType=local:ToolsetCard}}" Value="True">
+ <Setter Property="Visibility" Value="Collapsed"/>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </Path.Style>
<Path.Data>
<EllipseGeometry RadiusX="5" RadiusY="5"/>
</Path.Data>
</Path>
+
+ <Path Stroke="{StaticResource Brush_Separator}" StrokeThickness="0.5" Stretch="Uniform">
+ <Path.Style>
+ <Style TargetType="Path">
+ <Setter Property="Visibility" Value="Collapsed"/>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding IsSquareIcon, RelativeSource={RelativeSource AncestorType=local:ToolsetCard}}" Value="True">
+ <Setter Property="Visibility" Value="Visible"/>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </Path.Style>
+ <Path.Data>
+ <RectangleGeometry Rect="0,0,10,10"/>
+ </Path.Data>
+ </Path>
</Grid>
<TextBlock Style="{StaticResource TextDefault}" Foreground="{StaticResource Brush_Inactive}" Text="{Binding AuthorName, RelativeSource={RelativeSource AncestorType=local:ToolsetCard}}" VerticalAlignment="Center" Margin="5,0,0,0"/>
diff --git a/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml.cs b/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml.cs
index 406135c7..28f79418 100644
--- a/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml.cs
+++ b/.Source/GTweak/Assets/UserControls/ToolsetCard.xaml.cs
@@ -20,6 +20,7 @@ namespace GTweak.Assets.UserControls
public static readonly DependencyProperty IsDownloadingProperty = DependencyProperty.Register(nameof(IsDownloading), typeof(bool), typeof(ToolsetCard), new PropertyMetadata(false));
public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register(nameof(Progress), typeof(double), typeof(ToolsetCard), new PropertyMetadata(0.0));
+ public static readonly DependencyProperty IsSquareIconProperty = DependencyProperty.Register(nameof(IsSquareIcon), typeof(bool), typeof(ToolsetCard), new PropertyMetadata(false));
public ImageSource AppIcon
{
@@ -75,6 +76,12 @@ namespace GTweak.Assets.UserControls
set => SetValue(ProgressProperty, value);
}
+ public bool IsSquareIcon
+ {
+ get => (bool)GetValue(IsSquareIconProperty);
+ set => SetValue(IsSquareIconProperty, value);
+ }
+
public ToolsetCard()
{
InitializeComponent();
diff --git a/.Source/GTweak/Core/ViewModel/ToolsetViewModel.cs b/.Source/GTweak/Core/ViewModel/ToolsetViewModel.cs
index 53665bdd..86ea8ee2 100644
--- a/.Source/GTweak/Core/ViewModel/ToolsetViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/ToolsetViewModel.cs
@@ -121,6 +121,7 @@ namespace GTweak.Core.ViewModel
private ImageSource _authorIconSource;
private bool _isDownloading;
private double _progress;
+ private bool _isSquareIcon;
public ToolsetItem(ToolsetModel model)
{
@@ -160,6 +161,12 @@ namespace GTweak.Core.ViewModel
set { _progress = value; OnPropertyChanged(); }
}
+ public bool IsSquareIcon
+ {
+ get => _isSquareIcon;
+ set { _isSquareIcon = value; OnPropertyChanged(); }
+ }
+
public ICommand DownloadCommand { get; }
public ICommand CancelCommand { get; }
@@ -167,14 +174,15 @@ namespace GTweak.Core.ViewModel
{
try
{
+ IsSquareIcon = false;
+
AppIconSource = ToolsetIconManager.GetAppIconFromResource(_model.IconResourceName);
AuthorIconSource = ToolsetIconManager.GetPlaceholder(_model.Group);
- ImageSource realIcon = await ToolsetIconManager.GetAuthorIconAsync(_model.Group, _model.AuthorIconUrl);
- if (realIcon != null)
- {
- AuthorIconSource = realIcon;
- }
+ (ImageSource Image, bool IsFallback) = await ToolsetIconManager.GetAuthorIconAsync(_model.Group, _model.AuthorIconUrl);
+
+ AuthorIconSource = Image;
+ IsSquareIcon = string.Equals(_model.Group, "web", StringComparison.OrdinalIgnoreCase) && !IsFallback;
}
catch (Exception ex)
{
diff --git a/.Source/GTweak/Utilities/Managers/ToolsetIconManager.cs b/.Source/GTweak/Utilities/Managers/ToolsetIconManager.cs
index a0d7cd2d..ee5c8208 100644
--- a/.Source/GTweak/Utilities/Managers/ToolsetIconManager.cs
+++ b/.Source/GTweak/Utilities/Managers/ToolsetIconManager.cs
@@ -17,35 +17,35 @@ namespace GTweak.Utilities.Managers
public static ImageSource GetPlaceholder(string group) => Application.Current.TryFindResource(group.ToLower() == "github" ? "Icon_Git" : "Icon_Website") as ImageSource;
- public static async Task<ImageSource> GetAuthorIconAsync(string group, string authorIconUrlOrDomain)
+ public static async Task<(ImageSource Image, bool IsFallback)> GetAuthorIconAsync(string group, string authorIconUrlOrDomain)
{
if (string.IsNullOrWhiteSpace(authorIconUrlOrDomain))
{
- return GetPlaceholder(group);
+ return (GetPlaceholder(group), true);
}
if (_imageCache.TryGetValue(authorIconUrlOrDomain, out ImageSource cachedImage))
{
- return cachedImage;
+ return (cachedImage, false);
}
string urlToDownload = authorIconUrlOrDomain;
- bool isWeb = group.ToLower() == "web";
+ bool isWeb = string.Equals(group, "web", StringComparison.OrdinalIgnoreCase);
if (isWeb)
{
- urlToDownload = $"https://www.google.com/s2/favicons?domain={authorIconUrlOrDomain}&sz=64";
+ urlToDownload = $"https://www.google.com/s2/favicons?domain={authorIconUrlOrDomain}&sz=48";
}
try
{
- var imageBytes = await _httpClient.GetByteArrayAsync(urlToDownload);
- var image = LoadImage(imageBytes);
+ byte[] imageBytes = await _httpClient.GetByteArrayAsync(urlToDownload);
+ ImageSource image = LoadImage(imageBytes);
if (image != null)
{
_imageCache.TryAdd(authorIconUrlOrDomain, image);
- return image;
+ return (image, false);
}
}
catch
@@ -61,14 +61,14 @@ namespace GTweak.Utilities.Managers
if (image != null)
{
_imageCache.TryAdd(authorIconUrlOrDomain, image);
- return image;
+ return (image, false);
}
}
- catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}
}
- return GetPlaceholder(group);
+ return (GetPlaceholder(group), true);
}
private static ImageSource LoadImage(byte[] imageData)
diff --git a/.Source/GTweak/View/ToolsetView.xaml b/.Source/GTweak/View/ToolsetView.xaml
index b68d550c..338813c0 100644
--- a/.Source/GTweak/View/ToolsetView.xaml
+++ b/.Source/GTweak/View/ToolsetView.xaml
@@ -53,7 +53,7 @@
<ItemsControl.ItemTemplate>
<DataTemplate>
- <uc:ToolsetCard AppName="{Binding AppName}" AppIcon="{Binding AppIconSource}" AuthorName="{Binding AuthorName}" AuthorIcon="{Binding AuthorIconSource}" SourceUrl="{Binding SourceUrl}" DownloadCommand="{Binding DownloadCommand}" CancelCommand="{Binding CancelCommand}" IsDownloading="{Binding IsDownloading}" Progress="{Binding Progress}" />
+ <uc:ToolsetCard AppName="{Binding AppName}" AppIcon="{Binding AppIconSource}" AuthorName="{Binding AuthorName}" AuthorIcon="{Binding AuthorIconSource}" IsSquareIcon="{Binding IsSquareIcon}" SourceUrl="{Binding SourceUrl}" DownloadCommand="{Binding DownloadCommand}" CancelCommand="{Binding CancelCommand}" IsDownloading="{Binding IsDownloading}" Progress="{Binding Progress}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>