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

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
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 @@
}
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 Expand Up @@ -232,7 +232,7 @@
/// E.g. C:\Users\{UserName}\AppData\Local\Packages\Mozilla.Firefox_n80bbvh6b1yt2\LocalCache\Roaming\Mozilla\Firefox
/// <see href="https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data#w_finding-your-profile-without-opening-firefox"/>
/// </summary>
public static string MsixPlacesPath

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

View workflow job for this annotation

GitHub Actions / Check Spelling

`Msix` is not a recognized word. (unrecognized-spelling)
{
get
{
Expand All @@ -244,7 +244,7 @@
var firefoxPackageFolder = Directory.EnumerateDirectories(packagesPath, "Mozilla.Firefox*",
SearchOption.TopDirectoryOnly).FirstOrDefault();

// Msix FireFox not installed

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

View workflow job for this annotation

GitHub Actions / Check Spelling

`Msix` is not a recognized word. (unrecognized-spelling)
if (firefoxPackageFolder == null) return string.Empty;

var profileFolderPath = Path.Combine(firefoxPackageFolder, @"LocalCache\Roaming\Mozilla\Firefox");
Expand Down Expand Up @@ -288,7 +288,7 @@
[Profile2]
Name=dummyprofile
IsRelative=0
Path=C:\t6h2yuq8.dummyprofile <== Note this is a custom location path for the profile user can set, we need to cater for this in code.

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

View workflow job for this annotation

GitHub Actions / Check Spelling

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

[Profile1]
Name=default
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 @@

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 void Init(PluginInitContext context)
{
_context = context;
Context = context;

_settings = context.API.LoadSettingJsonStorage<Settings>();

Expand All @@ -42,7 +42,7 @@

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

Check warning on line 200 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

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

public Control CreateSettingPanel()
Expand All @@ -211,22 +211,22 @@
{
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(),

Check warning on line 214 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`browserbookmark` is not a recognized word. (unrecognized-spelling)
SubTitle = Localize.flowlauncher_plugin_browserbookmark_copyurl_subtitle(),

Check warning on line 215 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

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

Check warning on line 215 in Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`browserbookmark` is not a recognized word. (unrecognized-spelling)
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
Loading
Loading