Skip to content

Commit 196c359

Browse files
Add custom firefox browser location
1 parent 2e1c430 commit 196c359

File tree

4 files changed

+81
-13
lines changed

4 files changed

+81
-13
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ internal static List<Bookmark> LoadAllBookmarks(Settings setting)
4444

4545
foreach (var browser in setting.CustomChromiumBrowsers)
4646
{
47-
var loader = new CustomChromiumBookmarkLoader(browser);
47+
IBookmarkLoader loader;
48+
if (browser.BrowserType == BrowserType.Chromium)
49+
{
50+
loader = new CustomChromiumBookmarkLoader(browser);
51+
}
52+
else
53+
{
54+
loader = new CustomFirefoxBookmarkLoader(browser);
55+
}
4856
allBookmarks.AddRange(loader.GetBookmarks());
4957
}
5058

5159
return allBookmarks.Distinct().ToList();
5260
}
5361
}
54-
}
62+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Flow.Launcher.Plugin.BrowserBookmark.Models;
7+
8+
namespace Flow.Launcher.Plugin.BrowserBookmark
9+
{
10+
public class CustomFirefoxBookmarkLoader : FirefoxBookmarkLoaderBase
11+
{
12+
public CustomFirefoxBookmarkLoader(CustomBrowser browser)
13+
{
14+
BrowserName = browser.Name;
15+
BrowserDataPath = browser.DataDirectoryPath;
16+
}
17+
18+
/// <summary>
19+
/// Path to places.sqlite
20+
/// </summary>
21+
public string BrowserDataPath { get; init; }
22+
23+
public string BrowserName { get; init; }
24+
25+
public override List<Bookmark> GetBookmarks()
26+
{
27+
return GetBookmarksFromPath(BrowserDataPath);
28+
}
29+
}
30+
}

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace Flow.Launcher.Plugin.BrowserBookmark
99
{
10-
public class FirefoxBookmarkLoader : IBookmarkLoader
10+
public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
1111
{
12+
public abstract List<Bookmark> GetBookmarks();
13+
1214
private const string queryAllBookmarks = @"SELECT moz_places.url, moz_bookmarks.title
1315
FROM moz_places
1416
INNER JOIN moz_bookmarks ON (
@@ -19,35 +21,44 @@ ORDER BY moz_places.visit_count DESC
1921

2022
private const string dbPathFormat = "Data Source ={0};Version=3;New=False;Compress=True;";
2123

22-
/// <summary>
23-
/// Searches the places.sqlite db and returns all bookmarks
24-
/// </summary>
25-
public List<Bookmark> GetBookmarks()
24+
protected static List<Bookmark> GetBookmarksFromPath(string placesPath)
2625
{
2726
// Return empty list if the places.sqlite file cannot be found
28-
if (string.IsNullOrEmpty(PlacesPath) || !File.Exists(PlacesPath))
27+
if (string.IsNullOrEmpty(placesPath) || !File.Exists(placesPath))
2928
return new List<Bookmark>();
3029

3130
var bookmarkList = new List<Bookmark>();
32-
33-
Main.RegisterBookmarkFile(PlacesPath);
31+
32+
Main.RegisterBookmarkFile(placesPath);
3433

3534
// create the connection string and init the connection
36-
string dbPath = string.Format(dbPathFormat, PlacesPath);
35+
string dbPath = string.Format(dbPathFormat, placesPath);
3736
using var dbConnection = new SQLiteConnection(dbPath);
3837
// Open connection to the database file and execute the query
3938
dbConnection.Open();
4039
var reader = new SQLiteCommand(queryAllBookmarks, dbConnection).ExecuteReader();
4140

4241
// return results in List<Bookmark> format
4342
bookmarkList = reader.Select(
44-
x => new Bookmark(x["title"] is DBNull ? string.Empty : x["title"].ToString(),
43+
x => new Bookmark(x["title"] is DBNull ? string.Empty : x["title"].ToString(),
4544
x["url"].ToString())
4645
).ToList();
4746

4847
return bookmarkList;
4948
}
49+
}
50+
5051

52+
public class FirefoxBookmarkLoader : FirefoxBookmarkLoaderBase
53+
{
54+
/// <summary>
55+
/// Searches the places.sqlite db and returns all bookmarks
56+
/// </summary>
57+
public override List<Bookmark> GetBookmarks()
58+
{
59+
return GetBookmarksFromPath(PlacesPath);
60+
}
61+
5162
/// <summary>
5263
/// Path to places.sqlite
5364
/// </summary>

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ public class CustomBrowser : BaseModel
44
{
55
private string _name;
66
private string _dataDirectoryPath;
7+
private BrowserType browserType = BrowserType.Chromium;
8+
79
public string Name
810
{
911
get => _name;
@@ -13,6 +15,7 @@ public string Name
1315
OnPropertyChanged(nameof(Name));
1416
}
1517
}
18+
1619
public string DataDirectoryPath
1720
{
1821
get => _dataDirectoryPath;
@@ -22,5 +25,21 @@ public string DataDirectoryPath
2225
OnPropertyChanged(nameof(DataDirectoryPath));
2326
}
2427
}
28+
29+
public BrowserType BrowserType
30+
{
31+
get => browserType;
32+
set
33+
{
34+
browserType = value;
35+
OnPropertyChanged(nameof(BrowserType));
36+
}
37+
}
38+
}
39+
40+
public enum BrowserType
41+
{
42+
Chromium,
43+
Firefox,
2544
}
26-
}
45+
}

0 commit comments

Comments
 (0)