Skip to content

Use Flow.Launcher.Localization to improve code quality #3765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Jul 26, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fe7985d
Use Flow.Launcher.Localization to improve code quality
Jack251970 Jun 23, 2025
e6a38ad
Adjust indent
Jack251970 Jun 23, 2025
1b05643
Use Flow.Launcher.Localization to improve code quality
Jack251970 Jun 23, 2025
68fc103
Use trick to get the cache directory path
Jack251970 Jun 23, 2025
6143c99
Remove useless class
Jack251970 Jun 23, 2025
107da05
Fix build issue
Jack251970 Jun 23, 2025
9be2ef0
Remove unused class
Jack251970 Jun 23, 2025
c4cbf94
Add directory null check
Jack251970 Jun 23, 2025
fc6ff5a
Merge branch 'dev' into code_quality
Jack251970 Jul 14, 2025
7cc0d23
Merge branch 'dev' into code_quality
VictoriousRaptor Jul 14, 2025
3bf1887
Intoduce dependency
VictoriousRaptor Jul 15, 2025
e116668
Rename file
VictoriousRaptor Jul 15, 2025
30f7ae0
Use Localization for Explorer plugin
VictoriousRaptor Jul 16, 2025
d008b39
Fix loc error
VictoriousRaptor Jul 16, 2025
c3dc8e5
Merge branch 'dev' into code_quality
VictoriousRaptor Jul 16, 2025
2018956
Fix label translation issue
Jack251970 Jul 16, 2025
7ca0dba
Remove unnecessary view model reference
VictoriousRaptor Jul 17, 2025
976c30e
Update labels on first get
VictoriousRaptor Jul 18, 2025
b03dae6
Remove redundent save settings call
VictoriousRaptor Jul 18, 2025
5d0bf8f
Update spell check
VictoriousRaptor Jul 18, 2025
2e99ff9
Merge branch 'dev' into code_quality
VictoriousRaptor Jul 18, 2025
81ae8a4
Only assign when value is different
VictoriousRaptor Jul 18, 2025
010b6dd
Merge branch 'dev' into code_quality
Jack251970 Jul 19, 2025
ed0524d
Merge branch 'dev' into code_quality
Jack251970 Jul 20, 2025
8e898de
Fix build issue
Jack251970 Jul 20, 2025
71c8fce
Improve code quality
Jack251970 Jul 20, 2025
bea1078
Remove redundant function call
VictoriousRaptor Jul 20, 2025
ad1d42b
Update labels on initialization to update on language change
VictoriousRaptor Jul 20, 2025
1e4ff43
Use length and count instead of Any()
VictoriousRaptor Jul 20, 2025
71eaf2d
Merge branch 'dev' into code_quality
Jack251970 Jul 21, 2025
b9e0669
Intialize translations in InitAsync
Jack251970 Jul 21, 2025
af3aaa8
Update labels for setting view model when culture info changes
Jack251970 Jul 21, 2025
08f17c4
Merge branch 'dev' into code_quality
VictoriousRaptor Jul 22, 2025
22ffc80
Update labels on language change and other refactor
VictoriousRaptor Jul 22, 2025
6579a46
Compile regex on build time
VictoriousRaptor Jul 22, 2025
63009ba
Use ContextMenu class instead of interface
VictoriousRaptor Jul 22, 2025
2825819
Use new Localization package
VictoriousRaptor Jul 22, 2025
69c4d19
Improve code quality
Jack251970 Jul 23, 2025
0b6309f
Fix typo
VictoriousRaptor Jul 23, 2025
54a2817
Merge branch 'dev' into code_quality
Jack251970 Jul 24, 2025
14282b6
Fix typos
Jack251970 Jul 24, 2025
b637e0a
Use Flow.Launcher.Localization 0.0.4 & update expect list
VictoriousRaptor Jul 26, 2025
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
38 changes: 0 additions & 38 deletions Flow.Launcher.Core/Resource/LocalizationConverter.cs

This file was deleted.

58 changes: 0 additions & 58 deletions Flow.Launcher.Infrastructure/UI/EnumBindingSource.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}
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;
}

Expand All @@ -55,12 +55,12 @@
// Load favicons after loading bookmarks
if (Main._settings.EnableFavicons)
{
var faviconDbPath = Path.Combine(profile, "Favicons");

Check warning on line 58 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Favicons` is not a recognized word. (unrecognized-spelling)
if (File.Exists(faviconDbPath))
{
Main._context.API.StopwatchLogInfo(ClassName, $"Load {profileBookmarks.Count} favicons cost", () =>
Main.Context.API.StopwatchLogInfo(ClassName, $"Load {profileBookmarks.Count} favicons cost", () =>

Check warning on line 61 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`favicons` is not a recognized word. (unrecognized-spelling)
{
LoadFaviconsFromDb(faviconDbPath, profileBookmarks);

Check warning on line 63 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Favicons` is not a recognized word. (unrecognized-spelling)
});
}
}
Expand Down Expand Up @@ -125,19 +125,19 @@
}
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()}");
}
}
}

private void LoadFaviconsFromDb(string dbPath, List<Bookmark> bookmarks)

