From 196c359819b06a48348b2dbace1888e4ad4cb577 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Fri, 3 Feb 2023 13:07:46 +0800 Subject: [PATCH 1/5] Add custom firefox browser location --- .../Commands/BookmarkLoader.cs | 12 +++++-- .../CustomFirefoxBookmarkLoader.cs | 30 ++++++++++++++++++ .../FirefoxBookmarkLoader.cs | 31 +++++++++++++------ .../Models/CustomBrowser.cs | 21 ++++++++++++- 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs index 77d9c64a0ea..bfb611cf7ba 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs @@ -44,11 +44,19 @@ internal static List LoadAllBookmarks(Settings setting) 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(); } } -} \ No newline at end of file +} diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs new file mode 100644 index 00000000000..26e62df5e04 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs @@ -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; + } + + /// + /// Path to places.sqlite + /// + public string BrowserDataPath { get; init; } + + public string BrowserName { get; init; } + + public override List GetBookmarks() + { + return GetBookmarksFromPath(BrowserDataPath); + } + } +} diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs index fc58e40df53..022f2814408 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs @@ -7,8 +7,10 @@ namespace Flow.Launcher.Plugin.BrowserBookmark { - public class FirefoxBookmarkLoader : IBookmarkLoader + public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader { + public abstract List GetBookmarks(); + private const string queryAllBookmarks = @"SELECT moz_places.url, moz_bookmarks.title FROM moz_places INNER JOIN moz_bookmarks ON ( @@ -19,21 +21,18 @@ ORDER BY moz_places.visit_count DESC private const string dbPathFormat = "Data Source ={0};Version=3;New=False;Compress=True;"; - /// - /// Searches the places.sqlite db and returns all bookmarks - /// - public List GetBookmarks() + protected static List 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(); var bookmarkList = new List(); - - 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 @@ public List GetBookmarks() // return results in List 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 + { + /// + /// Searches the places.sqlite db and returns all bookmarks + /// + public override List GetBookmarks() + { + return GetBookmarksFromPath(PlacesPath); + } + /// /// Path to places.sqlite /// diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs index c19de08a446..69bb56e4879 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs @@ -4,6 +4,8 @@ public class CustomBrowser : BaseModel { private string _name; private string _dataDirectoryPath; + private BrowserType browserType = BrowserType.Chromium; + public string Name { get => _name; @@ -13,6 +15,7 @@ public string Name OnPropertyChanged(nameof(Name)); } } + public string DataDirectoryPath { get => _dataDirectoryPath; @@ -22,5 +25,21 @@ public string DataDirectoryPath OnPropertyChanged(nameof(DataDirectoryPath)); } } + + public BrowserType BrowserType + { + get => browserType; + set + { + browserType = value; + OnPropertyChanged(nameof(BrowserType)); + } + } + } + + public enum BrowserType + { + Chromium, + Firefox, } -} \ No newline at end of file +} From fe5da58378d3a7f733220fe3ed0cefebcb513760 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Fri, 3 Feb 2023 16:23:14 +0800 Subject: [PATCH 2/5] Use switch expression for loader --- .../Commands/BookmarkLoader.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs index bfb611cf7ba..d08c05b6ba1 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs @@ -44,15 +44,12 @@ internal static List LoadAllBookmarks(Settings setting) foreach (var browser in setting.CustomChromiumBrowsers) { - IBookmarkLoader loader; - if (browser.BrowserType == BrowserType.Chromium) + IBookmarkLoader loader = browser.BrowserType switch { - loader = new CustomChromiumBookmarkLoader(browser); - } - else - { - loader = new CustomFirefoxBookmarkLoader(browser); - } + BrowserType.Chromium => new CustomChromiumBookmarkLoader(browser), + BrowserType.Firefox => new CustomFirefoxBookmarkLoader(browser), + _ => new CustomChromiumBookmarkLoader(browser), + }; allBookmarks.AddRange(loader.GetBookmarks()); } From c7f3283e3a674b3b6787fe43ed07b55baa692f6d Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Fri, 3 Feb 2023 17:07:33 +0800 Subject: [PATCH 3/5] Add UI to select browser engine --- .../CustomFirefoxBookmarkLoader.cs | 6 +---- .../Languages/en.xaml | 1 + .../Views/CustomBrowserSetting.xaml | 23 ++++++++++++++++++- .../Views/CustomBrowserSetting.xaml.cs | 17 ++++---------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs index 26e62df5e04..c79cf86cb59 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; using Flow.Launcher.Plugin.BrowserBookmark.Models; namespace Flow.Launcher.Plugin.BrowserBookmark diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Languages/en.xaml index 7c88708f502..5dbe925c1cd 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Languages/en.xaml @@ -22,4 +22,5 @@ Add Delete Others + Browser Engine \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml index aff85072844..499d2283449 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Flow.Launcher.Plugin.BrowserBookmark.Models" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ui="clr-namespace:Flow.Launcher.Infrastructure.UI;assembly=Flow.Launcher.Infrastructure" Title="{DynamicResource flowlauncher_plugin_browserbookmark_bookmarkDataSetting}" Width="520" Background="{DynamicResource PopuBGColor}" @@ -79,6 +80,7 @@ + + + + Date: Fri, 3 Feb 2023 17:29:51 +0800 Subject: [PATCH 4/5] Fix folder path --- .../CustomFirefoxBookmarkLoader.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs index c79cf86cb59..82bdc29f54d 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/CustomFirefoxBookmarkLoader.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.IO; using Flow.Launcher.Plugin.BrowserBookmark.Models; namespace Flow.Launcher.Plugin.BrowserBookmark @@ -20,7 +21,7 @@ public CustomFirefoxBookmarkLoader(CustomBrowser browser) public override List GetBookmarks() { - return GetBookmarksFromPath(BrowserDataPath); + return GetBookmarksFromPath(Path.Combine(BrowserDataPath, "places.sqlite")); } } } From a6d3aafe9be695cd76eedc5610bb28b4c508bec0 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Mon, 6 Feb 2023 12:57:55 +0800 Subject: [PATCH 5/5] Add Browser Engine header --- .../Views/SettingsControl.xaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml index 12a84cb5a31..628a9417b2e 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml @@ -46,6 +46,8 @@ Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserName}"/> +