Skip to content

Commit b639960

Browse files
authored
Merge branch 'dev' into sys_plugin_improvement
2 parents 4652392 + 4f269d3 commit b639960

File tree

47 files changed

+2968
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2968
-166
lines changed

Flow.Launcher.Core/Configuration/Portable.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public void DisablePortableMode()
4545
#endif
4646
IndicateDeletion(DataLocation.PortableDataPath);
4747

48-
API.ShowMsgBox("Flow Launcher needs to restart to finish disabling portable mode, " +
49-
"after the restart your portable data profile will be deleted and roaming data profile kept");
48+
API.ShowMsgBox(API.GetTranslation("restartToDisablePortableMode"));
5049

5150
UpdateManager.RestartApp(Constant.ApplicationFileName);
5251
}
@@ -69,8 +68,7 @@ public void EnablePortableMode()
6968
#endif
7069
IndicateDeletion(DataLocation.RoamingDataPath);
7170

72-
API.ShowMsgBox("Flow Launcher needs to restart to finish enabling portable mode, " +
73-
"after the restart your roaming data profile will be deleted and portable data profile kept");
71+
API.ShowMsgBox(API.GetTranslation("restartToEnablePortableMode"));
7472

7573
UpdateManager.RestartApp(Constant.ApplicationFileName);
7674
}
@@ -154,9 +152,8 @@ public void PreStartCleanUpAfterPortabilityUpdate()
154152
{
155153
FilesFolders.RemoveFolderIfExists(roamingDataDir, (s) => API.ShowMsgBox(s));
156154

157-
if (API.ShowMsgBox("Flow Launcher has detected you enabled portable mode, " +
158-
"would you like to move it to a different location?", string.Empty,
159-
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
155+
if (API.ShowMsgBox(API.GetTranslation("moveToDifferentLocation"),
156+
string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
160157
{
161158
FilesFolders.OpenPath(Constant.RootDirectory, (s) => API.ShowMsgBox(s));
162159

@@ -169,8 +166,7 @@ public void PreStartCleanUpAfterPortabilityUpdate()
169166
{
170167
FilesFolders.RemoveFolderIfExists(portableDataDir, (s) => API.ShowMsgBox(s));
171168

172-
API.ShowMsgBox("Flow Launcher has detected you disabled portable mode, " +
173-
"the relevant shortcuts and uninstaller entry have been created");
169+
API.ShowMsgBox(API.GetTranslation("shortcutsUninstallerCreated"));
174170
}
175171
}
176172

@@ -181,9 +177,8 @@ public bool CanUpdatePortability()
181177

182178
if (roamingLocationExists && portableLocationExists)
183179
{
184-
API.ShowMsgBox(string.Format("Flow Launcher detected your user data exists both in {0} and " +
185-
"{1}. {2}{2}Please delete {1} in order to proceed. No changes have occurred.",
186-
DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine));
180+
API.ShowMsgBox(string.Format(API.GetTranslation("userDataDuplicated"),
181+
DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine));
187182

188183
return false;
189184
}

Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public static class PluginsManifest
2222
private static DateTime lastFetchedAt = DateTime.MinValue;
2323
private static readonly TimeSpan fetchTimeout = TimeSpan.FromMinutes(2);
2424

25+
// We should not initialize API in static constructor because it will create another API instance
26+
private static IPublicAPI api = null;
27+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
28+
2529
public static List<UserPlugin> UserPlugins { get; private set; }
2630

2731
public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default)
@@ -46,7 +50,7 @@ public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = fals
4650
}
4751
catch (Exception e)
4852
{
49-
Ioc.Default.GetRequiredService<IPublicAPI>().LogException(ClassName, "Http request failed", e);
53+
API.LogException(ClassName, "Http request failed", e);
5054
}
5155
finally
5256
{

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 73 additions & 7 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.IO;
@@ -9,6 +9,7 @@
99
using CommunityToolkit.Mvvm.DependencyInjection;
1010
using Flow.Launcher.Core.ExternalPlugins;
1111
using Flow.Launcher.Infrastructure;
12+
using Flow.Launcher.Infrastructure.DialogJump;
1213
using Flow.Launcher.Infrastructure.UserSettings;
1314
using Flow.Launcher.Plugin;
1415
using Flow.Launcher.Plugin.SharedCommands;
@@ -40,6 +41,9 @@ public static class PluginManager
4041
private static IEnumerable<PluginPair> _resultUpdatePlugin;
4142
private static IEnumerable<PluginPair> _translationPlugins;
4243

44+
private static readonly List<DialogJumpExplorerPair> _dialogJumpExplorerPlugins = new();
45+
private static readonly List<DialogJumpDialogPair> _dialogJumpDialogPlugins = new();
46+
4347
/// <summary>
4448
/// Directories that will hold Flow Launcher plugin directory
4549
/// </summary>
@@ -186,6 +190,24 @@ public static void LoadPlugins(PluginsSettings settings)
186190
_homePlugins = GetPluginsForInterface<IAsyncHomeQuery>();
187191
_resultUpdatePlugin = GetPluginsForInterface<IResultUpdated>();
188192
_translationPlugins = GetPluginsForInterface<IPluginI18n>();
193+
194+
// Initialize Dialog Jump plugin pairs
195+
foreach (var pair in GetPluginsForInterface<IDialogJumpExplorer>())
196+
{
197+
_dialogJumpExplorerPlugins.Add(new DialogJumpExplorerPair
198+
{
199+
Plugin = (IDialogJumpExplorer)pair.Plugin,
200+
Metadata = pair.Metadata
201+
});
202+
}
203+
foreach (var pair in GetPluginsForInterface<IDialogJumpDialog>())
204+
{
205+
_dialogJumpDialogPlugins.Add(new DialogJumpDialogPair
206+
{
207+
Plugin = (IDialogJumpDialog)pair.Plugin,
208+
Metadata = pair.Metadata
209+
});
210+
}
189211
}
190212

191213
private static void UpdatePluginDirectory(List<PluginMetadata> metadatas)
@@ -288,20 +310,24 @@ public static async Task InitializePluginsAsync()
288310
}
289311
}
290312

291-
public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
313+
public static ICollection<PluginPair> ValidPluginsForQuery(Query query, bool dialogJump)
292314
{
293315
if (query is null)
294316
return Array.Empty<PluginPair>();
295317

296318
if (!NonGlobalPlugins.TryGetValue(query.ActionKeyword, out var plugin))
297319
{
298-
return GlobalPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
320+
if (dialogJump)
321+
return GlobalPlugins.Where(p => p.Plugin is IAsyncDialogJump && !PluginModified(p.Metadata.ID)).ToList();
322+
else
323+
return GlobalPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
299324
}
300325

326+
if (dialogJump && plugin.Plugin is not IAsyncDialogJump)
327+
return Array.Empty<PluginPair>();
328+
301329
if (API.PluginModified(plugin.Metadata.ID))
302-
{
303330
return Array.Empty<PluginPair>();
304-
}
305331

306332
return new List<PluginPair>
307333
{
@@ -388,6 +414,36 @@ public static async Task<List<Result>> QueryHomeForPluginAsync(PluginPair pair,
388414
return results;
389415
}
390416

417+
public static async Task<List<DialogJumpResult>> QueryDialogJumpForPluginAsync(PluginPair pair, Query query, CancellationToken token)
418+
{
419+
var results = new List<DialogJumpResult>();
420+
var metadata = pair.Metadata;
421+
422+
try
423+
{
424+
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
425+
async () => results = await ((IAsyncDialogJump)pair.Plugin).QueryDialogJumpAsync(query, token).ConfigureAwait(false));
426+
427+
token.ThrowIfCancellationRequested();
428+
if (results == null)
429+
return null;
430+
UpdatePluginMetadata(results, metadata, query);
431+
432+
token.ThrowIfCancellationRequested();
433+
}
434+
catch (OperationCanceledException)
435+
{
436+
// null will be fine since the results will only be added into queue if the token hasn't been cancelled
437+
return null;
438+
}
439+
catch (Exception e)
440+
{
441+
API.LogException(ClassName, $"Failed to query Dialog Jump for plugin: {metadata.Name}", e);
442+
return null;
443+
}
444+
return results;
445+
}
446+
391447
public static void UpdatePluginMetadata(IReadOnlyList<Result> results, PluginMetadata metadata, Query query)
392448
{
393449
foreach (var r in results)
@@ -463,6 +519,16 @@ public static bool IsHomePlugin(string id)
463519
return _homePlugins.Where(p => !PluginModified(p.Metadata.ID)).Any(p => p.Metadata.ID == id);
464520
}
465521

522+
public static IList<DialogJumpExplorerPair> GetDialogJumpExplorers()
523+
{
524+
return _dialogJumpExplorerPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
525+
}
526+
527+
public static IList<DialogJumpDialogPair> GetDialogJumpDialogs()
528+
{
529+
return _dialogJumpDialogPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
530+
}
531+
466532
public static bool ActionKeywordRegistered(string actionKeyword)
467533
{
468534
// this method is only checking for action keywords (defined as not '*') registration
@@ -719,7 +785,7 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
719785
catch (Exception e)
720786
{
721787
API.LogException(ClassName, $"Failed to delete plugin settings folder for {plugin.Name}", e);
722-
API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"),
788+
API.ShowMsgError(API.GetTranslation("failedToRemovePluginSettingsTitle"),
723789
string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name));
724790
}
725791
}
@@ -735,7 +801,7 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
735801
catch (Exception e)
736802
{
737803
API.LogException(ClassName, $"Failed to delete plugin cache folder for {plugin.Name}", e);
738-
API.ShowMsg(API.GetTranslation("failedToRemovePluginCacheTitle"),
804+
API.ShowMsgError(API.GetTranslation("failedToRemovePluginCacheTitle"),
739805
string.Format(API.GetTranslation("failedToRemovePluginCacheMessage"), plugin.Name));
740806
}
741807
Settings.RemovePluginSettings(plugin.ID);

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ private static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source
120120
{
121121
var errorPluginString = string.Join(Environment.NewLine, erroredPlugins);
122122

123-
var errorMessage = "The following "
124-
+ (erroredPlugins.Count > 1 ? "plugins have " : "plugin has ")
125-
+ "errored and cannot be loaded:";
123+
var errorMessage = erroredPlugins.Count > 1 ?
124+
API.GetTranslation("pluginsHaveErrored") :
125+
API.GetTranslation("pluginHasErrored");
126126

127127
_ = Task.Run(() =>
128128
{
129-
Ioc.Default.GetRequiredService<IPublicAPI>().ShowMsgBox($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
129+
API.ShowMsgBox($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
130130
$"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
131-
$"Please refer to the logs for more information", "",
131+
API.GetTranslation("referToLogs"), string.Empty,
132132
MessageBoxButton.OK, MessageBoxImage.Warning);
133133
});
134134
}

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public bool PromptShouldUsePinyin(string languageCodeToSet)
214214
// "Do you want to search with pinyin?"
215215
string text = languageToSet == AvailableLanguages.Chinese ? "是否启用拼音搜索?" : "是否啓用拼音搜索?" ;
216216

217-
if (Ioc.Default.GetRequiredService<IPublicAPI>().ShowMsgBox(text, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
217+
if (API.ShowMsgBox(text, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
218218
return false;
219219

220220
return true;

Flow.Launcher.Core/Updater.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public async Task UpdateAppAsync(bool silentUpdate = true)
111111
}
112112

113113
if (!silentUpdate)
114-
_api.ShowMsg(_api.GetTranslation("update_flowlauncher_fail"),
114+
_api.ShowMsgError(_api.GetTranslation("update_flowlauncher_fail"),
115115
_api.GetTranslation("update_flowlauncher_check_connection"));
116116
}
117117
finally

0 commit comments

Comments
 (0)