Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core.ExternalPlugins;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.DialogJump;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedCommands;
Expand All @@ -32,6 +34,7 @@
private static readonly ConcurrentDictionary<string, PluginPair> _nonGlobalPlugins = [];

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

private static readonly ConcurrentBag<PluginPair> _contextMenuPlugins = [];
Expand Down Expand Up @@ -277,13 +280,15 @@
{
// If this plugin is already disabled, do not show error message again
// Or else it will be shown every time
PublicApi.Instance.LogDebug(ClassName, $"Skipped init for <{pair.Metadata.Name}> due to error");
if (FlowSettings.LogLevel == LOGLEVEL.DEBUG)
PublicApi.Instance.LogDebug(ClassName, $"Skipped init for <{pair.Metadata.Name}> due to error");
}
else
{
pair.Metadata.Disabled = true;
pair.Metadata.HomeDisabled = true;
PublicApi.Instance.LogDebug(ClassName, $"Disable plugin <{pair.Metadata.Name}> because init failed");
if (FlowSettings.LogLevel == LOGLEVEL.DEBUG)
PublicApi.Instance.LogDebug(ClassName, $"Disable plugin <{pair.Metadata.Name}> because init failed");
}

// Even if the plugin cannot be initialized, we still need to add it in all plugin list so that
Expand Down Expand Up @@ -599,7 +604,7 @@
r.OriginQuery = query;

// ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions
// Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level

Check warning on line 607 in Flow.Launcher.Core/Plugin/PluginManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`overriden` is not a recognized word. (unrecognized-spelling)
if (metadata.ActionKeywords.Count == 1)
r.ActionKeywordAssigned = query.ActionKeyword;
}
Expand Down Expand Up @@ -919,7 +924,7 @@
"CEA08895D2544B019B2E9C5009600DF4", // Sys
"0308FD86DE0A4DEE8D62B9B535370992", // URL
"565B73353DBF4806919830B9202EE3BF", // WebSearch
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings

Check warning on line 927 in Flow.Launcher.Core/Plugin/PluginManager.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`CETYU` is not a recognized word. (unrecognized-spelling)
};

// Treat default plugin differently, it needs to be removable along with each flow release
Expand Down
5 changes: 4 additions & 1 deletion Flow.Launcher.Core/Plugin/PluginsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core.ExternalPlugins.Environments;
#pragma warning disable IDE0005
using Flow.Launcher.Infrastructure.Logger;
Expand All @@ -14,6 +15,7 @@ namespace Flow.Launcher.Core.Plugin
public static class PluginsLoader
{
private static readonly string ClassName = nameof(PluginsLoader);
private static readonly Settings FlowSettings = Ioc.Default.GetRequiredService<Settings>();

public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
{
Expand Down Expand Up @@ -108,7 +110,8 @@ private static List<PluginPair> DotNetPlugins(List<PluginMetadata> source)
});

metadata.InitTime += milliseconds;
PublicApi.Instance.LogDebug(ClassName, $"Constructor cost for <{metadata.Name}> is <{metadata.InitTime}ms>");
if (FlowSettings.LogLevel == LOGLEVEL.DEBUG)
PublicApi.Instance.LogDebug(ClassName, $"Constructor cost for <{metadata.Name}> is <{metadata.InitTime}ms>");
}

if (erroredPlugins.Count > 0)
Expand Down
19 changes: 13 additions & 6 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.DialogJump;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Storage;
using iNKORE.UI.WPF.Modern;

Check warning on line 28 in Flow.Launcher/ViewModel/MainViewModel.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`NKORE` is not a recognized word. (unrecognized-spelling)
using Microsoft.VisualStudio.Threading;

namespace Flow.Launcher.ViewModel
Expand Down Expand Up @@ -271,7 +272,7 @@
#if DEBUG
throw t.Exception;
#else
App.API.LogError(ClassName, $"Error happen in task dealing with viewupdate for results. {t.Exception}");

Check warning on line 275 in Flow.Launcher/ViewModel/MainViewModel.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`viewupdate` is not a recognized word. (unrecognized-spelling)
_resultsViewUpdateTask =
Task.Run(UpdateActionAsync).ContinueWith(continueAction, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);
#endif
Expand Down Expand Up @@ -314,7 +315,8 @@

if (token.IsCancellationRequested) return;

