Skip to content

Commit 1c95033

Browse files
authored
Merge pull request #1875 from VictoriousRaptor/SelectBrowserCore
Close #1856
2 parents 70015e2 + ef16484 commit 1c95033

File tree

8 files changed

+105
-26
lines changed

8 files changed

+105
-26
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ 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 = browser.BrowserType switch
48+
{
49+
BrowserType.Chromium => new CustomChromiumBookmarkLoader(browser),
50+
BrowserType.Firefox => new CustomFirefoxBookmarkLoader(browser),
51+
_ => new CustomChromiumBookmarkLoader(browser),
52+
};
4853
allBookmarks.AddRange(loader.GetBookmarks());
4954
}
5055

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

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/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
<system:String x:Key="flowlauncher_plugin_browserbookmark_addBrowserBookmark">Add</system:String>
2323
<system:String x:Key="flowlauncher_plugin_browserbookmark_removeBrowserBookmark">Delete</system:String>
2424
<system:String x:Key="flowlauncher_plugin_browserbookmark_others">Others</system:String>
25+
<system:String x:Key="flowlauncher_plugin_browserbookmark_browserEngine">Browser Engine</system:String>
2526
</ResourceDictionary>

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+
}

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:Flow.Launcher.Plugin.BrowserBookmark.Models"
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:ui="clr-namespace:Flow.Launcher.Infrastructure.UI;assembly=Flow.Launcher.Infrastructure"
89
Title="{DynamicResource flowlauncher_plugin_browserbookmark_bookmarkDataSetting}"
910
Width="520"
1011
Background="{DynamicResource PopuBGColor}"
@@ -79,6 +80,7 @@
7980
<Grid.RowDefinitions>
8081
<RowDefinition />
8182
<RowDefinition />
83+
<RowDefinition />
8284
</Grid.RowDefinitions>
8385
<TextBlock
8486
Grid.Row="0"
@@ -104,9 +106,28 @@
104106
HorizontalAlignment="Left"
105107
VerticalAlignment="Center"
106108
FontSize="14"
109+
Text="{DynamicResource flowlauncher_plugin_browserbookmark_browserEngine}" />
110+
<ComboBox
111+
Grid.Row="1"
112+
Grid.Column="1"
113+
Width="120"
114+
Height="34"
115+
Margin="5,10,10,0"
116+
HorizontalAlignment="Left"
117+
VerticalAlignment="Center"
118+
ItemsSource="{Binding Source={ui:EnumBindingSource {x:Type local:BrowserType}}}"
119+
SelectedItem="{Binding BrowserType}">
120+
</ComboBox>
121+
<TextBlock
122+
Grid.Row="2"
123+
Grid.Column="0"
124+
Margin="5,10,20,0"
125+
HorizontalAlignment="Left"
126+
VerticalAlignment="Center"
127+
FontSize="14"
107128
Text="{DynamicResource flowlauncher_plugin_browserbookmark_browserBookmarkDataDirectory}" />
108129
<TextBox
109-
Grid.Row="1"
130+
Grid.Row="2"
110131
Grid.Column="1"
111132
Height="34"
112133
Margin="5,10,0,0"

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
using Flow.Launcher.Plugin.BrowserBookmark.Models;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72
using System.Windows;
83
using System.Windows.Controls;
9-
using System.Windows.Data;
10-
using System.Windows.Documents;
114
using System.Windows.Input;
12-
using System.Windows.Media;
13-
using System.Windows.Media.Imaging;
14-
using System.Windows.Shapes;
155

166
namespace Flow.Launcher.Plugin.BrowserBookmark.Views
177
{
@@ -27,7 +17,9 @@ public CustomBrowserSettingWindow(CustomBrowser browser)
2717
currentCustomBrowser = browser;
2818
DataContext = new CustomBrowser
2919
{
30-
Name = browser.Name, DataDirectoryPath = browser.DataDirectoryPath
20+
Name = browser.Name,
21+
DataDirectoryPath = browser.DataDirectoryPath,
22+
BrowserType = browser.BrowserType,
3123
};
3224
}
3325

@@ -39,6 +31,7 @@ private void ConfirmCancelEditCustomBrowser(object sender, RoutedEventArgs e)
3931
{
4032
currentCustomBrowser.Name = editBrowser.Name;
4133
currentCustomBrowser.DataDirectoryPath = editBrowser.DataDirectoryPath;
34+
currentCustomBrowser.BrowserType = editBrowser.BrowserType;
4235
Close();
4336
}
4437
}
@@ -54,4 +47,4 @@ private void WindowKeyDown(object sender, KeyEventArgs e)
5447
}
5548
}
5649
}
57-
}
50+
}

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserName}"/>
4747
<GridViewColumn DisplayMemberBinding="{Binding DataDirectoryPath, Mode=OneWay}"
4848
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserBookmarkDataDirectory}"/>
49+
<GridViewColumn DisplayMemberBinding="{Binding BrowserType, Mode=OneWay}"
50+
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserEngine}"/>
4951
</GridView>
5052
</ListView.View>
5153
</ListView>

0 commit comments

Comments
 (0)