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 all 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
4 changes: 4 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ ssh
ubuntu
runcount
Firefox
Português
Português (Brasil)
favicons
moz
workaround
4 changes: 4 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ metadatas
WMP
VSTHRD
CJK
Msix
dummyprofile
browserbookmark
copyurl
5 changes: 5 additions & 0 deletions .github/actions/spelling/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
# version suffix <word>v#
(?:(?<=[A-Z]{2})V|(?<=[a-z]{2}|[A-Z]{2})v)\d+(?:\b|(?=[a-zA-Z_]))

# Non-English
[a-zA-Z]*[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿĀāŁłŃńŅņŒœŚśŠšŜŝŸŽžź][a-zA-Z]{3}[a-zA-ZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿĀāŁłŃńŅņŒœŚśŠšŜŝŸŽžź]*


\bjjw24\b
\bappref-ms\b
\bTobiasSekan\b
Expand All @@ -143,3 +147,4 @@
\bXing\s*Kong\s*Jian\s*Dao\b
\bDa\s*Niu\b
\bXiao\s*Lang\b
\b[Ss]ettings [Ss]ettings\b
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 @@ protected List<Bookmark> LoadBookmarks(string browserDataPath, string name)
}
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 @@ -58,7 +58,7 @@ protected List<Bookmark> LoadBookmarks(string browserDataPath, string name)
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);
});
Expand Down Expand Up @@ -125,7 +125,7 @@ private static void EnumerateFolderBookmark(JsonElement folderElement, ICollecti
}
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()}");
}
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ ORDER BY b.width DESC
}
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 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<Bookmark> LoadAllBookmarks(Settings setting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
}
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 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
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 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
}
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 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
}
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 @@ ORDER BY i.width DESC -- Select largest icon available
}
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.4" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.7" />
</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,20 +211,20 @@ 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)
{
_context.API.LogException(ClassName, "Failed to set url in clipboard", e);
_context.API.ShowMsgError(_context.API.GetTranslation("flowlauncher_plugin_browserbookmark_copy_failed"));
Context.API.LogException(ClassName, "Failed to set url in clipboard", e);
Context.API.ShowMsgError(Localize.flowlauncher_plugin_browserbookmark_copy_failed());
return false;
}
},
Expand Down
Loading
Loading