From 50130e4b009ae5a808b7b65d3238d0785c60b0df Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 13 Apr 2025 17:59:39 +0800 Subject: [PATCH] Use class name instead --- Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs | 4 +++- Flow.Launcher/Helper/WallpaperPathRetrieval.cs | 10 ++++++---- Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs | 4 +++- Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs | 4 +++- .../Search/DirectoryInfo/DirectoryInfoSearch.cs | 4 +++- .../ProcessHelper.cs | 4 +++- .../SuggestionSources/Baidu.cs | 6 ++++-- .../SuggestionSources/Bing.cs | 6 ++++-- .../SuggestionSources/DuckDuckGo.cs | 6 ++++-- .../SuggestionSources/Google.cs | 6 ++++-- Plugins/Flow.Launcher.Plugin.WindowsSettings/Log.cs | 2 ++ 11 files changed, 39 insertions(+), 17 deletions(-) diff --git a/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs b/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs index 44d3ef0ff..7ca91eaec 100644 --- a/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs +++ b/Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs @@ -9,6 +9,8 @@ namespace Flow.Launcher.Core.ExternalPlugins { public static class PluginsManifest { + private static readonly string ClassName = nameof(PluginsManifest); + private static readonly CommunityPluginStore mainPluginStore = new("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json", "https://fastly.jsdelivr.net/gh/Flow-Launcher/Flow.Launcher.PluginsManifest@plugin_api_v2/plugins.json", @@ -44,7 +46,7 @@ namespace Flow.Launcher.Core.ExternalPlugins } catch (Exception e) { - Ioc.Default.GetRequiredService().LogException(nameof(PluginsManifest), "Http request failed", e); + Ioc.Default.GetRequiredService().LogException(ClassName, "Http request failed", e); } finally { diff --git a/Flow.Launcher/Helper/WallpaperPathRetrieval.cs b/Flow.Launcher/Helper/WallpaperPathRetrieval.cs index 77bebe2d3..93b9a8aaa 100644 --- a/Flow.Launcher/Helper/WallpaperPathRetrieval.cs +++ b/Flow.Launcher/Helper/WallpaperPathRetrieval.cs @@ -12,6 +12,8 @@ namespace Flow.Launcher.Helper; public static class WallpaperPathRetrieval { + private static readonly string ClassName = nameof(WallpaperPathRetrieval); + private const int MaxCacheSize = 3; private static readonly Dictionary<(string, DateTime), ImageBrush> WallpaperCache = new(); private static readonly object CacheLock = new(); @@ -29,7 +31,7 @@ public static class WallpaperPathRetrieval var wallpaperPath = Win32Helper.GetWallpaperPath(); if (string.IsNullOrEmpty(wallpaperPath) || !File.Exists(wallpaperPath)) { - App.API.LogInfo(nameof(WallpaperPathRetrieval), $"Wallpaper path is invalid: {wallpaperPath}"); + App.API.LogInfo(ClassName, $"Wallpaper path is invalid: {wallpaperPath}"); var wallpaperColor = GetWallpaperColor(); return new SolidColorBrush(wallpaperColor); } @@ -54,7 +56,7 @@ public static class WallpaperPathRetrieval if (originalWidth == 0 || originalHeight == 0) { - App.API.LogInfo(nameof(WallpaperPathRetrieval), $"Failed to load bitmap: Width={originalWidth}, Height={originalHeight}"); + App.API.LogInfo(ClassName, $"Failed to load bitmap: Width={originalWidth}, Height={originalHeight}"); return new SolidColorBrush(Colors.Transparent); } @@ -95,7 +97,7 @@ public static class WallpaperPathRetrieval } catch (Exception ex) { - App.API.LogException(nameof(WallpaperPathRetrieval), "Error retrieving wallpaper", ex); + App.API.LogException(ClassName, "Error retrieving wallpaper", ex); return new SolidColorBrush(Colors.Transparent); } } @@ -113,7 +115,7 @@ public static class WallpaperPathRetrieval } catch (Exception ex) { - App.API.LogException(nameof(WallpaperPathRetrieval), "Error parsing wallpaper color", ex); + App.API.LogException(ClassName, "Error parsing wallpaper color", ex); } } diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs index 3bee49bf2..9ad31ad14 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs @@ -15,6 +15,8 @@ namespace Flow.Launcher.Plugin.BrowserBookmark; public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu, IDisposable { + private static readonly string ClassName = nameof(Main); + internal static string _faviconCacheDir; internal static PluginInitContext _context; @@ -221,7 +223,7 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex catch (Exception e) { var message = "Failed to set url in clipboard"; - _context.API.LogException(nameof(Main), message, e); + _context.API.LogException(ClassName, message, e); _context.API.ShowMsg(message); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs index f47907824..633af7b6b 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs @@ -15,6 +15,8 @@ namespace Flow.Launcher.Plugin.Explorer { internal class ContextMenu : IContextMenu { + private static readonly string ClassName = nameof(ContextMenu); + private PluginInitContext Context { get; set; } private Settings Settings { get; set; } @@ -469,7 +471,7 @@ namespace Flow.Launcher.Plugin.Explorer private void LogException(string message, Exception e) { - Context.API.LogException(nameof(ContextMenu), message, e); + Context.API.LogException(ClassName, message, e); } private static bool CanRunAsDifferentUser(string path) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs index 1a0d3bd15..631744252 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs @@ -9,6 +9,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo { public static class DirectoryInfoSearch { + private static readonly string ClassName = nameof(DirectoryInfoSearch); + internal static IEnumerable TopLevelDirectorySearch(Query query, string search, CancellationToken token) { var criteria = ConstructSearchCriteria(search); @@ -75,7 +77,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo } catch (Exception e) { - Main.Context.API.LogException(nameof(DirectoryInfoSearch), "Error occurred while searching path", e); + Main.Context.API.LogException(ClassName, "Error occurred while searching path", e); throw; } diff --git a/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs b/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs index 4c07341ec..d7f44ccce 100644 --- a/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs @@ -12,6 +12,8 @@ namespace Flow.Launcher.Plugin.ProcessKiller { internal class ProcessHelper { + private static readonly string ClassName = nameof(ProcessHelper); + private readonly HashSet _systemProcessList = new() { "conhost", @@ -131,7 +133,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller } catch (Exception e) { - context.API.LogException($"{nameof(ProcessHelper)}", $"Failed to kill process {p.ProcessName}", e); + context.API.LogException(ClassName, $"Failed to kill process {p.ProcessName}", e); } } diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs index 65be06b53..681c8b649 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs @@ -11,6 +11,8 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources { public class Baidu : SuggestionSource { + private static readonly string ClassName = nameof(Baidu); + private readonly Regex _reg = new Regex("window.baidu.sug\\((.*)\\)"); public override async Task> SuggestionsAsync(string query, CancellationToken token) @@ -24,7 +26,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources } catch (Exception e) when (e is HttpRequestException or {InnerException: TimeoutException}) { - Main._context.API.LogException(nameof(Baidu), "Can't get suggestion from Baidu", e); + Main._context.API.LogException(ClassName, "Can't get suggestion from Baidu", e); return null; } @@ -39,7 +41,7 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources } catch (JsonException e) { - Main._context.API.LogException(nameof(Baidu), "Can't parse suggestions", e); + Main._context.API.LogException(ClassName, "Can't parse suggestions", e); return new List(); } diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs index 9efc36263..ccfa5dcc8 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs @@ -10,6 +10,8 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources { public class Bing : SuggestionSource { + private static readonly string ClassName = nameof(Bing); + public override async Task> SuggestionsAsync(string query, CancellationToken token) { try @@ -33,12 +35,12 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources } catch (Exception e) when (e is HttpRequestException or { InnerException: TimeoutException }) { - Main._context.API.LogException(nameof(Bing), "Can't get suggestion from Bing", e); + Main._context.API.LogException(ClassName, "Can't get suggestion from Bing", e); return null; } catch (JsonException e) { - Main._context.API.LogException(nameof(Bing), "Can't parse suggestions", e); + Main._context.API.LogException(ClassName, "Can't parse suggestions", e); return new List(); } } diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs index 1d248caf3..0627f7220 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs @@ -10,6 +10,8 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources { public class DuckDuckGo : SuggestionSource { + private static readonly string ClassName = nameof(DuckDuckGo); + public override async Task> SuggestionsAsync(string query, CancellationToken token) { // When the search query is empty, DuckDuckGo returns `[]`. When it's not empty, it returns data @@ -34,12 +36,12 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources } catch (Exception e) when (e is HttpRequestException or {InnerException: TimeoutException}) { - Main._context.API.LogException(nameof(DuckDuckGo), "Can't get suggestion from DuckDuckGo", e); + Main._context.API.LogException(ClassName, "Can't get suggestion from DuckDuckGo", e); return null; } catch (JsonException e) { - Main._context.API.LogException(nameof(DuckDuckGo), "Can't parse suggestions", e); + Main._context.API.LogException(ClassName, "Can't parse suggestions", e); return new List(); } } diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs index ad8fb508f..f28212524 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs @@ -10,6 +10,8 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources { public class Google : SuggestionSource { + private static readonly string ClassName = nameof(Google); + public override async Task> SuggestionsAsync(string query, CancellationToken token) { try @@ -27,12 +29,12 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources } catch (Exception e) when (e is HttpRequestException or {InnerException: TimeoutException}) { - Main._context.API.LogException(nameof(Google), "Can't get suggestion from Google", e); + Main._context.API.LogException(ClassName, "Can't get suggestion from Google", e); return null; } catch (JsonException e) { - Main._context.API.LogException(nameof(Google), "Can't parse suggestions", e); + Main._context.API.LogException(ClassName, "Can't parse suggestions", e); return new List(); } } diff --git a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Log.cs b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Log.cs index 257b0fa8b..c72230f2b 100644 --- a/Plugins/Flow.Launcher.Plugin.WindowsSettings/Log.cs +++ b/Plugins/Flow.Launcher.Plugin.WindowsSettings/Log.cs @@ -11,10 +11,12 @@ namespace Flow.Launcher.Plugin.WindowsSettings { _api = api; } + public static void Exception(string message, Exception exception, Type type, [CallerMemberName] string methodName = "") { _api?.LogException(type.FullName, message, exception, methodName); } + public static void Warn(string message, Type type, [CallerMemberName] string methodName = "") { _api?.LogWarn(type.FullName, message, methodName);