App.API.LogDebug(ClassName, $"Update results for plugin <{pair.Metadata.Name}>");
if (Settings.LogLevel == LOGLEVEL.DEBUG)
App.API.LogDebug(ClassName, $"Update results for plugin <{pair.Metadata.Name}>");

if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, pair.Metadata, e.Query,
token)))
Expand Down Expand Up @@ -468,7 +470,7 @@
else if (!string.IsNullOrEmpty(SelectedResults.SelectedItem?.QuerySuggestionText))
{
//var defaultSuggestion = SelectedResults.SelectedItem.QuerySuggestionText;
//// check if result.actionkeywordassigned is empty

Check warning on line 473 in Flow.Launcher/ViewModel/MainViewModel.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`actionkeywordassigned` is not a recognized word. (unrecognized-spelling)
//if (!string.IsNullOrEmpty(result.ActionKeywordAssigned))
//{
// autoCompleteText = $"{result.ActionKeywordAssigned} {defaultSuggestion}";
Expand Down Expand Up @@ -1382,7 +1384,8 @@
{
_updateSource?.Cancel();

App.API.LogDebug(ClassName, $"Start query with text: <{QueryText}>");
if (Settings.LogLevel == LOGLEVEL.DEBUG)
App.API.LogDebug(ClassName, $"Start query with text: <{QueryText}>");

var query = await ConstructQueryAsync(QueryText, Settings.CustomShortcuts, Settings.BuiltinShortcuts);

Expand All @@ -1392,7 +1395,8 @@
return;
}

App.API.LogDebug(ClassName, $"Start query with ActionKeyword <{query.ActionKeyword}> and TrimmedQuery <{query.TrimmedQuery}>");
if (Settings.LogLevel == LOGLEVEL.DEBUG)
App.API.LogDebug(ClassName, $"Start query with ActionKeyword <{query.ActionKeyword}> and TrimmedQuery <{query.TrimmedQuery}>");

var currentIsHomeQuery = query.IsHomeQuery;
var currentIsDialogJump = _isDialogJump;
Expand Down Expand Up @@ -1456,7 +1460,8 @@
}
}

App.API.LogDebug(ClassName, $"Valid <{plugins.Count}> plugins: {string.Join(" ", plugins.Select(x => $"<{x.Metadata.Name}>"))}");
if (Settings.LogLevel == LOGLEVEL.DEBUG)
App.API.LogDebug(ClassName, $"Valid <{plugins.Count}> plugins: {string.Join(" ", plugins.Select(x => $"<{x.Metadata.Name}>"))}");

// Do not wait for performance improvement
/*if (string.IsNullOrEmpty(query.ActionKeyword))
Expand Down Expand Up @@ -1560,7 +1565,8 @@

async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
{
App.API.LogDebug(ClassName, $"Wait for querying plugin <{plugin.Metadata.Name}>");
if (Settings.LogLevel == LOGLEVEL.DEBUG)
App.API.LogDebug(ClassName, $"Wait for querying plugin <{plugin.Metadata.Name}>");

if (searchDelay && !currentIsHomeQuery) // Do not delay for home query
{
Expand Down Expand Up @@ -1604,7 +1610,8 @@

if (token.IsCancellationRequested) return;

App.API.LogDebug(ClassName, $"Update results for plugin <{plugin.Metadata.Name}>");
if (Settings.LogLevel == LOGLEVEL.DEBUG)
App.API.LogDebug(ClassName, $"Update results for plugin <{plugin.Metadata.Name}>");

if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query,
token, reSelect)))
Expand Down
5 changes: 4 additions & 1 deletion Flow.Launcher/ViewModel/ResultsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;

Expand Down Expand Up @@ -253,7 +254,9 @@ private List<ResultViewModel> NewResults(ICollection<ResultsForUpdate> resultsFo
return newResults.OrderByDescending(rv => rv.Result.Score).ToList();
}

App.API.LogDebug(ClassName, $"Keeping existing results for {resultsForUpdates.Count} queries");
if (_settings.LogLevel == LOGLEVEL.DEBUG)
App.API.LogDebug(ClassName, $"Keeping existing results for {resultsForUpdates.Count} queries");

return Results.Where(r => r?.Result != null && resultsForUpdates.All(u => u.ID != r.Result.PluginID))
.Concat(newResults)
.OrderByDescending(rv => rv.Result.Score)
Expand Down
Loading