Skip to content

Commit 45ed9fa

Browse files
authored
Merge branch 'dev' into rename-file
2 parents 15e4a4f + 4f269d3 commit 45ed9fa

File tree

44 files changed

+2956
-159
lines changed

Some content is hidden

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

44 files changed

+2956
-159
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;
@@ -10,6 +10,7 @@
1010
using CommunityToolkit.Mvvm.DependencyInjection;
1111
using Flow.Launcher.Core.ExternalPlugins;
1212
using Flow.Launcher.Infrastructure;
13+
using Flow.Launcher.Infrastructure.DialogJump;
1314
using Flow.Launcher.Infrastructure.Hotkey;
1415
using Flow.Launcher.Infrastructure.UserSettings;
1516
using Flow.Launcher.Plugin;
@@ -48,6 +49,9 @@ public static class PluginManager
4849
private static readonly Dictionary<PluginPair, List<BasePluginHotkey>> _pluginHotkeyInfo = new();
4950
private static readonly Dictionary<HotkeyModel, List<(PluginMetadata, SearchWindowPluginHotkey)>> _windowPluginHotkeys = new();
5051

52+
private static readonly List<DialogJumpExplorerPair> _dialogJumpExplorerPlugins = new();
53+
private static readonly List<DialogJumpDialogPair> _dialogJumpDialogPlugins = new();
54+
5155
/// <summary>
5256
/// Directories that will hold Flow Launcher plugin directory
5357
/// </summary>
@@ -195,6 +199,24 @@ public static void LoadPlugins(PluginsSettings settings)
195199
_resultUpdatePlugin = GetPluginsForInterface<IResultUpdated>();
196200
_translationPlugins = GetPluginsForInterface<IPluginI18n>();
197201
_hotkeyPlugins = GetPluginsForInterface<IPluginHotkey>();
202+
203+
// Initialize Dialog Jump plugin pairs
204+
foreach (var pair in GetPluginsForInterface<IDialogJumpExplorer>())
205+
{
206+
_dialogJumpExplorerPlugins.Add(new DialogJumpExplorerPair
207+
{
208+
Plugin = (IDialogJumpExplorer)pair.Plugin,
209+
Metadata = pair.Metadata
210+
});
211+
}
212+
foreach (var pair in GetPluginsForInterface<IDialogJumpDialog>())
213+
{
214+
_dialogJumpDialogPlugins.Add(new DialogJumpDialogPair
215+
{
216+
Plugin = (IDialogJumpDialog)pair.Plugin,
217+
Metadata = pair.Metadata
218+
});
219+
}
198220
}
199221

200222
private static void UpdatePluginDirectory(List<PluginMetadata> metadatas)
@@ -301,20 +323,24 @@ public static async Task InitializePluginsAsync()
301323
}
302324
}
303325

304-
public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
326+
public static ICollection<PluginPair> ValidPluginsForQuery(Query query, bool dialogJump)
305327
{
306328
if (query is null)
307329
return Array.Empty<PluginPair>();
308330

309331
if (!NonGlobalPlugins.TryGetValue(query.ActionKeyword, out var plugin))
310332
{
311-
return GlobalPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
333+
if (dialogJump)
334+
return GlobalPlugins.Where(p => p.Plugin is IAsyncDialogJump && !PluginModified(p.Metadata.ID)).ToList();
335+
else
336+
return GlobalPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
312337
}
313338

339+
if (dialogJump && plugin.Plugin is not IAsyncDialogJump)
340+
return Array.Empty<PluginPair>();
341+
314342
if (API.PluginModified(plugin.Metadata.ID))
315-
{
316343
return Array.Empty<PluginPair>();
317-
}
318344

319345
return new List<PluginPair>
320346
{
@@ -401,6 +427,36 @@ public static async Task<List<Result>> QueryHomeForPluginAsync(PluginPair pair,
401427
return results;
402428
}
403429

430+
public static async Task<List<DialogJumpResult>> QueryDialogJumpForPluginAsync(PluginPair pair, Query query, CancellationToken token)
431+
{
432+
var results = new List<DialogJumpResult>();
433+
var metadata = pair.Metadata;
434+
435+
try
436+
{
437+
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
438+
async () => results = await ((IAsyncDialogJump)pair.Plugin).QueryDialogJumpAsync(query, token).ConfigureAwait(false));
439+
440+
token.ThrowIfCancellationRequested();
441+
if (results == null)
442+
return null;
443+
UpdatePluginMetadata(results, metadata, query);
444+
445+
token.ThrowIfCancellationRequested();
446+
}
447+
catch (OperationCanceledException)
448+
{
449+
// null will be fine since the results will only be added into queue if the token hasn't been cancelled
450+
return null;
451+
}
452+
catch (Exception e)
453+
{
454+
API.LogException(ClassName, $"Failed to query Dialog Jump for plugin: {metadata.Name}", e);
455+
return null;
456+
}
457+
return results;
458+
}
459+
404460
public static void UpdatePluginMetadata(IReadOnlyList<Result> results, PluginMetadata metadata, Query query)
405461
{
406462
foreach (var r in results)
@@ -481,6 +537,16 @@ public static bool IsHomePlugin(string id)
481537
return _homePlugins.Where(p => !PluginModified(p.Metadata.ID)).Any(p => p.Metadata.ID == id);
482538
}
483539

540+
public static IList<DialogJumpExplorerPair> GetDialogJumpExplorers()
541+
{
542+
return _dialogJumpExplorerPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
543+
}
544+
545+
public static IList<DialogJumpDialogPair> GetDialogJumpDialogs()
546+
{
547+
return _dialogJumpDialogPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
548+
}
549+
484550
public static IDictionary<PluginPair, List<BasePluginHotkey>> GetPluginHotkeyInfo()
485551
{
486552
return _pluginHotkeyInfo.Where(p => !PluginModified(p.Key.Metadata.ID))
@@ -862,7 +928,7 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
862928
catch (Exception e)
863929
{
864930
API.LogException(ClassName, $"Failed to delete plugin settings folder for {plugin.Name}", e);
865-
API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"),
931+
API.ShowMsgError(API.GetTranslation("failedToRemovePluginSettingsTitle"),
866932
string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name));
867933
}
868934
}
@@ -878,7 +944,7 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
878944
catch (Exception e)
879945
{
880946
API.LogException(ClassName, $"Failed to delete plugin cache folder for {plugin.Name}", e);
881-
API.ShowMsg(API.GetTranslation("failedToRemovePluginCacheTitle"),
947+
API.ShowMsgError(API.GetTranslation("failedToRemovePluginCacheTitle"),
882948
string.Format(API.GetTranslation("failedToRemovePluginCacheMessage"), plugin.Name));
883949
}
884950
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)