From fe7985d5644a2c3b86ff369736fb461e7fc0fba4 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Mon, 23 Jun 2025 12:25:16 +0800
Subject: [PATCH 01/54] Use Flow.Launcher.Localization to improve code quality
---
.../DecimalSeparator.cs | 11 +++---
.../Flow.Launcher.Plugin.Calculator.csproj | 2 +-
.../Flow.Launcher.Plugin.Calculator/Main.cs | 35 +++++++++----------
.../ViewModels/SettingsViewModel.cs | 16 +++++++++
.../Views/CalculatorSettings.xaml | 19 +++-------
.../Views/CalculatorSettings.xaml.cs | 12 +++----
6 files changed, 48 insertions(+), 47 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/DecimalSeparator.cs b/Plugins/Flow.Launcher.Plugin.Calculator/DecimalSeparator.cs
index 81a68739b..0ece36d54 100644
--- a/Plugins/Flow.Launcher.Plugin.Calculator/DecimalSeparator.cs
+++ b/Plugins/Flow.Launcher.Plugin.Calculator/DecimalSeparator.cs
@@ -1,18 +1,17 @@
-using System.ComponentModel;
-using Flow.Launcher.Core.Resource;
+using Flow.Launcher.Localization.Attributes;
namespace Flow.Launcher.Plugin.Calculator
{
- [TypeConverter(typeof(LocalizationConverter))]
+ [EnumLocalize]
public enum DecimalSeparator
{
- [LocalizedDescription("flowlauncher_plugin_calculator_decimal_seperator_use_system_locale")]
+ [EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_seperator_use_system_locale))]
UseSystemLocale,
- [LocalizedDescription("flowlauncher_plugin_calculator_decimal_seperator_dot")]
+ [EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_seperator_dot))]
Dot,
- [LocalizedDescription("flowlauncher_plugin_calculator_decimal_seperator_comma")]
+ [EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_calculator_decimal_seperator_comma))]
Comma
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj b/Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj
index 9cdef365d..73dacf3d1 100644
--- a/Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj
+++ b/Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj
@@ -42,7 +42,6 @@
-
@@ -63,6 +62,7 @@
+
diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs
index b1e4cd606..f35e64237 100644
--- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs
@@ -5,7 +5,6 @@ using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using Mages.Core;
-using Flow.Launcher.Plugin.Calculator.ViewModels;
using Flow.Launcher.Plugin.Calculator.Views;
namespace Flow.Launcher.Plugin.Calculator
@@ -24,19 +23,17 @@ namespace Flow.Launcher.Plugin.Calculator
@")+$", RegexOptions.Compiled);
private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
private static Engine MagesEngine;
- private const string comma = ",";
- private const string dot = ".";
+ private const string Comma = ",";
+ private const string Dot = ".";
- private PluginInitContext Context { get; set; }
+ internal static PluginInitContext Context { get; set; } = null!;
private static Settings _settings;
- private static SettingsViewModel _viewModel;
public void Init(PluginInitContext context)
{
Context = context;
_settings = context.API.LoadSettingJsonStorage();
- _viewModel = new SettingsViewModel(_settings);
MagesEngine = new Engine(new Configuration
{
@@ -72,10 +69,10 @@ namespace Flow.Launcher.Plugin.Calculator
var result = MagesEngine.Interpret(expression);
if (result?.ToString() == "NaN")
- result = Context.API.GetTranslation("flowlauncher_plugin_calculator_not_a_number");
+ result = Localize.flowlauncher_plugin_calculator_not_a_number();
if (result is Function)
- result = Context.API.GetTranslation("flowlauncher_plugin_calculator_expression_not_complete");
+ result = Localize.flowlauncher_plugin_calculator_expression_not_complete();
if (!string.IsNullOrEmpty(result?.ToString()))
{
@@ -89,7 +86,7 @@ namespace Flow.Launcher.Plugin.Calculator
Title = newResult,
IcoPath = "Images/calculator.png",
Score = 300,
- SubTitle = Context.API.GetTranslation("flowlauncher_plugin_calculator_copy_number_to_clipboard"),
+ SubTitle = Localize.flowlauncher_plugin_calculator_copy_number_to_clipboard(),
CopyText = newResult,
Action = c =>
{
@@ -134,16 +131,16 @@ namespace Flow.Launcher.Plugin.Calculator
return false;
}
- if ((query.Search.Contains(dot) && GetDecimalSeparator() != dot) ||
- (query.Search.Contains(comma) && GetDecimalSeparator() != comma))
+ if ((query.Search.Contains(Dot) && GetDecimalSeparator() != Dot) ||
+ (query.Search.Contains(Comma) && GetDecimalSeparator() != Comma))
return false;
return true;
}
- private string ChangeDecimalSeparator(decimal value, string newDecimalSeparator)
+ private static string ChangeDecimalSeparator(decimal value, string newDecimalSeparator)
{
- if (String.IsNullOrEmpty(newDecimalSeparator))
+ if (string.IsNullOrEmpty(newDecimalSeparator))
{
return value.ToString();
}
@@ -161,13 +158,13 @@ namespace Flow.Launcher.Plugin.Calculator
return _settings.DecimalSeparator switch
{
DecimalSeparator.UseSystemLocale => systemDecimalSeparator,
- DecimalSeparator.Dot => dot,
- DecimalSeparator.Comma => comma,
+ DecimalSeparator.Dot => Dot,
+ DecimalSeparator.Comma => Comma,
_ => systemDecimalSeparator,
};
}
- private bool IsBracketComplete(string query)
+ private static bool IsBracketComplete(string query)
{
var matchs = RegBrackets.Matches(query);
var leftBracketCount = 0;
@@ -188,17 +185,17 @@ namespace Flow.Launcher.Plugin.Calculator
public string GetTranslatedPluginTitle()
{
- return Context.API.GetTranslation("flowlauncher_plugin_caculator_plugin_name");
+ return Localize.flowlauncher_plugin_caculator_plugin_name();
}
public string GetTranslatedPluginDescription()
{
- return Context.API.GetTranslation("flowlauncher_plugin_caculator_plugin_description");
+ return Localize.flowlauncher_plugin_caculator_plugin_description();
}
public Control CreateSettingPanel()
{
- return new CalculatorSettings(_viewModel);
+ return new CalculatorSettings(_settings);
}
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs
index 09f745669..a1f07bd17 100644
--- a/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs
+++ b/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs
@@ -8,10 +8,26 @@ namespace Flow.Launcher.Plugin.Calculator.ViewModels
public SettingsViewModel(Settings settings)
{
Settings = settings;
+ DecimalSeparatorLocalized.UpdateLabels(AllDecimalSeparator);
}
public Settings Settings { get; init; }
public IEnumerable MaxDecimalPlacesRange => Enumerable.Range(1, 20);
+
+ public List AllDecimalSeparator { get; } = DecimalSeparatorLocalized.GetValues();
+
+ public DecimalSeparator SelectedDecimalSeparator
+ {
+ get => Settings.DecimalSeparator;
+ set
+ {
+ if (Settings.DecimalSeparator != value)
+ {
+ Settings.DecimalSeparator = value;
+ OnPropertyChanged();
+ }
+ }
+ }
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml b/Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml
index ceee3897c..589f3ddcd 100644
--- a/Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml
@@ -3,20 +3,15 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:calculator="clr-namespace:Flow.Launcher.Plugin.Calculator"
- xmlns:core="clr-namespace:Flow.Launcher.Core.Resource;assembly=Flow.Launcher.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:ui="clr-namespace:Flow.Launcher.Infrastructure.UI;assembly=Flow.Launcher.Infrastructure"
xmlns:viewModels="clr-namespace:Flow.Launcher.Plugin.Calculator.ViewModels"
+ d:DataContext="{d:DesignInstance Type=viewModels:SettingsViewModel}"
d:DesignHeight="450"
d:DesignWidth="800"
Loaded="CalculatorSettings_Loaded"
mc:Ignorable="d">
-
-
-
-
@@ -42,14 +37,10 @@
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
- ItemsSource="{Binding Source={ui:EnumBindingSource {x:Type calculator:DecimalSeparator}}}"
- SelectedItem="{Binding Settings.DecimalSeparator}">
-
-
-
-
-
-
+ DisplayMemberPath="Display"
+ ItemsSource="{Binding AllDecimalSeparator}"
+ SelectedValue="{Binding SelectedDecimalSeparator, Mode=TwoWay}"
+ SelectedValuePath="Value" />
Date: Mon, 23 Jun 2025 12:37:58 +0800
Subject: [PATCH 02/54] Adjust indent
---
.../Flow.Launcher.Plugin.Calculator.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj b/Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj
index 73dacf3d1..719b6c74f 100644
--- a/Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj
+++ b/Plugins/Flow.Launcher.Plugin.Calculator/Flow.Launcher.Plugin.Calculator.csproj
@@ -62,7 +62,7 @@
-
+
From 1b05643b64acaa357bb5f3195f933d0d1210fbf7 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Mon, 23 Jun 2025 12:38:27 +0800
Subject: [PATCH 03/54] Use Flow.Launcher.Localization to improve code quality
---
.../ChromiumBookmarkLoader.cs | 8 ++---
.../Commands/BookmarkLoader.cs | 4 +--
.../FirefoxBookmarkLoader.cs | 10 +++---
...low.Launcher.Plugin.BrowserBookmark.csproj | 2 +-
.../Helper/FaviconHelper.cs | 10 +++---
.../Main.cs | 24 +++++++-------
.../Models/CustomBrowser.cs | 32 +++++++++++++++----
.../Views/CustomBrowserSetting.xaml | 7 ++--
8 files changed, 58 insertions(+), 39 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs
index 6e6b2e5f4..6dc0f7a9a 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs
@@ -45,7 +45,7 @@ public abstract class ChromiumBookmarkLoader : IBookmarkLoader
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to register bookmark file monitoring: {bookmarkPath}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to register bookmark file monitoring: {bookmarkPath}", ex);
continue;
}
@@ -58,7 +58,7 @@ public abstract class ChromiumBookmarkLoader : IBookmarkLoader
var faviconDbPath = Path.Combine(profile, "Favicons");
if (File.Exists(faviconDbPath))
{
- Main._context.API.StopwatchLogInfo(ClassName, $"Load {profileBookmarks.Count} favicons cost", () =>
+ Main.Context.API.StopwatchLogInfo(ClassName, $"Load {profileBookmarks.Count} favicons cost", () =>
{
LoadFaviconsFromDb(faviconDbPath, profileBookmarks);
});
@@ -125,7 +125,7 @@ public abstract class ChromiumBookmarkLoader : IBookmarkLoader
}
else
{
- Main._context.API.LogError(ClassName, $"type property not found for {subElement.GetString()}");
+ Main.Context.API.LogError(ClassName, $"type property not found for {subElement.GetString()}");
}
}
}
@@ -190,7 +190,7 @@ public abstract class ChromiumBookmarkLoader : IBookmarkLoader
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to extract bookmark favicon: {bookmark.Url}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to extract bookmark favicon: {bookmark.Url}", ex);
}
finally
{
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs
index 758ce68ae..b76adae93 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs
@@ -9,11 +9,11 @@ internal static class BookmarkLoader
{
internal static MatchResult MatchProgram(Bookmark bookmark, string queryString)
{
- var match = Main._context.API.FuzzySearch(queryString, bookmark.Name);
+ var match = Main.Context.API.FuzzySearch(queryString, bookmark.Name);
if (match.IsSearchPrecisionScoreMet())
return match;
- return Main._context.API.FuzzySearch(queryString, bookmark.Url);
+ return Main.Context.API.FuzzySearch(queryString, bookmark.Url);
}
internal static List LoadAllBookmarks(Settings setting)
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs
index ec3b867ea..68e5d5caa 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs
@@ -49,7 +49,7 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to register Firefox bookmark file monitoring: {placesPath}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to register Firefox bookmark file monitoring: {placesPath}", ex);
return bookmarks;
}
@@ -84,7 +84,7 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
var faviconDbPath = Path.Combine(Path.GetDirectoryName(placesPath), "favicons.sqlite");
if (File.Exists(faviconDbPath))
{
- Main._context.API.StopwatchLogInfo(ClassName, $"Load {bookmarks.Count} favicons cost", () =>
+ Main.Context.API.StopwatchLogInfo(ClassName, $"Load {bookmarks.Count} favicons cost", () =>
{
LoadFaviconsFromDb(faviconDbPath, bookmarks);
});
@@ -98,7 +98,7 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to load Firefox bookmarks: {placesPath}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to load Firefox bookmarks: {placesPath}", ex);
}
// Delete temporary file
@@ -111,7 +111,7 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
}
return bookmarks;
@@ -186,7 +186,7 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to extract Firefox favicon: {bookmark.Url}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to extract Firefox favicon: {bookmark.Url}", ex);
}
finally
{
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj
index 3fb0fa46f..bf558bc31 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj
@@ -81,7 +81,6 @@
-
@@ -96,6 +95,7 @@
+
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs
index a879dcefd..b88bd7640 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs
@@ -27,9 +27,9 @@ public static class FaviconHelper
}
catch (Exception ex1)
{
- Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex1);
+ Main.Context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex1);
}
- Main._context.API.LogException(ClassName, $"Failed to copy favicon DB: {dbPath}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to copy favicon DB: {dbPath}", ex);
return;
}
@@ -39,7 +39,7 @@ public static class FaviconHelper
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to connect to SQLite: {tempDbPath}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to connect to SQLite: {tempDbPath}", ex);
}
// Delete temporary file
@@ -49,7 +49,7 @@ public static class FaviconHelper
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
}
}
@@ -61,7 +61,7 @@ public static class FaviconHelper
}
catch (Exception ex)
{
- Main._context.API.LogException(ClassName, $"Failed to save image: {outputPath}", ex);
+ Main.Context.API.LogException(ClassName, $"Failed to save image: {outputPath}", ex);
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
index 91ade206b..3b67e6f18 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
@@ -19,7 +19,7 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
internal static string _faviconCacheDir;
- internal static PluginInitContext _context;
+ internal static PluginInitContext Context { get; set; }
internal static Settings _settings;
@@ -29,7 +29,7 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
public void Init(PluginInitContext context)
{
- _context = context;
+ Context = context;
_settings = context.API.LoadSettingJsonStorage();
@@ -42,7 +42,7 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
private static void LoadBookmarksIfEnabled()
{
- if (_context.CurrentPluginMetadata.Disabled)
+ if (Context.CurrentPluginMetadata.Disabled)
{
// Don't load or monitor files if disabled
return;
@@ -84,7 +84,7 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
Score = BookmarkLoader.MatchProgram(c, param).Score,
Action = _ =>
{
- _context.API.OpenUrl(c.Url);
+ Context.API.OpenUrl(c.Url);
return true;
},
@@ -108,7 +108,7 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
Score = 5,
Action = _ =>
{
- _context.API.OpenUrl(c.Url);
+ Context.API.OpenUrl(c.Url);
return true;
},
ContextData = new BookmarkAttributes { Url = c.Url }
@@ -192,12 +192,12 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
public string GetTranslatedPluginTitle()
{
- return _context.API.GetTranslation("flowlauncher_plugin_browserbookmark_plugin_name");
+ return Localize.flowlauncher_plugin_browserbookmark_plugin_name();
}
public string GetTranslatedPluginDescription()
{
- return _context.API.GetTranslation("flowlauncher_plugin_browserbookmark_plugin_description");
+ return Localize.flowlauncher_plugin_browserbookmark_plugin_description();
}
public Control CreateSettingPanel()
@@ -211,22 +211,22 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
{
new()
{
- Title = _context.API.GetTranslation("flowlauncher_plugin_browserbookmark_copyurl_title"),
- SubTitle = _context.API.GetTranslation("flowlauncher_plugin_browserbookmark_copyurl_subtitle"),
+ Title = Localize.flowlauncher_plugin_browserbookmark_copyurl_title(),
+ SubTitle = Localize.flowlauncher_plugin_browserbookmark_copyurl_subtitle(),
Action = _ =>
{
try
{
- _context.API.CopyToClipboard(((BookmarkAttributes)selectedResult.ContextData).Url);
+ Context.API.CopyToClipboard(((BookmarkAttributes)selectedResult.ContextData).Url);
return true;
}
catch (Exception e)
{
var message = "Failed to set url in clipboard";
- _context.API.LogException(ClassName, message, e);
+ Context.API.LogException(ClassName, message, e);
- _context.API.ShowMsg(message);
+ Context.API.ShowMsg(message);
return false;
}
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs
index 74e0f299a..af1e3fee4 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Models/CustomBrowser.cs
@@ -1,4 +1,7 @@
-namespace Flow.Launcher.Plugin.BrowserBookmark.Models;
+using System.Collections.Generic;
+using Flow.Launcher.Localization.Attributes;
+
+namespace Flow.Launcher.Plugin.BrowserBookmark.Models;
public class CustomBrowser : BaseModel
{
@@ -11,8 +14,11 @@ public class CustomBrowser : BaseModel
get => _name;
set
{
- _name = value;
- OnPropertyChanged();
+ if (_name != value)
+ {
+ _name = value;
+ OnPropertyChanged();
+ }
}
}
@@ -21,24 +27,36 @@ public class CustomBrowser : BaseModel
get => _dataDirectoryPath;
set
{
- _dataDirectoryPath = value;
- OnPropertyChanged();
+ if (_dataDirectoryPath != value)
+ {
+ _dataDirectoryPath = value;
+ OnPropertyChanged();
+ }
}
}
+ public List AllBrowserTypes { get; } = BrowserTypeLocalized.GetValues();
+
public BrowserType BrowserType
{
get => _browserType;
set
{
- _browserType = value;
- OnPropertyChanged();
+ if (_browserType != value)
+ {
+ _browserType = value;
+ OnPropertyChanged();
+ }
}
}
}
+[EnumLocalize]
public enum BrowserType
{
+ [EnumLocalizeValue("Chromium")]
Chromium,
+
+ [EnumLocalizeValue("Firefox")]
Firefox,
}
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml
index 80b004ff9..f67d359bf 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/CustomBrowserSetting.xaml
@@ -5,7 +5,6 @@
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="550"
Background="{DynamicResource PopuBGColor}"
@@ -142,8 +141,10 @@
Margin="5 10 10 0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
- ItemsSource="{Binding Source={ui:EnumBindingSource {x:Type local:BrowserType}}}"
- SelectedItem="{Binding BrowserType}" />
+ DisplayMemberPath="Display"
+ ItemsSource="{Binding AllBrowserTypes}"
+ SelectedValue="{Binding BrowserType}"
+ SelectedValuePath="Value" />
Date: Mon, 23 Jun 2025 12:45:31 +0800
Subject: [PATCH 04/54] Use trick to get the cache directory path
---
.../Flow.Launcher.Plugin.Program.csproj | 1 -
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 11 ++++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj b/Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj
index 99c1a12e9..7e61f19b3 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj
+++ b/Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj
@@ -58,7 +58,6 @@
-
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index d28845994..211afcfb0 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -6,7 +6,6 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
-using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin.Program.Programs;
using Flow.Launcher.Plugin.Program.Views;
using Flow.Launcher.Plugin.Program.Views.Models;
@@ -234,11 +233,17 @@ namespace Flow.Launcher.Plugin.Program
}
}
+ // If plugin cache directory is this: D:\\Data\\Cache\\Plugins\\Flow.Launcher.Plugin.Program
+ // then the parent directory is: D:\\Data\\Cache
+ // So we can use the parent of the parent directory to get the cache directory path
+ var directoryInfo = new DirectoryInfo(pluginCacheDirectory);
+ var cacheDirectory = directoryInfo.Parent.Parent.FullName;
+
// Move old cache files to the new cache directory
- var oldWin32CacheFile = Path.Combine(DataLocation.CacheDirectory, $"{Win32CacheName}.cache");
+ var oldWin32CacheFile = Path.Combine(cacheDirectory, $"{Win32CacheName}.cache");
var newWin32CacheFile = Path.Combine(pluginCacheDirectory, $"{Win32CacheName}.cache");
MoveFile(oldWin32CacheFile, newWin32CacheFile);
- var oldUWPCacheFile = Path.Combine(DataLocation.CacheDirectory, $"{UwpCacheName}.cache");
+ var oldUWPCacheFile = Path.Combine(cacheDirectory, $"{UwpCacheName}.cache");
var newUWPCacheFile = Path.Combine(pluginCacheDirectory, $"{UwpCacheName}.cache");
MoveFile(oldUWPCacheFile, newUWPCacheFile);
From 6143c9945497397c19ef3476c8a17ebd0c922bd1 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Mon, 23 Jun 2025 12:47:44 +0800
Subject: [PATCH 05/54] Remove useless class
---
.../UI/EnumBindingSource.cs | 58 -------------------
1 file changed, 58 deletions(-)
delete mode 100644 Flow.Launcher.Infrastructure/UI/EnumBindingSource.cs
diff --git a/Flow.Launcher.Infrastructure/UI/EnumBindingSource.cs b/Flow.Launcher.Infrastructure/UI/EnumBindingSource.cs
deleted file mode 100644
index f9504e6d9..000000000
--- a/Flow.Launcher.Infrastructure/UI/EnumBindingSource.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using System;
-using System.Windows.Markup;
-
-namespace Flow.Launcher.Infrastructure.UI
-{
- [Obsolete("EnumBindingSourceExtension is obsolete. Use with Flow.Launcher.Localization NuGet package instead.")]
- public class EnumBindingSourceExtension : MarkupExtension
- {
- private Type _enumType;
- public Type EnumType
- {
- get { return _enumType; }
- set
- {
- if (value != _enumType)
- {
- if (value != null)
- {
- Type enumType = Nullable.GetUnderlyingType(value) ?? value;
- if (!enumType.IsEnum)
- {
- throw new ArgumentException("Type must represent an enum.");
- }
- }
-
- _enumType = value;
- }
- }
- }
-
- public EnumBindingSourceExtension() { }
-
- public EnumBindingSourceExtension(Type enumType)
- {
- EnumType = enumType;
- }
-
- public override object ProvideValue(IServiceProvider serviceProvider)
- {
- if (_enumType == null)
- {
- throw new InvalidOperationException("The EnumType must be specified.");
- }
-
- Type actualEnumType = Nullable.GetUnderlyingType(_enumType) ?? _enumType;
- Array enumValues = Enum.GetValues(actualEnumType);
-
- if (actualEnumType == _enumType)
- {
- return enumValues;
- }
-
- Array tempArray = Array.CreateInstance(actualEnumType, enumValues.Length + 1);
- enumValues.CopyTo(tempArray, 1);
- return tempArray;
- }
- }
-}
From 107da050a57dca45991be856cfba3c6640e8e9c8 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Mon, 23 Jun 2025 13:02:04 +0800
Subject: [PATCH 06/54] Fix build issue
---
.../Flow.Launcher.Plugin.Program.csproj | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj b/Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj
index 7e61f19b3..16a8c03f4 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj
+++ b/Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj
@@ -63,11 +63,13 @@
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
\ No newline at end of file
From 9be2ef092476727aaf9404e0a196165df4535fbc Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Mon, 23 Jun 2025 13:03:45 +0800
Subject: [PATCH 07/54] Remove unused class
---
.../Resource/LocalizationConverter.cs | 38 -------------------
1 file changed, 38 deletions(-)
delete mode 100644 Flow.Launcher.Core/Resource/LocalizationConverter.cs
diff --git a/Flow.Launcher.Core/Resource/LocalizationConverter.cs b/Flow.Launcher.Core/Resource/LocalizationConverter.cs
deleted file mode 100644
index fdda33926..000000000
--- a/Flow.Launcher.Core/Resource/LocalizationConverter.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Globalization;
-using System.Reflection;
-using System.Windows.Data;
-
-namespace Flow.Launcher.Core.Resource
-{
- [Obsolete("LocalizationConverter is obsolete. Use with Flow.Launcher.Localization NuGet package instead.")]
- public class LocalizationConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (targetType == typeof(string) && value != null)
- {
- FieldInfo fi = value.GetType().GetField(value.ToString());
- if (fi != null)
- {
- string localizedDescription = string.Empty;
- var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
- if ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description)))
- {
- localizedDescription = attributes[0].Description;
- }
-
- return (!String.IsNullOrEmpty(localizedDescription)) ? localizedDescription : value.ToString();
- }
- }
-
- return string.Empty;
- }
-
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
-}
From c4cbf941cf4a681255a39c9fc38850b178be1fde Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Mon, 23 Jun 2025 13:13:45 +0800
Subject: [PATCH 08/54] Add directory null check
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index 211afcfb0..b9187a801 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -237,15 +237,17 @@ namespace Flow.Launcher.Plugin.Program
// then the parent directory is: D:\\Data\\Cache
// So we can use the parent of the parent directory to get the cache directory path
var directoryInfo = new DirectoryInfo(pluginCacheDirectory);
- var cacheDirectory = directoryInfo.Parent.Parent.FullName;
-
- // Move old cache files to the new cache directory
- var oldWin32CacheFile = Path.Combine(cacheDirectory, $"{Win32CacheName}.cache");
- var newWin32CacheFile = Path.Combine(pluginCacheDirectory, $"{Win32CacheName}.cache");
- MoveFile(oldWin32CacheFile, newWin32CacheFile);
- var oldUWPCacheFile = Path.Combine(cacheDirectory, $"{UwpCacheName}.cache");
- var newUWPCacheFile = Path.Combine(pluginCacheDirectory, $"{UwpCacheName}.cache");
- MoveFile(oldUWPCacheFile, newUWPCacheFile);
+ var cacheDirectory = directoryInfo.Parent?.Parent?.FullName;
+ // Move old cache files to the new cache directory if cache directory exists
+ if (!string.IsNullOrEmpty(cacheDirectory))
+ {
+ var oldWin32CacheFile = Path.Combine(cacheDirectory, $"{Win32CacheName}.cache");
+ var newWin32CacheFile = Path.Combine(pluginCacheDirectory, $"{Win32CacheName}.cache");
+ MoveFile(oldWin32CacheFile, newWin32CacheFile);
+ var oldUWPCacheFile = Path.Combine(cacheDirectory, $"{UwpCacheName}.cache");
+ var newUWPCacheFile = Path.Combine(pluginCacheDirectory, $"{UwpCacheName}.cache");
+ MoveFile(oldUWPCacheFile, newUWPCacheFile);
+ }
await _win32sLock.WaitAsync();
_win32s = await context.API.LoadCacheBinaryStorageAsync(Win32CacheName, pluginCacheDirectory, new List());
From 78b4c7db855a2daee98e830613a3f331ba89395e Mon Sep 17 00:00:00 2001
From: dcog989
Date: Mon, 14 Jul 2025 00:43:39 +0100
Subject: [PATCH 09/54] Fix BrowserBookmark '100% CPU' issue
# Fix BrowserBookmark plugin locking threads at 100% CPU
The following files were modified to implement this fix:
1. /Flow.Launcher.Plugin.BrowserBookmark.csproj
- packages SkiaSharp and Svg.Skia added to output WEBP
2. /Helper/FaviconHelper.cs
- new method, TryConvertToWebp, added to take any image data and encode to WEBP
3. /FirefoxBookmarkLoader.cs
- LoadFaviconsFromDb to use the new helper which ensures only safe WEBP files are used by the UI, which resolves the CPU-locking. It was GZIPped SVGs that were causing the thread / CPU lock.
---
.../FirefoxBookmarkLoader.cs | 48 +++++++-------
...low.Launcher.Plugin.BrowserBookmark.csproj | 2 +
.../Helper/FaviconHelper.cs | 62 ++++++++++++++++---
3 files changed, 82 insertions(+), 30 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs
index ec3b867ea..f933fa2bb 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs
@@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
+using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using Flow.Launcher.Plugin.BrowserBookmark.Helper;
@@ -134,10 +135,6 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
try
{
- if (string.IsNullOrEmpty(bookmark.Url))
- return;
-
- // Extract domain from URL
if (!Uri.TryCreate(bookmark.Url, UriKind.Absolute, out Uri uri))
return;
@@ -146,43 +143,48 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
// Query for latest Firefox version favicon structure
using var cmd = connection.CreateCommand();
cmd.CommandText = @"
- SELECT i.data
+ SELECT i.id, i.data
FROM moz_icons i
JOIN moz_icons_to_pages ip ON i.id = ip.icon_id
JOIN moz_pages_w_icons p ON ip.page_id = p.id
- WHERE p.page_url LIKE @url
- AND i.data IS NOT NULL
- ORDER BY i.width DESC -- Select largest icon available
+ WHERE p.page_url LIKE @domain
+ ORDER BY i.width DESC
LIMIT 1";
- cmd.Parameters.AddWithValue("@url", $"%{domain}%");
+ cmd.Parameters.AddWithValue("@domain", $"%{domain}%");
using var reader = cmd.ExecuteReader();
- if (!reader.Read() || reader.IsDBNull(0))
+ if (!reader.Read() || reader.IsDBNull(1))
return;
+ var iconId = reader.GetInt64(0).ToString();
var imageData = (byte[])reader["data"];
if (imageData is not { Length: > 0 })
return;
-
- string faviconPath;
- if (FaviconHelper.IsSvgData(imageData))
+
+ if (imageData.Length > 2 && imageData[0] == 0x1f && imageData[1] == 0x8b)
{
- faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}.svg");
+ using var inputStream = new MemoryStream(imageData);
+ using var gZipStream = new GZipStream(inputStream, CompressionMode.Decompress);
+ using var outputStream = new MemoryStream();
+ gZipStream.CopyTo(outputStream);
+ imageData = outputStream.ToArray();
}
- else
+
+ var webpData = FaviconHelper.TryConvertToWebp(imageData);
+
+ if (webpData != null)
{
- faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}.png");
- }
+ var faviconPath = Path.Combine(_faviconCacheDir, $"firefox_{domain}_{iconId}.webp");
- // Filter out duplicate favicons
- if (savedPaths.TryAdd(faviconPath, true))
- {
- FaviconHelper.SaveBitmapData(imageData, faviconPath);
- }
+ if (savedPaths.TryAdd(faviconPath, true))
+ {
+ FaviconHelper.SaveBitmapData(webpData, faviconPath);
+ }
- bookmark.FaviconPath = faviconPath;
+ bookmark.FaviconPath = faviconPath;
+ }
}
catch (Exception ex)
{
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj
index 3fb0fa46f..7b2fb47f8 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj
@@ -97,6 +97,8 @@
+
+
diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs
index a879dcefd..bd8492408 100644
--- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs
+++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs
@@ -1,5 +1,7 @@
using System;
using System.IO;
+using SkiaSharp;
+using Svg.Skia;
namespace Flow.Launcher.Plugin.BrowserBookmark.Helper;
@@ -65,12 +67,58 @@ public static class FaviconHelper
}
}
- public static bool IsSvgData(byte[] data)
+ public static byte[] TryConvertToWebp(byte[] data)
{
- if (data.Length < 5)
- return false;
- string start = System.Text.Encoding.ASCII.GetString(data, 0, Math.Min(100, data.Length));
- return start.Contains("
-
-