From 2148f5a089a45f22dc6db65c32af5d9cd155e6c9 Mon Sep 17 00:00:00 2001 From: Zain Gill Date: Wed, 19 Mar 2025 07:08:33 -0600 Subject: [PATCH] Implemented suggested changes for PR#3079 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR is based on #3079 Show favicons as Bookmarks icons, originally by @z1nc0r3. Since it seems inactive, I’ve picked it up please let me know if anything is wrong with it or if additional changes need to be made. --- .../Main.cs | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs index a48d70f2d46..363cee1b3ac 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs @@ -19,6 +19,8 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex private static List _cachedBookmarks = new List(); + private static Dictionary faviconCache = new Dictionary(); + private static Settings _settings; private static bool _initialized = false; @@ -68,7 +70,7 @@ public List Query(Query query) { Title = c.Name, SubTitle = c.Url, - IcoPath = @"Images\bookmark.png", + IcoPath = GetFaviconPath(c.Url), Score = BookmarkLoader.MatchProgram(c, param).Score, Action = _ => { @@ -90,7 +92,7 @@ public List Query(Query query) { Title = c.Name, SubTitle = c.Url, - IcoPath = @"Images\bookmark.png", + IcoPath = GetFaviconPath(c.Url), Score = 5, Action = _ => { @@ -104,6 +106,35 @@ public List Query(Query query) } } + private string GetFaviconPath(string url) + { + try + { + var uri = new Uri(url); + var domain = uri.Host; + + if (faviconCache.TryGetValue(domain, out var cachedFaviconUrl)) + { + return cachedFaviconUrl; + } + else + { + var encodedDomain = Uri.EscapeDataString(domain); + var faviconUrl = $"https://www.google.com/s2/favicons?domain={encodedDomain}&sz=64"; + + // Store the favicon URL in the cache + faviconCache[domain] = faviconUrl; + return faviconUrl; + } + } + catch (Exception ex) + { + Log.Exception("Main", "Failed to generate favicon URL", ex); + + // Fallback to default icon + return @"Images\bookmark.png"; + } + } private static Channel _refreshQueue = Channel.CreateBounded(1);