Add custom firefox browser location

This commit is contained in:
Vic 2023-02-03 13:07:46 +08:00
parent 2e1c430234
commit 196c359819
4 changed files with 81 additions and 13 deletions

View file

@ -44,11 +44,19 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Commands
foreach (var browser in setting.CustomChromiumBrowsers)
{
var loader = new CustomChromiumBookmarkLoader(browser);
IBookmarkLoader loader;
if (browser.BrowserType == BrowserType.Chromium)
{
loader = new CustomChromiumBookmarkLoader(browser);
}
else
{
loader = new CustomFirefoxBookmarkLoader(browser);
}
allBookmarks.AddRange(loader.GetBookmarks());
}
return allBookmarks.Distinct().ToList();
}
}
}
}

View file

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Flow.Launcher.Plugin.BrowserBookmark.Models;
namespace Flow.Launcher.Plugin.BrowserBookmark
{
public class CustomFirefoxBookmarkLoader : FirefoxBookmarkLoaderBase
{
public CustomFirefoxBookmarkLoader(CustomBrowser browser)
{
BrowserName = browser.Name;
BrowserDataPath = browser.DataDirectoryPath;
}
/// <summary>
/// Path to places.sqlite
/// </summary>
public string BrowserDataPath { get; init; }
public string BrowserName { get; init; }
public override List<Bookmark> GetBookmarks()
{
return GetBookmarksFromPath(BrowserDataPath);
}
}
}

View file

@ -7,8 +7,10 @@ using System.Linq;
namespace Flow.Launcher.Plugin.BrowserBookmark
{
public class FirefoxBookmarkLoader : IBookmarkLoader
public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
{
public abstract List<Bookmark> GetBookmarks();
private const string queryAllBookmarks = @"SELECT moz_places.url, moz_bookmarks.title
FROM moz_places
INNER JOIN moz_bookmarks ON (
@ -19,21 +21,18 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
private const string dbPathFormat = "Data Source ={0};Version=3;New=False;Compress=True;";
/// <summary>
/// Searches the places.sqlite db and returns all bookmarks
/// </summary>
public List<Bookmark> GetBookmarks()
protected static List<Bookmark> GetBookmarksFromPath(string placesPath)
{
// Return empty list if the places.sqlite file cannot be found
if (string.IsNullOrEmpty(PlacesPath) || !File.Exists(PlacesPath))
if (string.IsNullOrEmpty(placesPath) || !File.Exists(placesPath))
return new List<Bookmark>();
var bookmarkList = new List<Bookmark>();
Main.RegisterBookmarkFile(PlacesPath);
Main.RegisterBookmarkFile(placesPath);
// create the connection string and init the connection
string dbPath = string.Format(dbPathFormat, PlacesPath);
string dbPath = string.Format(dbPathFormat, placesPath);
using var dbConnection = new SQLiteConnection(dbPath);
// Open connection to the database file and execute the query
dbConnection.Open();
@ -41,13 +40,25 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
// return results in List<Bookmark> format
bookmarkList = reader.Select(
x => new Bookmark(x["title"] is DBNull ? string.Empty : x["title"].ToString(),
x => new Bookmark(x["title"] is DBNull ? string.Empty : x["title"].ToString(),
x["url"].ToString())
).ToList();
return bookmarkList;
}
}
public class FirefoxBookmarkLoader : FirefoxBookmarkLoaderBase
{
/// <summary>
/// Searches the places.sqlite db and returns all bookmarks
/// </summary>
public override List<Bookmark> GetBookmarks()
{
return GetBookmarksFromPath(PlacesPath);
}
/// <summary>
/// Path to places.sqlite
/// </summary>

View file

@ -4,6 +4,8 @@
{
private string _name;
private string _dataDirectoryPath;
private BrowserType browserType = BrowserType.Chromium;
public string Name
{
get => _name;
@ -13,6 +15,7 @@
OnPropertyChanged(nameof(Name));
}
}
public string DataDirectoryPath
{
get => _dataDirectoryPath;
@ -22,5 +25,21 @@
OnPropertyChanged(nameof(DataDirectoryPath));
}
}
public BrowserType BrowserType
{
get => browserType;
set
{
browserType = value;
OnPropertyChanged(nameof(BrowserType));
}
}
}
}
public enum BrowserType
{
Chromium,
Firefox,
}
}