Skip to content

Commit 8387e72

Browse files
committed
Refactor logging system and remove unused dependencies
Replaced `FlowSettings.LogLevel` with `PublicApi.Instance.GetLogLevel()` for dynamic log level retrieval. Introduced a centralized `LOGLEVEL` enum in the `Flow.Launcher.Plugin` namespace to standardize log level definitions. Added `GetLogLevel()` to the `IPublicAPI` interface for plugin access. Removed the dependency on `CommunityToolkit.Mvvm.DependencyInjection` and unused namespaces across multiple files. Updated `PublicAPIInstance` to use a `Lock` type for `_saveSettingsLock`. Introduced a new `LogLevel.cs` file for the `LOGLEVEL` enum and removed the old enum from `Flow.Launcher.Infrastructure.Logger`. Improved modularity, maintainability, and extensibility of the logging system while streamlining the codebase.
1 parent a2188ac commit 8387e72

File tree

8 files changed

+43
-18
lines changed

8 files changed

+43
-18
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
using System.Text.Json;
77
using System.Threading;
88
using System.Threading.Tasks;
9-
using CommunityToolkit.Mvvm.DependencyInjection;
109
using Flow.Launcher.Core.ExternalPlugins;
1110
using Flow.Launcher.Core.Resource;
1211
using Flow.Launcher.Infrastructure;
1312
using Flow.Launcher.Infrastructure.DialogJump;
14-
using Flow.Launcher.Infrastructure.Logger;
1513
using Flow.Launcher.Infrastructure.UserSettings;
1614
using Flow.Launcher.Plugin;
1715
using Flow.Launcher.Plugin.SharedCommands;
@@ -34,7 +32,6 @@ public static class PluginManager
3432
private static readonly ConcurrentDictionary<string, PluginPair> _nonGlobalPlugins = [];
3533

3634
private static PluginsSettings Settings;
37-
private static readonly Settings FlowSettings = Ioc.Default.GetRequiredService<Settings>();
3835
private static readonly ConcurrentBag<string> ModifiedPlugins = [];
3936

4037
private static readonly ConcurrentBag<PluginPair> _contextMenuPlugins = [];
@@ -280,14 +277,14 @@ public static async Task InitializePluginsAsync(IResultUpdateRegister register)
280277
{
281278
// If this plugin is already disabled, do not show error message again
282279
// Or else it will be shown every time
283-
if (FlowSettings.LogLevel == LOGLEVEL.DEBUG)
280+
if (PublicApi.Instance.GetLogLevel() == LOGLEVEL.DEBUG)
284281
PublicApi.Instance.LogDebug(ClassName, $"Skipped init for <{pair.Metadata.Name}> due to error");
285282
}
286283
else
287284
{
288285
pair.Metadata.Disabled = true;
289286
pair.Metadata.HomeDisabled = true;
290-
if (FlowSettings.LogLevel == LOGLEVEL.DEBUG)
287+
if (PublicApi.Instance.GetLogLevel() == LOGLEVEL.DEBUG)
291288
PublicApi.Instance.LogDebug(ClassName, $"Disable plugin <{pair.Metadata.Name}> because init failed");
292289
}
293290

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 1 addition & 3 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.Reflection;
5-
using CommunityToolkit.Mvvm.DependencyInjection;
65
using Flow.Launcher.Core.ExternalPlugins.Environments;
76
#pragma warning disable IDE0005
87
using Flow.Launcher.Infrastructure.Logger;
@@ -15,7 +14,6 @@ namespace Flow.Launcher.Core.Plugin
1514
public static class PluginsLoader
1615
{
1716
private static readonly string ClassName = nameof(PluginsLoader);
18-
private static readonly Settings FlowSettings = Ioc.Default.GetRequiredService<Settings>();
1917

2018
public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
2119
{
@@ -110,7 +108,7 @@ private static List<PluginPair> DotNetPlugins(List<PluginMetadata> source)
110108
});
111109

112110
metadata.InitTime += milliseconds;
113-
if (FlowSettings.LogLevel == LOGLEVEL.DEBUG)
111+
if (PublicApi.Instance.GetLogLevel() == LOGLEVEL.DEBUG)
114112
PublicApi.Instance.LogDebug(ClassName, $"Constructor cost for <{metadata.Name}> is <{metadata.InitTime}ms>");
115113
}
116114

Flow.Launcher.Infrastructure/Http/Http.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using Flow.Launcher.Infrastructure.Logger;
88
using Flow.Launcher.Infrastructure.UserSettings;
9+
using Flow.Launcher.Plugin;
910
using JetBrains.Annotations;
1011

1112
namespace Flow.Launcher.Infrastructure.Http

Flow.Launcher.Infrastructure/Logger/Log.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.CompilerServices;
44
using System.Runtime.ExceptionServices;
55
using Flow.Launcher.Infrastructure.UserSettings;
6+
using Flow.Launcher.Plugin;
67
using NLog;
78
using NLog.Config;
89
using NLog.Targets;
@@ -167,12 +168,4 @@ public static void Warn(string className, string message, [CallerMemberName] str
167168
LogInternal(NLog.LogLevel.Warn, className, message, methodName);
168169
}
169170
}
170-
171-
public enum LOGLEVEL
172-
{
173-
NONE,
174-
ERROR,
175-
INFO,
176-
DEBUG
177-
}
178171
}

Flow.Launcher.Infrastructure/Stopwatch.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Runtime.CompilerServices;
33
using System.Threading.Tasks;
44
using Flow.Launcher.Infrastructure.Logger;
5+
using Flow.Launcher.Plugin;
56

67
namespace Flow.Launcher.Infrastructure
78
{

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,5 +637,11 @@ public interface IPublicAPI
637637
/// </summary>
638638
/// <returns></returns>
639639
string GetLogDirectory();
640+
641+
/// <summary>
642+
/// Get the current log level of Flow Launcher.
643+
/// </summary>
644+
/// <returns></returns>
645+
LOGLEVEL GetLogLevel();
640646
}
641647
}

Flow.Launcher.Plugin/LogLevel.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Flow.Launcher.Plugin;
2+
3+
/// <summary>
4+
/// Log level enum used in Flow
5+
/// </summary>
6+
public enum LOGLEVEL
7+
{
8+
/// <summary>
9+
/// No log will be produced
10+
/// </summary>
11+
NONE,
12+
13+
/// <summary>
14+
/// Only error log will be produced
15+
/// </summary>
16+
ERROR,
17+
18+
/// <summary>
19+
/// Info and error log will be produced
20+
/// </summary>
21+
INFO,
22+
23+
/// <summary>
24+
/// Debug, info and error log will be produced
25+
/// </summary>
26+
DEBUG
27+
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Collections.Specialized;
@@ -52,7 +52,7 @@ public class PublicAPIInstance : IPublicAPI, IRemovable
5252
private Updater _updater;
5353
private Updater Updater => _updater ??= Ioc.Default.GetRequiredService<Updater>();
5454

55-
private readonly object _saveSettingsLock = new();
55+
private readonly Lock _saveSettingsLock = new();
5656

5757
#region Constructor
5858

@@ -623,6 +623,8 @@ public event ActualApplicationThemeChangedEventHandler ActualApplicationThemeCha
623623

624624
public string GetLogDirectory() => DataLocation.VersionLogDirectory;
625625

626+
public LOGLEVEL GetLogLevel() => Log.LogLevel;
627+
626628
#endregion
627629

628630
#region Private Methods

0 commit comments

Comments
 (0)