Skip to content

Commit 2148f5a

Browse files
committed
Implemented suggested changes for PR#3079
This PR is based on Flow-Launcher#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.
1 parent e28a69c commit 2148f5a

File tree

1 file changed

+33
-2
lines changed
  • Plugins/Flow.Launcher.Plugin.BrowserBookmark

1 file changed

+33
-2
lines changed

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

+33-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
1919

2020
private static List<Bookmark> _cachedBookmarks = new List<Bookmark>();
2121

22+
private static Dictionary<string, string> faviconCache = new Dictionary<string, string>();
23+
2224
private static Settings _settings;
2325

2426
private static bool _initialized = false;
@@ -68,7 +70,7 @@ public List<Result> Query(Query query)
6870
{
6971
Title = c.Name,
7072
SubTitle = c.Url,
71-
IcoPath = @"Images\bookmark.png",
73+
IcoPath = GetFaviconPath(c.Url),
7274
Score = BookmarkLoader.MatchProgram(c, param).Score,
7375
Action = _ =>
7476
{
@@ -90,7 +92,7 @@ public List<Result> Query(Query query)
9092
{
9193
Title = c.Name,
9294
SubTitle = c.Url,
93-
IcoPath = @"Images\bookmark.png",
95+
IcoPath = GetFaviconPath(c.Url),
9496
Score = 5,
9597
Action = _ =>
9698
{
@@ -104,6 +106,35 @@ public List<Result> Query(Query query)
104106
}
105107
}
106108

109+
private string GetFaviconPath(string url)
110+
{
111+
try
112+
{
113+
var uri = new Uri(url);
114+
var domain = uri.Host;
115+
116+
if (faviconCache.TryGetValue(domain, out var cachedFaviconUrl))
117+
{
118+
return cachedFaviconUrl;
119+
}
120+
else
121+
{
122+
var encodedDomain = Uri.EscapeDataString(domain);
123+
var faviconUrl = $"https://www.google.com/s2/favicons?domain={encodedDomain}&sz=64";
124+
125+
// Store the favicon URL in the cache
126+
faviconCache[domain] = faviconUrl;
127+
return faviconUrl;
128+
}
129+
}
130+
catch (Exception ex)
131+
{
132+
Log.Exception("Main", "Failed to generate favicon URL", ex);
133+
134+
// Fallback to default icon
135+
return @"Images\bookmark.png";
136+
}
137+
}
107138

108139
private static Channel<byte> _refreshQueue = Channel.CreateBounded<byte>(1);
109140

0 commit comments

Comments
 (0)