Fixed icon updates not working correctly

This commit is contained in:
Ray 2024-08-04 04:11:19 +01:00
parent 0a7bf62bff
commit ce54eb7ce4
3 changed files with 32 additions and 28 deletions

View File

@ -55,9 +55,12 @@ namespace FizzyLauncher
try
{
if (model.Icon.Width > 16)
if (model.Icon != null)
{
model.Icon = RyzStudio.Drawing.ImageEditor.Resize(model.Icon, 16, 16);
if (model.Icon.Width > 16)
{
model.Icon = RyzStudio.Drawing.ImageEditor.Resize(model.Icon, 16, 16);
}
}
pictureBox1.Image = model.Icon;
@ -206,6 +209,7 @@ namespace FizzyLauncher
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBox1.TabIndex = 201;
pictureBox1.TabStop = false;
pictureBox1.MouseClick += pictureBox1_MouseClick;
pictureBox1.MouseDoubleClick += pictureBox1_MouseDoubleClick;
//
// textBox3
@ -362,6 +366,14 @@ namespace FizzyLauncher
}
}
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
pictureBox1.Image = null;
}
}
private async Task InvalidateWebPage(string url, bool updateTitle, bool updateDescription, bool updateIcon)
{
if (string.IsNullOrWhiteSpace(url))
@ -403,10 +415,12 @@ namespace FizzyLauncher
try
{
pictureBox1.Image = await _webProvider.RetrieveImage(document);
if (pictureBox1.Image.Width > 16)
if (pictureBox1.Image != null)
{
pictureBox1.Image = RyzStudio.Drawing.ImageEditor.Resize(pictureBox1.Image, 16, 16);
if (pictureBox1.Image.Width > 16)
{
pictureBox1.Image = RyzStudio.Drawing.ImageEditor.Resize(pictureBox1.Image, 16, 16);
}
}
}
catch (Exception)

View File

@ -361,14 +361,12 @@ namespace FizzyLauncher
try
{
var image = await _webProvider.RetrieveImage(document);
if (image == null)
if (image != null)
{
continue;
}
if (image.Width > 16)
{
image = RyzStudio.Drawing.ImageEditor.Resize(image, 16, 16);
if (image.Width > 16)
{
image = RyzStudio.Drawing.ImageEditor.Resize(image, 16, 16);
}
}
newModel.Icon = image;

View File

@ -416,36 +416,28 @@ namespace RyzStudio.Windows.Forms
return;
}
var iconIndex = (int)NodeIcon.Default;
var iconKey = "default";
// Update custom favicon
var iconKey = model.Id.ToString();
if (!string.IsNullOrWhiteSpace(iconKey))
var key = model.Id.ToString();
if (!string.IsNullOrWhiteSpace(key))
{
UIControl.Invoke(this, (x) =>
{
if (this.ImageList.Images.ContainsKey(iconKey))
{
this.ImageList.Images.RemoveByKey(iconKey);
}
});
if (model.Icon != null)
{
UIControl.Invoke(this, (x) =>
{
this.ImageList.Images.Add(iconKey, model.Icon);
this.ImageList.Images.Add(key, model.Icon);
});
iconIndex = this.ImageList.Images.IndexOfKey(iconKey);
iconKey = key;
}
}
UIControl.Invoke(this, (x) =>
{
node.Text = model.Title;
node.ImageIndex = iconIndex;
node.SelectedImageIndex = iconIndex;
node.ImageKey = iconKey;
node.SelectedImageKey = iconKey;
node.Tag = model;
node.ToolTipText = model.ToString();
});
@ -462,7 +454,7 @@ namespace RyzStudio.Windows.Forms
this.ImageList.Images.Add(Resources.hexagon);
this.ImageList.Images.Add(Resources.folder);
this.ImageList.Images.Add(Resources.folder_explore);
this.ImageList.Images.Add(Resources.file_text);
this.ImageList.Images.Add("default", Resources.file_text);
});
}