Skip to content

Commit b68b299

Browse files
committed
Support enable favorite icons for firefox bookmarks
1 parent f982d80 commit b68b299

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,33 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
4141
if (string.IsNullOrEmpty(placesPath) || !File.Exists(placesPath))
4242
return bookmarks;
4343

44+
// Try to register file monitoring
45+
try
46+
{
47+
Main.RegisterBookmarkFile(placesPath);
48+
}
49+
catch (Exception ex)
50+
{
51+
Main._context.API.LogException(ClassName, $"Failed to register Firefox bookmark file monitoring: {placesPath}", ex);
52+
return bookmarks;
53+
}
54+
4455
var tempDbPath = Path.Combine(_faviconCacheDir, $"tempplaces_{Guid.NewGuid()}.sqlite");
4556

4657
try
4758
{
48-
// Try to register file monitoring
49-
try
50-
{
51-
Main.RegisterBookmarkFile(placesPath);
52-
}
53-
catch (Exception ex)
54-
{
55-
Main._context.API.LogException(ClassName, $"Failed to register Firefox bookmark file monitoring: {placesPath}", ex);
56-
}
57-
5859
// Use a copy to avoid lock issues with the original file
5960
File.Copy(placesPath, tempDbPath, true);
6061

61-
// Connect to database and execute query
62+
// Create the connection string and init the connection
6263
string dbPath = string.Format(DbPathFormat, tempDbPath);
6364
using var dbConnection = new SqliteConnection(dbPath);
65+
66+
// Open connection to the database file and execute the query
6467
dbConnection.Open();
6568
var reader = new SqliteCommand(QueryAllBookmarks, dbConnection).ExecuteReader();
6669

67-
// Create bookmark list
70+
// Get results in List<Bookmark> format
6871
bookmarks = reader
6972
.Select(
7073
x => new Bookmark(
@@ -75,12 +78,16 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
7578
)
7679
.ToList();
7780

78-
// Path to favicon database
79-
var faviconDbPath = Path.Combine(Path.GetDirectoryName(placesPath), "favicons.sqlite");
80-
if (File.Exists(faviconDbPath))
81+
// Load favicons after loading bookmarks
82+
if (Main._settings.EnableFavoriteIcons)
8183
{
82-
LoadFaviconsFromDb(faviconDbPath, bookmarks);
84+
var faviconDbPath = Path.Combine(Path.GetDirectoryName(placesPath), "favicons.sqlite");
85+
if (File.Exists(faviconDbPath))
86+
{
87+
LoadFaviconsFromDb(faviconDbPath, bookmarks);
88+
}
8389
}
90+
8491
// https://github.com/dotnet/efcore/issues/26580
8592
SqliteConnection.ClearPool(dbConnection);
8693
dbConnection.Close();

0 commit comments

Comments
 (0)