Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ internal static List<Bookmark> LoadAllBookmarks(Settings setting)

foreach (var browser in setting.CustomChromiumBrowsers)
{
var loader = new CustomChromiumBookmarkLoader(browser);
IBookmarkLoader loader = browser.BrowserType switch
{
BrowserType.Chromium => new CustomChromiumBookmarkLoader(browser),
BrowserType.Firefox => new CustomFirefoxBookmarkLoader(browser),
_ => new CustomChromiumBookmarkLoader(browser),
};
allBookmarks.AddRange(loader.GetBookmarks());
}

return allBookmarks.Distinct().ToList();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.IO;
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(Path.Combine(BrowserDataPath, "places.sqlite"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

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 (
Expand All @@ -19,35 +21,44 @@ ORDER BY moz_places.visit_count DESC

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();
var reader = new SQLiteCommand(queryAllBookmarks, dbConnection).ExecuteReader();

// 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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<system:String x:Key="flowlauncher_plugin_browserbookmark_addBrowserBookmark">Add</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_removeBrowserBookmark">Delete</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_others">Others</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_browserEngine">Browser Engine</system:String>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public class CustomBrowser : BaseModel
{
private string _name;
private string _dataDirectoryPath;
private BrowserType browserType = BrowserType.Chromium;

public string Name
{
get => _name;
Expand All @@ -13,6 +15,7 @@ public string Name
OnPropertyChanged(nameof(Name));
}
}

public string DataDirectoryPath
{
get => _dataDirectoryPath;
Expand All @@ -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,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -79,6 +80,7 @@
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Expand All @@ -104,9 +106,28 @@
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browserbookmark_browserEngine}" />
<ComboBox
Grid.Row="1"
Grid.Column="1"
Width="120"
Height="34"
Margin="5,10,10,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
ItemsSource="{Binding Source={ui:EnumBindingSource {x:Type local:BrowserType}}}"
SelectedItem="{Binding BrowserType}">
</ComboBox>
<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="5,10,20,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browserbookmark_browserBookmarkDataDirectory}" />
<TextBox
Grid.Row="1"
Grid.Row="2"
Grid.Column="1"
Height="34"
Margin="5,10,0,0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
using Flow.Launcher.Plugin.BrowserBookmark.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Flow.Launcher.Plugin.BrowserBookmark.Views
{
Expand All @@ -27,7 +17,9 @@ public CustomBrowserSettingWindow(CustomBrowser browser)
currentCustomBrowser = browser;
DataContext = new CustomBrowser
{
Name = browser.Name, DataDirectoryPath = browser.DataDirectoryPath
Name = browser.Name,
DataDirectoryPath = browser.DataDirectoryPath,
BrowserType = browser.BrowserType,
};
}

Expand All @@ -39,6 +31,7 @@ private void ConfirmCancelEditCustomBrowser(object sender, RoutedEventArgs e)
{
currentCustomBrowser.Name = editBrowser.Name;
currentCustomBrowser.DataDirectoryPath = editBrowser.DataDirectoryPath;
currentCustomBrowser.BrowserType = editBrowser.BrowserType;
Close();
}
}
Expand All @@ -54,4 +47,4 @@ private void WindowKeyDown(object sender, KeyEventArgs e)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserName}"/>
<GridViewColumn DisplayMemberBinding="{Binding DataDirectoryPath, Mode=OneWay}"
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserBookmarkDataDirectory}"/>
<GridViewColumn DisplayMemberBinding="{Binding BrowserType, Mode=OneWay}"
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserEngine}"/>
</GridView>
</ListView.View>
</ListView>
Expand Down