Use api functions instead of project reference for code quality

This commit is contained in:
Jack251970 2025-04-02 22:25:55 +08:00
parent 2c6fdc0b2e
commit 0430eea2fd
4 changed files with 16 additions and 28 deletions

View file

@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Plugin.BrowserBookmark.Models;
using Flow.Launcher.Plugin.SharedModels;
@ -10,11 +9,11 @@ internal static class BookmarkLoader
{
internal static MatchResult MatchProgram(Bookmark bookmark, string queryString)
{
var match = StringMatcher.FuzzySearch(queryString, bookmark.Name);
var match = Main._context.API.FuzzySearch(queryString, bookmark.Name);
if (match.IsSearchPrecisionScoreMet())
return match;
return StringMatcher.FuzzySearch(queryString, bookmark.Url);
return Main._context.API.FuzzySearch(queryString, bookmark.Url);
}
internal static List<Bookmark> LoadAllBookmarks(Settings setting)

View file

@ -1,15 +1,16 @@
using Flow.Launcher.Plugin.BrowserBookmark.Models;
using Microsoft.Data.Sqlite;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin.BrowserBookmark.Models;
using Microsoft.Data.Sqlite;
namespace Flow.Launcher.Plugin.BrowserBookmark;
public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
{
private static readonly string ClassName = nameof(FirefoxBookmarkLoaderBase);
private readonly string _faviconCacheDir;
protected FirefoxBookmarkLoaderBase()
@ -52,7 +53,7 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
Log.Exception($"Failed to register Firefox bookmark file monitoring: {placesPath}", ex);
Main._context.API.LogException(ClassName, $"Failed to register Firefox bookmark file monitoring: {placesPath}", ex);
}
// Use a copy to avoid lock issues with the original file
@ -93,12 +94,12 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
Log.Exception($"Failed to delete temporary favicon DB: {tempDbPath}", ex);
Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
}
}
catch (Exception ex)
{
Log.Exception($"Failed to load Firefox bookmarks: {placesPath}", ex);
Main._context.API.LogException(ClassName, $"Failed to load Firefox bookmarks: {placesPath}", ex);
}
return bookmarks;
@ -177,7 +178,7 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
Log.Exception($"Failed to extract Firefox favicon: {bookmark.Url}", ex);
Main._context.API.LogException(ClassName, $"Failed to extract Firefox favicon: {bookmark.Url}", ex);
}
}
@ -192,12 +193,12 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
Log.Exception($"Failed to delete temporary favicon DB: {tempDbPath}", ex);
Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
}
}
catch (Exception ex)
{
Log.Exception($"Failed to load Firefox favicon DB: {faviconDbPath}", ex);
Main._context.API.LogException(ClassName, $"Failed to load Firefox favicon DB: {faviconDbPath}", ex);
}
}
@ -218,7 +219,7 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader
}
catch (Exception ex)
{
Log.Exception($"Failed to save image: {outputPath}", ex);
Main._context.API.LogException(ClassName, $"Failed to save image: {outputPath}", ex);
}
}
}

View file

@ -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>

View file

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin.BrowserBookmark.Commands;
using Flow.Launcher.Plugin.BrowserBookmark.Models;
using Flow.Launcher.Plugin.BrowserBookmark.Views;
@ -15,7 +14,7 @@ namespace Flow.Launcher.Plugin.BrowserBookmark;
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu, IDisposable
{
private static PluginInitContext _context;
internal static PluginInitContext _context;
private static List<Bookmark> _cachedBookmarks = new();
@ -23,16 +22,6 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
private static bool _initialized = false;
public static PluginInitContext GetContext()
{
return _context;
}
public static string GetPluginDirectory()
{
return _context?.CurrentPluginMetadata?.PluginDirectory;
}
public void Init(PluginInitContext context)
{
_context = context;
@ -223,7 +212,7 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
catch (Exception e)
{
var message = "Failed to set url in clipboard";
Log.Exception("Main", message, e, "LoadContextMenus");
_context.API.LogException(nameof(Main), message, e);
_context.API.ShowMsg(message);