Check warning on line 133 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Favicons` is not a recognized word. (unrecognized-spelling)
{
FaviconHelper.LoadFaviconsFromDb(_faviconCacheDir, dbPath, (tempDbPath) =>

Check warning on line 135 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Favicons` is not a recognized word. (unrecognized-spelling)
{
// Since some bookmarks may have same favicon id, we need to record them to avoid duplicates
var savedPaths = new ConcurrentDictionary<string, bool>();

// Get favicons based on bookmarks concurrently

Check warning on line 140 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`favicons` is not a recognized word. (unrecognized-spelling)
Parallel.ForEach(bookmarks, bookmark =>
{
// Use read-only connection to avoid locking issues
Expand All @@ -159,7 +159,7 @@
using var cmd = connection.CreateCommand();
cmd.CommandText = @"
SELECT f.id, b.image_data
FROM favicons f

Check warning on line 162 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`favicons` is not a recognized word. (unrecognized-spelling)
JOIN favicon_bitmaps b ON f.id = b.icon_id
JOIN icon_mapping m ON f.id = m.icon_id
WHERE m.page_url LIKE @url
Expand All @@ -180,7 +180,7 @@

var faviconPath = Path.Combine(_faviconCacheDir, $"chromium_{domain}_{iconId}.png");

// Filter out duplicate favicons

Check warning on line 183 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`favicons` is not a recognized word. (unrecognized-spelling)
if (savedPaths.TryAdd(faviconPath, true))
{
FaviconHelper.SaveBitmapData(imageData, faviconPath);
Expand All @@ -190,7 +190,7 @@
}
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
{
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<Bookmark> LoadAllBookmarks(Settings setting)
Expand All @@ -31,7 +31,7 @@
{
// Add Firefox bookmarks
var mozBookmarks = new FirefoxBookmarkLoader();
allBookmarks.AddRange(mozBookmarks.GetBookmarks());

Check warning on line 34 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`moz` is not a recognized word. (unrecognized-spelling)
}

if (setting.LoadEdgeBookmark)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

// Updated query - removed favicon_id column
private const string QueryAllBookmarks = """
SELECT moz_places.url, moz_bookmarks.title

Check warning on line 28 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`moz` is not a recognized word. (unrecognized-spelling)
FROM moz_places
INNER JOIN moz_bookmarks ON (
moz_bookmarks.fk NOT NULL AND moz_bookmarks.title NOT NULL AND moz_bookmarks.fk = moz_places.id
Expand All @@ -49,7 +49,7 @@
}
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;
}

Expand Down Expand Up @@ -84,7 +84,7 @@
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);
});
Expand All @@ -98,7 +98,7 @@
}
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
Expand All @@ -111,7 +111,7 @@
}
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;
Expand Down Expand Up @@ -186,7 +186,7 @@
}
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
</ItemGroup>

Expand All @@ -96,6 +95,7 @@

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Flow.Launcher.Localization" Version="0.0.3" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public static void LoadFaviconsFromDb(string faviconCacheDir, string dbPath, Act
}
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;
}

Expand All @@ -39,7 +39,7 @@ public static void LoadFaviconsFromDb(string faviconCacheDir, string dbPath, Act
}
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
Expand All @@ -49,7 +49,7 @@ public static void LoadFaviconsFromDb(string faviconCacheDir, string dbPath, Act
}
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);
}
}

Expand All @@ -61,7 +61,7 @@ public static void SaveBitmapData(byte[] imageData, string outputPath)
}
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);
}
}

Expand Down
24 changes: 12 additions & 12 deletions Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Settings>();

Expand All @@ -42,7 +42,7 @@ public void Init(PluginInitContext context)

private static void LoadBookmarksIfEnabled()
{
if (_context.CurrentPluginMetadata.Disabled)
if (Context.CurrentPluginMetadata.Disabled)
{
// Don't load or monitor files if disabled
return;
Expand Down Expand Up @@ -84,7 +84,7 @@ public List<Result> Query(Query query)
Score = BookmarkLoader.MatchProgram(c, param).Score,
Action = _ =>
{
_context.API.OpenUrl(c.Url);
Context.API.OpenUrl(c.Url);

return true;
},
Expand All @@ -108,7 +108,7 @@ public List<Result> Query(Query query)
Score = 5,
Action = _ =>
{
_context.API.OpenUrl(c.Url);
Context.API.OpenUrl(c.Url);
return true;
},
ContextData = new BookmarkAttributes { Url = c.Url }
Expand Down Expand Up @@ -192,12 +192,12 @@ public static void ReloadAllBookmarks(bool disposeFileWatchers = true)

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()
Expand All @@ -211,22 +211,22 @@ public List<Result> LoadContextMenus(Result selectedResult)
{
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -11,8 +14,11 @@ public string Name
get => _name;
set
{
_name = value;
OnPropertyChanged();
if (_name != value)
{
_name = value;
OnPropertyChanged();
}
}
}

Expand All @@ -21,24 +27,36 @@ public string DataDirectoryPath
get => _dataDirectoryPath;
set
{
_dataDirectoryPath = value;
OnPropertyChanged();
if (_dataDirectoryPath != value)
{
_dataDirectoryPath = value;
OnPropertyChanged();
}
}
}

public List<BrowserTypeLocalized> 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,
}
Loading
Loading