Skip to content

Commit ba0205f

Browse files
committed
Force save favicon icons & Fix svg save issue
1 parent 4f24646 commit ba0205f

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,9 @@ ORDER BY b.width DESC
177177
if (imageData is not { Length: > 0 })
178178
continue;
179179

180-
var faviconPath = Path.Combine(_faviconCacheDir, $"{domain}_{iconId}.png");
181-
if (!File.Exists(faviconPath))
182-
{
183-
SaveBitmapData(imageData, faviconPath);
184-
}
180+
var faviconPath = Path.Combine(_faviconCacheDir, $"chromium_{domain}_{iconId}.png");
181+
SaveBitmapData(imageData, faviconPath);
182+
185183
bookmark.FaviconPath = faviconPath;
186184
}
187185
catch (Exception ex)

Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,16 @@ ORDER BY i.width DESC -- Select largest icon available
155155
if (imageData is not { Length: > 0 })
156156
continue;
157157

158-
var faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}.png");
159-
160-
if (!File.Exists(faviconPath))
158+
string faviconPath;
159+
if (IsSvgData(imageData))
160+
{
161+
faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}.svg");
162+
}
163+
else
161164
{
162-
SaveBitmapData(imageData, faviconPath);
165+
faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}.png");
163166
}
167+
SaveBitmapData(imageData, faviconPath);
164168

165169
bookmark.FaviconPath = faviconPath;
166170
}
@@ -201,6 +205,15 @@ private static void SaveBitmapData(byte[] imageData, string outputPath)
201205
Main._context.API.LogException(ClassName, $"Failed to save image: {outputPath}", ex);
202206
}
203207
}
208+
209+
private static bool IsSvgData(byte[] data)
210+
{
211+
if (data.Length < 5)
212+
return false;
213+
string start = System.Text.Encoding.ASCII.GetString(data, 0, Math.Min(100, data.Length));
214+
return start.Contains("<svg") ||
215+
(start.StartsWith("<?xml") && start.Contains("<svg"));
216+
}
204217
}
205218

206219
public class FirefoxBookmarkLoader : FirefoxBookmarkLoaderBase

0 commit comments

Comments
 (0)