Skip to content

Commit 31fd6fd

Browse files
committed
review feedback
1 parent 15a7a58 commit 31fd6fd

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private string SetupTempDirectory()
6767
public List<Result> Query(Query query)
6868
{
6969
var search = query.Search.Trim();
70-
var bookmarks = _bookmarks; // use a local copy
70+
var bookmarks = Volatile.Read(ref _bookmarks); // use a local copy with proper memory barrier
7171

7272
if (!string.IsNullOrEmpty(search))
7373
{

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,22 @@ public async IAsyncEnumerable<Bookmark> GetBookmarksAsync([EnumeratorCancellatio
5555
bookmarks.AddRange(EnumerateBookmarks(rootElement, source, profilePath));
5656
}
5757
}
58+
catch (IOException ex)
59+
{
60+
_logException(nameof(ChromiumBookmarkLoader), $"IO error reading {_browserName} bookmarks: {bookmarkPath}", ex);
61+
}
62+
catch (UnauthorizedAccessException ex)
63+
{
64+
_logException(nameof(ChromiumBookmarkLoader), $"Unauthorized to read {_browserName} bookmarks: {bookmarkPath}", ex);
65+
}
5866
catch (JsonException ex)
5967
{
6068
_logException(nameof(ChromiumBookmarkLoader), $"Failed to parse bookmarks file for {_browserName}: {bookmarkPath}", ex);
6169
}
70+
catch (Exception ex)
71+
{
72+
_logException(nameof(ChromiumBookmarkLoader), $"Unexpected error loading {_browserName} bookmarks: {bookmarkPath}", ex);
73+
}
6274

6375
foreach (var bookmark in bookmarks)
6476
{

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Services/FaviconService.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,15 @@ private static string GetCachePath(string url, string cacheDir)
240240

241241
private static FetchResult SelectBestFavicon(FetchResult icoResult, FetchResult htmlResult)
242242
{
243-
if (htmlResult.Size >= ImageConverter.TargetIconSize) return htmlResult;
244-
if (icoResult.Size >= ImageConverter.TargetIconSize) return icoResult;
245-
if (htmlResult.Size > icoResult.Size) return htmlResult;
246-
if (icoResult.Size >= 0) return icoResult;
247-
if (htmlResult.Size >= 0) return htmlResult;
243+
var htmlValid = htmlResult.PngData != null;
244+
var icoValid = icoResult.PngData != null;
245+
246+
if (htmlValid && htmlResult.Size >= ImageConverter.TargetIconSize) return htmlResult;
247+
if (icoValid && icoResult.Size >= ImageConverter.TargetIconSize) return icoResult;
248+
249+
if (htmlValid && icoValid) return htmlResult.Size >= icoResult.Size ? htmlResult : icoResult;
250+
if (htmlValid) return htmlResult;
251+
if (icoValid) return icoResult;
248252
return default;
249253
}
250254

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Services/FaviconWebClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public FaviconWebClient(PluginInitContext context)
4646
var buffer = new char[4096];
4747
int charsRead;
4848
var totalCharsRead = 0;
49-
const int maxCharsToRead = 500 * 1024;
49+
const int maxHeadChars = 150 * 1024;
5050

51-
while (!token.IsCancellationRequested && (charsRead = await reader.ReadAsync(buffer, 0, buffer.Length)) > 0 && totalCharsRead < maxCharsToRead)
51+
while (!token.IsCancellationRequested && (charsRead = await reader.ReadAsync(buffer, 0, buffer.Length)) > 0 && totalCharsRead < maxHeadChars)
5252
{
5353
contentBuilder.Append(buffer, 0, charsRead);
5454
totalCharsRead += charsRead;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ public async IAsyncEnumerable<Bookmark> GetBookmarksAsync([EnumeratorCancellatio
5757
try
5858
{
5959
tempDbPath = Path.Combine(_tempPath, $"ff_places_{Guid.NewGuid()}.sqlite");
60+
var walPath = _placesPath + "-wal";
61+
var shmPath = _placesPath + "-shm";
62+
6063
File.Copy(_placesPath, tempDbPath, true);
64+
if (File.Exists(walPath))
65+
File.Copy(walPath, tempDbPath + "-wal", true);
66+
if (File.Exists(shmPath))
67+
File.Copy(shmPath, tempDbPath + "-shm", true);
68+
6169
await ReadBookmarksFromDb(tempDbPath, bookmarks, cancellationToken);
6270
}
6371
catch (Exception copyEx)

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Services/LocalFaviconExtractor.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ public LocalFaviconExtractor(PluginInitContext context, string tempPath)
2222

2323
public async Task<byte[]?> GetFaviconDataAsync(Bookmark bookmark, CancellationToken token)
2424
{
25-
return bookmark.Source switch
25+
var profilePath = bookmark.ProfilePath;
26+
if (!string.IsNullOrEmpty(profilePath))
2627
{
27-
var s when s.Contains("Firefox") => await GetFirefoxFaviconAsync(bookmark, token),
28-
_ => await GetChromiumFaviconAsync(bookmark, token) // Default to Chromium
29-
};
28+
if (File.Exists(Path.Combine(profilePath, "favicons.sqlite")))
29+
return await GetFirefoxFaviconAsync(bookmark, token);
30+
31+
if (File.Exists(Path.Combine(profilePath, "Favicons")))
32+
return await GetChromiumFaviconAsync(bookmark, token);
33+
}
34+
35+
return bookmark.Source?.IndexOf("Firefox", StringComparison.OrdinalIgnoreCase) >= 0
36+
? await GetFirefoxFaviconAsync(bookmark, token)
37+
: await GetChromiumFaviconAsync(bookmark, token);
3038
}
3139

3240
private Task<byte[]?> GetChromiumFaviconAsync(Bookmark bookmark, CancellationToken token)

0 commit comments

Comments
 (0)