Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
8 changes: 6 additions & 2 deletions Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Flow.Launcher.Core.Plugin.JsonRPCV2Models
{
public class JsonRPCPublicAPI
{
private IPublicAPI _api;
private readonly IPublicAPI _api;

public JsonRPCPublicAPI(IPublicAPI api)
{
Expand Down Expand Up @@ -104,7 +104,6 @@ public List<PluginPair> GetAllPlugins()
return _api.GetAllPlugins();
}


public MatchResult FuzzySearch(string query, string stringToCompare)
{
return _api.FuzzySearch(query, stringToCompare);
Expand Down Expand Up @@ -156,6 +155,11 @@ public void LogWarn(string className, string message, [CallerMemberName] string
_api.LogWarn(className, message, methodName);
}

public void LogError(string className, string message, [CallerMemberName] string methodName = "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the [CallerMemberName] syntax. Is that just apart of the typing of the methodName parameter?

How would this work for json-rpc plugins? Would they make a request like (this is a mockup, I don't remember the exact structure):

{
"method": "LogError",
"params": ["plugin_name", "traceback/stacktrace", "name of method that the plugin was handling"]
}

Copy link
Member Author

@Jack251970 Jack251970 Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the [CallerMemberName] syntax. Is that just apart of the typing of the methodName parameter?

How would this work for json-rpc plugins? Would they make a request like (this is a mockup, I don't remember the exact structure):

{
"method": "LogError",
"params": ["plugin_name", "traceback/stacktrace", "name of method that the plugin was handling"]
}

No sure how to use it, I think we need to manually pass methodName. Just ignore [CallMemberName] which should be used by csharp plugins only.

And usage is the same as LogInfo etc.

{
_api.LogError(className, message, methodName);
}

public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
{
_api.OpenDirectory(DirectoryPath, FileNameOrFilePath);
Expand Down
6 changes: 4 additions & 2 deletions Flow.Launcher.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using Flow.Launcher.Infrastructure.UserSettings;
using NLog;
using NLog.Config;
using NLog.Targets;
using Flow.Launcher.Infrastructure.UserSettings;
using NLog.Targets.Wrappers;
using System.Runtime.ExceptionServices;

namespace Flow.Launcher.Infrastructure.Logger
{
Expand Down Expand Up @@ -135,12 +135,14 @@ private static string CheckClassAndMessageAndReturnFullClassWithMethod(string cl
return className;
}

#if !DEBUG
Copy link
Contributor

@VictoriousRaptor VictoriousRaptor Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need DEBUG macro here? Is ExceptionInternal only used in DEBUG mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need DEBUG macro here? Is ExceptionInternal only used in DEBUG mode?

yes, this function is only used in

ExceptionInternal(prefix, unprefixed, e);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's no need for this. It is ok for the debug version to contain extra symbol.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we alter the usage in log.cs we need to also tweak it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we alter the usage in log.cs we need to also tweak it here.

Could you please explain it further?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we alter the usage in log.cs we need to also tweak it here.

Could you please explain it further?

For example we adapt this change then delete the #if DEBUG else ... in the reference line you post, it will raise a compile error in DEBUG mode since compiler can't find this func.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well. just keep as it was

private static void ExceptionInternal(string classAndMethod, string message, System.Exception e)
{
var logger = LogManager.GetLogger(classAndMethod);

logger.Error(e, message);
}
#endif

private static void LogInternal(string message, LogLevel level)
{
Expand Down
5 changes: 5 additions & 0 deletions Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ public interface IPublicAPI
/// </summary>
void LogWarn(string className, string message, [CallerMemberName] string methodName = "");

/// <summary>
/// Log error message
/// </summary>
void LogError(string className, string message, [CallerMemberName] string methodName = "");

/// <summary>
/// Log an Exception. Will throw if in debug mode so developer will be aware,
/// otherwise logs the eror message. This is the primary logging method used for Flow
Expand Down
38 changes: 26 additions & 12 deletions Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
using System.Threading.Tasks;
using System.Windows;
using CommunityToolkit.Mvvm.DependencyInjection;
using Squirrel;
using Flow.Launcher.Core;
using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Http;
Expand All @@ -27,7 +27,7 @@
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.ViewModel;
using JetBrains.Annotations;
using Flow.Launcher.Core.Resource;
using Squirrel;

namespace Flow.Launcher
{
Expand Down Expand Up @@ -78,7 +78,11 @@ public void RestartApp()

public bool IsMainWindowVisible() => _mainVM.MainWindowVisibilityStatus;

public event VisibilityChangedEventHandler VisibilityChanged { add => _mainVM.VisibilityChanged += value; remove => _mainVM.VisibilityChanged -= value; }
public event VisibilityChangedEventHandler VisibilityChanged
{
add => _mainVM.VisibilityChanged += value;
remove => _mainVM.VisibilityChanged -= value;
}

// Must use Ioc.Default.GetRequiredService<Updater>() to avoid circular dependency
public void CheckForNewUpdate() => _ = Ioc.Default.GetRequiredService<Updater>().UpdateAppAsync(false);
Expand Down Expand Up @@ -162,13 +166,14 @@ public void CopyToClipboard(string stringToCopy, bool directCopy = false, bool s
public MatchResult FuzzySearch(string query, string stringToCompare) =>
StringMatcher.FuzzySearch(query, stringToCompare);

public Task<string> HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url, token);
public Task<string> HttpGetStringAsync(string url, CancellationToken token = default) =>
Http.GetAsync(url, token);

public Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default) =>
Http.GetStreamAsync(url, token);

public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, Action<double> reportProgress = null,
CancellationToken token = default) => Http.DownloadAsync(url, filePath, reportProgress, token);
CancellationToken token = default) =>Http.DownloadAsync(url, filePath, reportProgress, token);

public void AddActionKeyword(string pluginId, string newActionKeyword) =>
PluginManager.AddActionKeyword(pluginId, newActionKeyword);
Expand All @@ -187,8 +192,11 @@ public void LogInfo(string className, string message, [CallerMemberName] string
public void LogWarn(string className, string message, [CallerMemberName] string methodName = "") =>
Log.Warn(className, message, methodName);

public void LogException(string className, string message, Exception e,
[CallerMemberName] string methodName = "") => Log.Exception(className, message, e, methodName);
public void LogError(string className, string message, [CallerMemberName] string methodName = "") =>
Log.Error(className, message, methodName);

public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") =>
Log.Exception(className, message, e, methodName);

private readonly ConcurrentDictionary<Type, object> _pluginJsonStorages = new();

Expand All @@ -201,7 +209,7 @@ public void RemovePluginSettings(string assemblyName)
var name = value.GetType().GetField("AssemblyName")?.GetValue(value)?.ToString();
if (name == assemblyName)
{
_pluginJsonStorages.Remove(key, out var pluginJsonStorage);
_pluginJsonStorages.Remove(key, out var _);
}
}
}
Expand Down Expand Up @@ -330,17 +338,23 @@ public bool IsGameModeOn()

private readonly List<Func<int, int, SpecialKeyState, bool>> _globalKeyboardHandlers = new();

public void RegisterGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Add(callback);
public void RemoveGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Remove(callback);
public void RegisterGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) =>
_globalKeyboardHandlers.Add(callback);

public void RemoveGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) =>
_globalKeyboardHandlers.Remove(callback);

public void ReQuery(bool reselect = true) => _mainVM.ReQuery(reselect);

public void BackToQueryResults() => _mainVM.BackToQueryResults();

public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK) =>
public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "",
MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None,
MessageBoxResult defaultResult = MessageBoxResult.OK) =>
MessageBoxEx.Show(messageBoxText, caption, button, icon, defaultResult);

public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync, Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress);
public Task ShowProgressBoxAsync(string caption, Func<Action<double>, Task> reportProgressAsync,
Action cancelProgress = null) => ProgressBoxEx.ShowAsync(caption, reportProgressAsync, cancelProgress);

#endregion

Expand Down
Loading