Skip to content

Commit 0430eea

Browse files
committed
Use api functions instead of project reference for code quality
1 parent 2c6fdc0 commit 0430eea

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/BookmarkLoader.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Flow.Launcher.Infrastructure;
43
using Flow.Launcher.Plugin.BrowserBookmark.Models;
54
using Flow.Launcher.Plugin.SharedModels;
65

@@ -10,11 +9,11 @@ internal static class BookmarkLoader
109
{
1110
internal static MatchResult MatchProgram(Bookmark bookmark, string queryString)
1211
{
13-
var match = StringMatcher.FuzzySearch(queryString, bookmark.Name);
12+
var match = Main._context.API.FuzzySearch(queryString, bookmark.Name);
1413
if (match.IsSearchPrecisionScoreMet())
1514
return match;
1615

17-
return StringMatcher.FuzzySearch(queryString, bookmark.Url);
16+
return Main._context.API.FuzzySearch(queryString, bookmark.Url);
1817
}
1918

2019
internal static List<Bookmark> LoadAllBookmarks(Settings setting)

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
using Flow.Launcher.Plugin.BrowserBookmark.Models;
2-
using Microsoft.Data.Sqlite;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.IO;
64
using System.Linq;
7-
using Flow.Launcher.Infrastructure.Logger;
5+
using Flow.Launcher.Plugin.BrowserBookmark.Models;
6+
using Microsoft.Data.Sqlite;
87

98
namespace Flow.Launcher.Plugin.BrowserBookmark;
109

1110
public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
1211
{
12+
private static readonly string ClassName = nameof(FirefoxBookmarkLoaderBase);
13+
1314
private readonly string _faviconCacheDir;
1415

1516
protected FirefoxBookmarkLoaderBase()
@@ -52,7 +53,7 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
5253
}
5354
catch (Exception ex)
5455
{
55-
Log.Exception($"Failed to register Firefox bookmark file monitoring: {placesPath}", ex);
56+
Main._context.API.LogException(ClassName, $"Failed to register Firefox bookmark file monitoring: {placesPath}", ex);
5657
}
5758

5859
// Use a copy to avoid lock issues with the original file
@@ -93,12 +94,12 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
9394
}
9495
catch (Exception ex)
9596
{
96-
Log.Exception($"Failed to delete temporary favicon DB: {tempDbPath}", ex);
97+
Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
9798
}
9899
}
99100
catch (Exception ex)
100101
{
101-
Log.Exception($"Failed to load Firefox bookmarks: {placesPath}", ex);
102+
Main._context.API.LogException(ClassName, $"Failed to load Firefox bookmarks: {placesPath}", ex);
102103
}
103104

104105
return bookmarks;
@@ -177,7 +178,7 @@ ORDER BY i.width DESC -- Select largest icon available
177178
}
178179
catch (Exception ex)
179180
{
180-
Log.Exception($"Failed to extract Firefox favicon: {bookmark.Url}", ex);
181+
Main._context.API.LogException(ClassName, $"Failed to extract Firefox favicon: {bookmark.Url}", ex);
181182
}
182183
}
183184

@@ -192,12 +193,12 @@ ORDER BY i.width DESC -- Select largest icon available
192193
}
193194
catch (Exception ex)
194195
{
195-
Log.Exception($"Failed to delete temporary favicon DB: {tempDbPath}", ex);
196+
Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
196197
}
197198
}
198199
catch (Exception ex)
199200
{
200-
Log.Exception($"Failed to load Firefox favicon DB: {faviconDbPath}", ex);
201+
Main._context.API.LogException(ClassName, $"Failed to load Firefox favicon DB: {faviconDbPath}", ex);
201202
}
202203
}
203204

@@ -218,7 +219,7 @@ private static void SaveBitmapData(byte[] imageData, string outputPath)
218219
}
219220
catch (Exception ex)
220221
{
221-
Log.Exception($"Failed to save image: {outputPath}", ex);
222+
Main._context.API.LogException(ClassName, $"Failed to save image: {outputPath}", ex);
222223
}
223224
}
224225
}

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
</ItemGroup>
8282

8383
<ItemGroup>
84-
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
8584
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
8685
</ItemGroup>
8786

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Windows.Controls;
5-
using Flow.Launcher.Infrastructure.Logger;
65
using Flow.Launcher.Plugin.BrowserBookmark.Commands;
76
using Flow.Launcher.Plugin.BrowserBookmark.Models;
87
using Flow.Launcher.Plugin.BrowserBookmark.Views;
@@ -15,24 +14,14 @@ namespace Flow.Launcher.Plugin.BrowserBookmark;
1514

1615
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu, IDisposable
1716
{
18-
private static PluginInitContext _context;
17+
internal static PluginInitContext _context;
1918

2019
private static List<Bookmark> _cachedBookmarks = new();
2120

2221
private static Settings _settings;
2322

2423
private static bool _initialized = false;
2524

26-
public static PluginInitContext GetContext()
27-
{
28-
return _context;
29-
}
30-
31-
public static string GetPluginDirectory()
32-
{
33-
return _context?.CurrentPluginMetadata?.PluginDirectory;
34-
}
35-
3625
public void Init(PluginInitContext context)
3726
{
3827
_context = context;
@@ -223,7 +212,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
223212
catch (Exception e)
224213
{
225214
var message = "Failed to set url in clipboard";
226-
Log.Exception("Main", message, e, "LoadContextMenus");
215+
_context.API.LogException(nameof(Main), message, e);
227216

228217
_context.API.ShowMsg(message);
229218

0 commit comments

Comments
 (0)