Skip to content

Commit ab0d624

Browse files
Auto reload all bookmarks when finish editing
1 parent dd61d19 commit ab0d624

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Languages/en.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@
2727
<system:String x:Key="flowlauncher_plugin_browserbookmark_browserEngine">Browser Engine</system:String>
2828
<system:String x:Key="flowlauncher_plugin_browserbookmark_guideMessage01">If you are not using Chrome, Firefox or Edge, or you are using their portable version, you need to add bookmarks data directory and select correct browser engine to make this plugin work.</system:String>
2929
<system:String x:Key="flowlauncher_plugin_browserbookmark_guideMessage02">For example: Brave's engine is Chromium; and its default bookmarks data location is: "%LOCALAPPDATA%\BraveSoftware\Brave-Browser\UserData". For Firefox engine, the bookmarks directory is the folder contains the places.sqlite file.</system:String>
30-
<system:String x:Key="flowlauncher_plugin_browserbookmark_guideMessage03">After changing these values, close all setting windows and press F5 when Flow Launcher is open to reload the plug-in.</system:String>
3130
</ResourceDictionary>

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
1717
{
1818
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu, IDisposable
1919
{
20-
private PluginInitContext context;
20+
private static PluginInitContext context;
2121

22-
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
23-
24-
private Settings _settings { get; set; }
22+
private static List<Bookmark> cachedBookmarks = new List<Bookmark>();
2523

24+
private static Settings _settings;
25+
2626
public void Init(PluginInitContext context)
2727
{
28-
this.context = context;
29-
28+
Main.context = context;
29+
3030
_settings = context.API.LoadSettingJsonStorage<Settings>();
3131

3232
cachedBookmarks = BookmarkLoader.LoadAllBookmarks(_settings);
@@ -136,6 +136,11 @@ internal static void RegisterBookmarkFile(string path)
136136
}
137137

138138
public void ReloadData()
139+
{
140+
ReloadAllBookmarks();
141+
}
142+
143+
public static void ReloadAllBookmarks()
139144
{
140145
cachedBookmarks.Clear();
141146

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</Grid.ColumnDefinitions>
4040
<Button
4141
Grid.Column="4"
42-
Click="ConfirmCancelEditCustomBrowser"
42+
Click="CancelEditCustomBrowser"
4343
Style="{StaticResource TitleBarCloseButtonStyle}">
4444
<Path
4545
Width="46"
@@ -187,13 +187,13 @@
187187
x:Name="btnCancel"
188188
MinWidth="145"
189189
Margin="0,0,5,0"
190-
Click="ConfirmCancelEditCustomBrowser"
190+
Click="CancelEditCustomBrowser"
191191
Content="{DynamicResource cancel}" />
192192
<Button
193193
Name="btnConfirm"
194194
MinWidth="145"
195195
Margin="5,0,0,0"
196-
Click="ConfirmCancelEditCustomBrowser"
196+
Click="ConfirmEditCustomBrowser"
197197
Style="{StaticResource AccentButtonStyle}">
198198
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
199199
</Button>
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using Flow.Launcher.Plugin.BrowserBookmark.Models;
2-
using Microsoft.Win32;
3-
using System;
42
using System.Windows;
5-
using System.Windows.Controls;
63
using System.Windows.Input;
74
using System.Windows.Forms;
5+
using System.Threading.Tasks;
86

97
namespace Flow.Launcher.Plugin.BrowserBookmark.Views
108
{
@@ -25,37 +23,36 @@ public CustomBrowserSettingWindow(CustomBrowser browser)
2523
BrowserType = browser.BrowserType,
2624
};
2725
}
28-
29-
private void ConfirmCancelEditCustomBrowser(object sender, RoutedEventArgs e)
26+
27+
private void ConfirmEditCustomBrowser(object sender, RoutedEventArgs e)
3028
{
31-
if (DataContext is CustomBrowser editBrowser && e.Source is System.Windows.Controls.Button button)
32-
{
33-
if (button.Name == "btnConfirm")
34-
{
35-
currentCustomBrowser.Name = editBrowser.Name;
36-
currentCustomBrowser.DataDirectoryPath = editBrowser.DataDirectoryPath;
37-
currentCustomBrowser.BrowserType = editBrowser.BrowserType;
38-
Close();
39-
}
40-
}
29+
CustomBrowser editBrowser = (CustomBrowser)DataContext;
30+
currentCustomBrowser.Name = editBrowser.Name;
31+
currentCustomBrowser.DataDirectoryPath = editBrowser.DataDirectoryPath;
32+
currentCustomBrowser.BrowserType = editBrowser.BrowserType;
33+
_ = Task.Run(() => Main.ReloadAllBookmarks());
34+
Close();
35+
}
4136

37+
private void CancelEditCustomBrowser(object sender, RoutedEventArgs e)
38+
{
4239
Close();
4340
}
4441

4542
private void WindowKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
4643
{
4744
if (e.Key == Key.Enter)
4845
{
49-
ConfirmCancelEditCustomBrowser(sender, e);
46+
ConfirmEditCustomBrowser(sender, e);
5047
}
5148
}
5249

5350
private void OnSelectPathClick(object sender, RoutedEventArgs e)
5451
{
5552
var dialog = new FolderBrowserDialog();
5653
dialog.ShowDialog();
57-
PathTextBox.Text = dialog.SelectedPath;
58-
string folder = dialog.SelectedPath;
54+
CustomBrowser editBrowser = (CustomBrowser)DataContext;
55+
editBrowser.DataDirectoryPath = dialog.SelectedPath;
5956
}
6057
}
6158
}

0 commit comments

Comments
 (0)