Skip to content

Commit 7975ab5

Browse files
authored
Merge branch 'dev' into plugin_settings_cache_path
2 parents f8d0981 + 79d54d0 commit 7975ab5

File tree

57 files changed

+777
-393
lines changed

Some content is hidden

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

57 files changed

+777
-393
lines changed

Flow.Launcher.Core/Configuration/Portable.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
using Flow.Launcher.Infrastructure.UserSettings;
1010
using Flow.Launcher.Plugin.SharedCommands;
1111
using System.Linq;
12+
using CommunityToolkit.Mvvm.DependencyInjection;
13+
using Flow.Launcher.Plugin;
1214

1315
namespace Flow.Launcher.Core.Configuration
1416
{
1517
public class Portable : IPortable
1618
{
19+
private readonly IPublicAPI API = Ioc.Default.GetRequiredService<IPublicAPI>();
20+
1721
/// <summary>
1822
/// As at Squirrel.Windows version 1.5.2, UpdateManager needs to be disposed after finish
1923
/// </summary>
@@ -40,7 +44,7 @@ public void DisablePortableMode()
4044
#endif
4145
IndicateDeletion(DataLocation.PortableDataPath);
4246

43-
MessageBoxEx.Show("Flow Launcher needs to restart to finish disabling portable mode, " +
47+
API.ShowMsgBox("Flow Launcher needs to restart to finish disabling portable mode, " +
4448
"after the restart your portable data profile will be deleted and roaming data profile kept");
4549

4650
UpdateManager.RestartApp(Constant.ApplicationFileName);
@@ -64,7 +68,7 @@ public void EnablePortableMode()
6468
#endif
6569
IndicateDeletion(DataLocation.RoamingDataPath);
6670

67-
MessageBoxEx.Show("Flow Launcher needs to restart to finish enabling portable mode, " +
71+
API.ShowMsgBox("Flow Launcher needs to restart to finish enabling portable mode, " +
6872
"after the restart your roaming data profile will be deleted and portable data profile kept");
6973

7074
UpdateManager.RestartApp(Constant.ApplicationFileName);
@@ -95,13 +99,13 @@ public void RemoveUninstallerEntry()
9599

96100
public void MoveUserDataFolder(string fromLocation, string toLocation)
97101
{
98-
FilesFolders.CopyAll(fromLocation, toLocation, MessageBoxEx.Show);
102+
FilesFolders.CopyAll(fromLocation, toLocation, (s) => API.ShowMsgBox(s));
99103
VerifyUserDataAfterMove(fromLocation, toLocation);
100104
}
101105

102106
public void VerifyUserDataAfterMove(string fromLocation, string toLocation)
103107
{
104-
FilesFolders.VerifyBothFolderFilesEqual(fromLocation, toLocation, MessageBoxEx.Show);
108+
FilesFolders.VerifyBothFolderFilesEqual(fromLocation, toLocation, (s) => API.ShowMsgBox(s));
105109
}
106110

107111
public void CreateShortcuts()
@@ -157,13 +161,13 @@ public void PreStartCleanUpAfterPortabilityUpdate()
157161
// delete it and prompt the user to pick the portable data location
158162
if (File.Exists(roamingDataDeleteFilePath))
159163
{
160-
FilesFolders.RemoveFolderIfExists(roamingDataDir, MessageBoxEx.Show);
164+
FilesFolders.RemoveFolderIfExists(roamingDataDir, (s) => API.ShowMsgBox(s));
161165

162-
if (MessageBoxEx.Show("Flow Launcher has detected you enabled portable mode, " +
166+
if (API.ShowMsgBox("Flow Launcher has detected you enabled portable mode, " +
163167
"would you like to move it to a different location?", string.Empty,
164168
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
165169
{
166-
FilesFolders.OpenPath(Constant.RootDirectory, MessageBoxEx.Show);
170+
FilesFolders.OpenPath(Constant.RootDirectory, (s) => API.ShowMsgBox(s));
167171

168172
Environment.Exit(0);
169173
}
@@ -172,9 +176,9 @@ public void PreStartCleanUpAfterPortabilityUpdate()
172176
// delete it and notify the user about it.
173177
else if (File.Exists(portableDataDeleteFilePath))
174178
{
175-
FilesFolders.RemoveFolderIfExists(portableDataDir, MessageBoxEx.Show);
179+
FilesFolders.RemoveFolderIfExists(portableDataDir, (s) => API.ShowMsgBox(s));
176180

177-
MessageBoxEx.Show("Flow Launcher has detected you disabled portable mode, " +
181+
API.ShowMsgBox("Flow Launcher has detected you disabled portable mode, " +
178182
"the relevant shortcuts and uninstaller entry have been created");
179183
}
180184
}
@@ -186,7 +190,7 @@ public bool CanUpdatePortability()
186190

187191
if (roamingLocationExists && portableLocationExists)
188192
{
189-
MessageBoxEx.Show(string.Format("Flow Launcher detected your user data exists both in {0} and " +
193+
API.ShowMsgBox(string.Format("Flow Launcher detected your user data exists both in {0} and " +
190194
"{1}. {2}{2}Please delete {1} in order to proceed. No changes have occurred.",
191195
DataLocation.PortableDataPath, DataLocation.RoamingDataPath, Environment.NewLine));
192196

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
using System.Windows;
1010
using System.Windows.Forms;
1111
using Flow.Launcher.Core.Resource;
12+
using CommunityToolkit.Mvvm.DependencyInjection;
1213

1314
namespace Flow.Launcher.Core.ExternalPlugins.Environments
1415
{
1516
public abstract class AbstractPluginEnvironment
1617
{
18+
protected readonly IPublicAPI API = Ioc.Default.GetRequiredService<IPublicAPI>();
19+
1720
internal abstract string Language { get; }
1821

1922
internal abstract string EnvName { get; }
@@ -26,7 +29,7 @@ public abstract class AbstractPluginEnvironment
2629

2730
internal virtual string FileDialogFilter => string.Empty;
2831

29-
internal abstract string PluginsSettingsFilePath { get; set; }
32+
internal abstract string PluginsSettingsFilePath { get; set; }
3033

3134
internal List<PluginMetadata> PluginMetadataList;
3235

@@ -58,7 +61,7 @@ internal IEnumerable<PluginPair> Setup()
5861
EnvName,
5962
Environment.NewLine
6063
);
61-
if (MessageBoxEx.Show(noRuntimeMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
64+
if (API.ShowMsgBox(noRuntimeMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
6265
{
6366
var msg = string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName);
6467
string selectedFile;
@@ -83,7 +86,7 @@ internal IEnumerable<PluginPair> Setup()
8386
}
8487
else
8588
{
86-
MessageBoxEx.Show(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
89+
API.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
8790
Log.Error("PluginsLoader",
8891
$"Not able to successfully set {EnvName} path, setting's plugin executable path variable is still an empty string.",
8992
$"{Language}Environment");
@@ -99,7 +102,7 @@ private void EnsureLatestInstalled(string expectedPath, string currentPath, stri
99102
if (expectedPath == currentPath)
100103
return;
101104

102-
FilesFolders.RemoveFolderIfExists(installedDirPath, MessageBoxEx.Show);
105+
FilesFolders.RemoveFolderIfExists(installedDirPath, (s) => API.ShowMsgBox(s));
103106

104107
InstallEnvironment();
105108

Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal PythonEnvironment(List<PluginMetadata> pluginMetadataList, PluginsSetti
2828

2929
internal override void InstallEnvironment()
3030
{
31-
FilesFolders.RemoveFolderIfExists(InstallPath, MessageBoxEx.Show);
31+
FilesFolders.RemoveFolderIfExists(InstallPath, (s) => API.ShowMsgBox(s));
3232

3333
// Python 3.11.4 is no longer Windows 7 compatible. If user is on Win 7 and
3434
// uses Python plugin they need to custom install and use v3.8.9

Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal TypeScriptEnvironment(List<PluginMetadata> pluginMetadataList, PluginsS
2525

2626
internal override void InstallEnvironment()
2727
{
28-
FilesFolders.RemoveFolderIfExists(InstallPath, MessageBoxEx.Show);
28+
FilesFolders.RemoveFolderIfExists(InstallPath, (s) => API.ShowMsgBox(s));
2929

3030
DroplexPackage.Drop(App.nodejs_16_18_0, InstallPath).Wait();
3131

Flow.Launcher.Core/ExternalPlugins/Environments/TypeScriptV2Environment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal TypeScriptV2Environment(List<PluginMetadata> pluginMetadataList, Plugin
2525

2626
internal override void InstallEnvironment()
2727
{
28-
FilesFolders.RemoveFolderIfExists(InstallPath, MessageBoxEx.Show);
28+
FilesFolders.RemoveFolderIfExists(InstallPath, (s) => API.ShowMsgBox(s));
2929

3030
DroplexPackage.Drop(App.nodejs_16_18_0, InstallPath).Wait();
3131

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Flow.Launcher.Plugin.SharedCommands;
1515
using System.Text.Json;
1616
using Flow.Launcher.Core.Resource;
17+
using CommunityToolkit.Mvvm.DependencyInjection;
1718

1819
namespace Flow.Launcher.Core.Plugin
1920
{
@@ -28,7 +29,9 @@ public static class PluginManager
2829
public static readonly HashSet<PluginPair> GlobalPlugins = new();
2930
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new();
3031

31-
public static IPublicAPI API { private set; get; }
32+
// We should not initialize API in static constructor because it will create another API instance
33+
private static IPublicAPI api = null;
34+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
3235

3336
private static PluginsSettings Settings;
3437
private static List<PluginMetadata> _metadatas;
@@ -186,9 +189,8 @@ private static void UpdateNotNetPluginDirectory(List<PluginMetadata> metadatas)
186189
/// Call initialize for all plugins
187190
/// </summary>
188191
/// <returns>return the list of failed to init plugins or null for none</returns>
189-
public static async Task InitializePluginsAsync(IPublicAPI api)
192+
public static async Task InitializePluginsAsync()
190193
{
191-
API = api;
192194
var failedPlugins = new ConcurrentQueue<PluginPair>();
193195

194196
var InitTasks = AllPlugins.Select(pair => Task.Run(async delegate
@@ -232,7 +234,7 @@ public static async Task InitializePluginsAsync(IPublicAPI api)
232234
}
233235

234236
InternationalizationManager.Instance.AddPluginLanguageDirectories(GetPluginsForInterface<IPluginI18n>());
235-
InternationalizationManager.Instance.ChangeLanguage(InternationalizationManager.Instance.Settings.Language);
237+
InternationalizationManager.Instance.ChangeLanguage(Ioc.Default.GetRequiredService<Settings>().Language);
236238

237239
if (failedPlugins.Any())
238240
{
@@ -545,7 +547,7 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
545547

546548
var newPluginPath = Path.Combine(installDirectory, folderName);
547549

548-
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, MessageBoxEx.Show);
550+
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => API.ShowMsgBox(s));
549551

550552
try
551553
{

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Reflection;
66
using System.Threading.Tasks;
77
using System.Windows;
8+
using CommunityToolkit.Mvvm.DependencyInjection;
89
using Flow.Launcher.Core.ExternalPlugins.Environments;
910
#pragma warning disable IDE0005
1011
using Flow.Launcher.Infrastructure.Logger;
@@ -122,7 +123,7 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
122123

123124
_ = Task.Run(() =>
124125
{
125-
MessageBoxEx.Show($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
126+
Ioc.Default.GetRequiredService<IPublicAPI>().ShowMsgBox($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
126127
$"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
127128
$"Please refer to the logs for more information", "",
128129
MessageBoxButton.OK, MessageBoxImage.Warning);

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@
1111
using Flow.Launcher.Plugin;
1212
using System.Globalization;
1313
using System.Threading.Tasks;
14+
using CommunityToolkit.Mvvm.DependencyInjection;
1415

1516
namespace Flow.Launcher.Core.Resource
1617
{
1718
public class Internationalization
1819
{
19-
public Settings Settings { get; set; }
2020
private const string Folder = "Languages";
2121
private const string DefaultLanguageCode = "en";
2222
private const string DefaultFile = "en.xaml";
2323
private const string Extension = ".xaml";
24+
private readonly Settings _settings;
2425
private readonly List<string> _languageDirectories = new List<string>();
2526
private readonly List<ResourceDictionary> _oldResources = new List<ResourceDictionary>();
2627
private readonly string SystemLanguageCode;
2728

28-
public Internationalization()
29+
public Internationalization(Settings settings)
2930
{
31+
_settings = settings;
3032
AddFlowLauncherLanguageDirectory();
3133
SystemLanguageCode = GetSystemLanguageCodeAtStartup();
3234
}
@@ -141,7 +143,7 @@ private void ChangeLanguage(Language language, bool isSystem)
141143
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
142144

143145
// Raise event after culture is set
144-
Settings.Language = isSystem ? Constant.SystemLanguageCode : language.LanguageCode;
146+
_settings.Language = isSystem ? Constant.SystemLanguageCode : language.LanguageCode;
145147
_ = Task.Run(() =>
146148
{
147149
UpdatePluginMetadataTranslations();
@@ -152,7 +154,7 @@ public bool PromptShouldUsePinyin(string languageCodeToSet)
152154
{
153155
var languageToSet = GetLanguageByLanguageCode(languageCodeToSet);
154156

155-
if (Settings.ShouldUsePinyin)
157+
if (_settings.ShouldUsePinyin)
156158
return false;
157159

158160
if (languageToSet != AvailableLanguages.Chinese && languageToSet != AvailableLanguages.Chinese_TW)
@@ -162,7 +164,7 @@ public bool PromptShouldUsePinyin(string languageCodeToSet)
162164
// "Do you want to search with pinyin?"
163165
string text = languageToSet == AvailableLanguages.Chinese ? "是否启用拼音搜索?" : "是否啓用拼音搜索?" ;
164166

165-
if (MessageBoxEx.Show(text, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
167+
if (Ioc.Default.GetRequiredService<IPublicAPI>().ShowMsgBox(text, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
166168
return false;
167169

168170
return true;
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
namespace Flow.Launcher.Core.Resource
1+
using System;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
4+
namespace Flow.Launcher.Core.Resource
25
{
6+
[Obsolete("InternationalizationManager.Instance is obsolete. Use Ioc.Default.GetRequiredService<Internationalization>() instead.")]
37
public static class InternationalizationManager
48
{
5-
private static Internationalization instance;
6-
private static object syncObject = new object();
7-
89
public static Internationalization Instance
9-
{
10-
get
11-
{
12-
if (instance == null)
13-
{
14-
lock (syncObject)
15-
{
16-
if (instance == null)
17-
{
18-
instance = new Internationalization();
19-
}
20-
}
21-
}
22-
return instance;
23-
}
24-
}
10+
=> Ioc.Default.GetRequiredService<Internationalization>();
2511
}
26-
}
12+
}

0 commit comments

Comments
 (0)