From 10d3f4a3377bdb8d3a72f5a1a53cedbd949ec3c4 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 25 Feb 2025 12:41:13 +0800 Subject: [PATCH 1/5] Make PluginManager.API private --- Flow.Launcher.Core/Plugin/PluginManager.cs | 26 +++++++++---------- Flow.Launcher/MainWindow.xaml.cs | 2 +- .../ViewModels/SettingsPaneAboutViewModel.cs | 5 ++-- .../Views/SettingsPanePluginStore.xaml.cs | 3 +-- Flow.Launcher/ViewModel/MainViewModel.cs | 2 +- Flow.Launcher/ViewModel/PluginViewModel.cs | 8 +++--- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 6e7b5ec6002..4b31904597c 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -29,7 +29,7 @@ public static class PluginManager public static readonly HashSet GlobalPlugins = new(); public static readonly Dictionary NonGlobalPlugins = new(); - public static IPublicAPI API { get; private set; } = Ioc.Default.GetRequiredService(); + private static readonly IPublicAPI _api = Ioc.Default.GetRequiredService(); private static PluginsSettings Settings; private static List _metadatas; @@ -63,7 +63,7 @@ public static void Save() savable?.Save(); } - API.SavePluginSettings(); + _api.SavePluginSettings(); } public static async ValueTask DisposePluginsAsync() @@ -168,7 +168,7 @@ public static async Task InitializePluginsAsync() try { var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>", - () => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, API))); + () => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, _api))); pair.Metadata.InitTime += milliseconds; Log.Info( @@ -209,10 +209,10 @@ public static async Task InitializePluginsAsync() if (failedPlugins.Any()) { var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name)); - API.ShowMsg( - API.GetTranslation("failedToInitializePluginsTitle"), + _api.ShowMsg( + _api.GetTranslation("failedToInitializePluginsTitle"), string.Format( - API.GetTranslation("failedToInitializePluginsMessage"), + _api.GetTranslation("failedToInitializePluginsMessage"), failed ), "", @@ -519,7 +519,7 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c var newPluginPath = Path.Combine(installDirectory, folderName); - FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => API.ShowMsgBox(s)); + FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => _api.ShowMsgBox(s)); try { @@ -554,8 +554,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro // if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin // so we need to remove it from the api instance - var method = API.GetType().GetMethod("RemovePluginSettings"); - var pluginJsonStorage = method?.Invoke(API, new object[] { assemblyName }); + var method = _api.GetType().GetMethod("RemovePluginSettings"); + var pluginJsonStorage = method?.Invoke(_api, new object[] { assemblyName }); // if there exists a json storage for current plugin, we need to delete the directory path if (pluginJsonStorage != null) @@ -568,8 +568,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro catch (Exception e) { Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e); - API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"), - string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name)); + _api.ShowMsg(_api.GetTranslation("failedToRemovePluginSettingsTitle"), + string.Format(_api.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name)); } } } @@ -585,8 +585,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro catch (Exception e) { Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e); - API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"), - string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name)); + _api.ShowMsg(_api.GetTranslation("failedToRemovePluginSettingsTitle"), + string.Format(_api.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name)); } } } diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 41dc68fd924..3f1bae090a3 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -438,7 +438,7 @@ private void CheckFirstLaunch() if (_settings.FirstLaunch) { _settings.FirstLaunch = false; - PluginManager.API.SaveAppAllSettings(); + App.API.SaveAppAllSettings(); OpenWelcomeWindow(); } } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index cb434f399f0..ade65028472 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -6,7 +6,6 @@ using System.Windows; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; -using Flow.Launcher.Core.Plugin; using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; @@ -77,7 +76,7 @@ private void AskClearLogFolderConfirmation() [RelayCommand] private void OpenSettingsFolder() { - PluginManager.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Settings)); + App.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Settings)); } [RelayCommand] @@ -85,7 +84,7 @@ private void OpenParentOfSettingsFolder(object parameter) { string settingsFolderPath = Path.Combine(DataLocation.DataDirectory(), Constant.Settings); string parentFolderPath = Path.GetDirectoryName(settingsFolderPath); - PluginManager.API.OpenDirectory(parentFolderPath); + App.API.OpenDirectory(parentFolderPath); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs index dfb4a7eaf6c..db476331908 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs @@ -3,7 +3,6 @@ using System.Windows.Data; using System.Windows.Input; using System.Windows.Navigation; -using Flow.Launcher.Core.Plugin; using Flow.Launcher.SettingPages.ViewModels; using Flow.Launcher.ViewModel; @@ -49,7 +48,7 @@ private void SettingsPanePlugins_OnKeyDown(object sender, KeyEventArgs e) private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) { - PluginManager.API.OpenUrl(e.Uri.AbsoluteUri); + App.API.OpenUrl(e.Uri.AbsoluteUri); e.Handled = true; } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 650a276109d..6b0144a0384 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -442,7 +442,7 @@ private void OpenSetting() [RelayCommand] private void SelectHelp() { - PluginManager.API.OpenUrl("https://www.flowlauncher.com/docs/#/usage-tips"); + App.API.OpenUrl("https://www.flowlauncher.com/docs/#/usage-tips"); } [RelayCommand] diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs index bae9292bff7..46f8e00a222 100644 --- a/Flow.Launcher/ViewModel/PluginViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginViewModel.cs @@ -134,20 +134,20 @@ private void OpenPluginDirectory() { var directory = PluginPair.Metadata.PluginDirectory; if (!string.IsNullOrEmpty(directory)) - PluginManager.API.OpenDirectory(directory); + App.API.OpenDirectory(directory); } [RelayCommand] private void OpenSourceCodeLink() { - PluginManager.API.OpenUrl(PluginPair.Metadata.Website); + App.API.OpenUrl(PluginPair.Metadata.Website); } [RelayCommand] private void OpenDeletePluginWindow() { - PluginManager.API.ChangeQuery($"{PluginManagerActionKeyword} uninstall {PluginPair.Metadata.Name}".Trim(), true); - PluginManager.API.ShowMainWindow(); + App.API.ChangeQuery($"{PluginManagerActionKeyword} uninstall {PluginPair.Metadata.Name}".Trim(), true); + App.API.ShowMainWindow(); } public static bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword); From bbc7b53321d3fa29f25b32354d7eaaf0b5b2b61b Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 25 Feb 2025 12:45:45 +0800 Subject: [PATCH 2/5] Remove ThemeManager.Instance --- Flow.Launcher.Core/Resource/ThemeManager.cs | 12 -------- Flow.Launcher/App.xaml.cs | 3 +- .../ViewModels/SettingsPaneThemeViewModel.cs | 28 +++++++++---------- 3 files changed, 15 insertions(+), 28 deletions(-) delete mode 100644 Flow.Launcher.Core/Resource/ThemeManager.cs diff --git a/Flow.Launcher.Core/Resource/ThemeManager.cs b/Flow.Launcher.Core/Resource/ThemeManager.cs deleted file mode 100644 index 3cbe8319ad3..00000000000 --- a/Flow.Launcher.Core/Resource/ThemeManager.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using CommunityToolkit.Mvvm.DependencyInjection; - -namespace Flow.Launcher.Core.Resource -{ - [Obsolete("ThemeManager.Instance is obsolete. Use Ioc.Default.GetRequiredService() instead.")] - public class ThemeManager - { - public static Theme Instance - => Ioc.Default.GetRequiredService(); - } -} diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 952ca70c458..a788a7bfd9e 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -112,8 +112,7 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => HotKeyMapper.Initialize(); // main windows needs initialized before theme change because of blur settings - // TODO: Clean ThemeManager.Instance in future - ThemeManager.Instance.ChangeTheme(_settings.Theme); + Ioc.Default.GetRequiredService().ChangeTheme(_settings.Theme); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 980b2a811a4..7e19868e671 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -7,6 +7,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure; @@ -14,8 +15,6 @@ using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; using ModernWpf; -using Flow.Launcher.Core; -using ThemeManager = Flow.Launcher.Core.Resource.ThemeManager; using ThemeManagerForColorSchemeSwitch = ModernWpf.ThemeManager; namespace Flow.Launcher.SettingPages.ViewModels; @@ -24,6 +23,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel { private const string DefaultFont = "Segoe UI"; public Settings Settings { get; } + private readonly Theme _theme = Ioc.Default.GetRequiredService(); public static string LinkHowToCreateTheme => @"https://flowlauncher.com/docs/#/how-to-create-a-theme"; public static string LinkThemeGallery => "https://github.com/Flow-Launcher/Flow.Launcher/discussions/1438"; @@ -35,9 +35,9 @@ public Theme.ThemeData SelectedTheme set { _selectedTheme = value; - ThemeManager.Instance.ChangeTheme(value.FileNameWithoutExtension); + _theme.ChangeTheme(value.FileNameWithoutExtension); - if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) + if (_theme.BlurEnabled && Settings.UseDropShadowEffect) DropShadowEffect = false; } } @@ -47,7 +47,7 @@ public bool DropShadowEffect get => Settings.UseDropShadowEffect; set { - if (ThemeManager.Instance.BlurEnabled && value) + if (_theme.BlurEnabled && value) { App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("shadowEffectNotAllowed")); return; @@ -55,11 +55,11 @@ public bool DropShadowEffect if (value) { - ThemeManager.Instance.AddDropShadowEffectToCurrentTheme(); + _theme.AddDropShadowEffectToCurrentTheme(); } else { - ThemeManager.Instance.RemoveDropShadowEffectFromCurrentTheme(); + _theme.RemoveDropShadowEffectFromCurrentTheme(); } Settings.UseDropShadowEffect = value; @@ -97,7 +97,7 @@ public double ResultSubItemFontSize } private List _themes; - public List Themes => _themes ??= ThemeManager.Instance.LoadAvailableThemes(); + public List Themes => _themes ??= _theme.LoadAvailableThemes(); public class ColorSchemeData : DropdownDataGeneric { } @@ -300,7 +300,7 @@ public FontFamily SelectedQueryBoxFont set { Settings.QueryBoxFont = value.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } @@ -322,7 +322,7 @@ public FamilyTypeface SelectedQueryBoxFontFaces Settings.QueryBoxFontStretch = value.Stretch.ToString(); Settings.QueryBoxFontWeight = value.Weight.ToString(); Settings.QueryBoxFontStyle = value.Style.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } @@ -344,7 +344,7 @@ public FontFamily SelectedResultFont set { Settings.ResultFont = value.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } @@ -366,7 +366,7 @@ public FamilyTypeface SelectedResultFontFaces Settings.ResultFontStretch = value.Stretch.ToString(); Settings.ResultFontWeight = value.Weight.ToString(); Settings.ResultFontStyle = value.Style.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } @@ -390,7 +390,7 @@ public FontFamily SelectedResultSubFont set { Settings.ResultSubFont = value.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } @@ -411,7 +411,7 @@ public FamilyTypeface SelectedResultSubFontFaces Settings.ResultSubFontStretch = value.Stretch.ToString(); Settings.ResultSubFontWeight = value.Weight.ToString(); Settings.ResultSubFontStyle = value.Style.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } From 8eb3b84dd088e7b09ddaf8f6494437fa4cda1615 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 25 Feb 2025 13:22:27 +0800 Subject: [PATCH 3/5] Remove InternationalizationManager.Instance --- .../Environments/AbstractPluginEnvironment.cs | 7 ++--- Flow.Launcher.Core/Plugin/PluginManager.cs | 5 ++-- .../Resource/InternationalizationManager.cs | 12 -------- .../Resource/LocalizedDescriptionAttribute.cs | 7 +++-- Flow.Launcher.Core/Resource/Theme.cs | 5 ++-- .../Resource/TranslationConverter.cs | 10 +++++-- Flow.Launcher.Core/Updater.cs | 4 +-- Flow.Launcher/ActionKeywords.xaml.cs | 5 +--- Flow.Launcher/App.xaml.cs | 6 ++-- Flow.Launcher/Converters/TextConverter.cs | 3 +- .../CustomQueryHotkeySetting.xaml.cs | 7 ++--- Flow.Launcher/CustomShortcutSetting.xaml.cs | 15 ++++------ Flow.Launcher/Helper/HotKeyMapper.cs | 13 ++++----- Flow.Launcher/HotkeyControl.xaml.cs | 3 +- Flow.Launcher/HotkeyControlDialog.xaml.cs | 13 ++++----- Flow.Launcher/MainWindow.xaml.cs | 29 +++++++++---------- Flow.Launcher/PriorityChangeWindow.xaml.cs | 12 +++----- Flow.Launcher/PublicAPIInstance.cs | 10 ++++--- .../Resources/Pages/WelcomePage1.xaml.cs | 11 +++---- .../ViewModels/DropdownDataGeneric.cs | 5 ++-- .../ViewModels/SettingsPaneAboutViewModel.cs | 11 ++++--- .../SettingsPaneGeneralViewModel.cs | 17 ++++++----- .../ViewModels/SettingsPaneHotkeyViewModel.cs | 17 +++++------ .../ViewModels/SettingsPaneProxyViewModel.cs | 3 +- .../ViewModels/SettingsPaneThemeViewModel.cs | 18 ++++++------ Flow.Launcher/ViewModel/MainViewModel.cs | 28 ++++++++---------- Flow.Launcher/ViewModel/PluginViewModel.cs | 5 ++-- .../Search/ResultManager.cs | 7 ++--- 28 files changed, 126 insertions(+), 162 deletions(-) delete mode 100644 Flow.Launcher.Core/Resource/InternationalizationManager.cs diff --git a/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs b/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs index 451df6147fa..917bb7ad6cd 100644 --- a/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs +++ b/Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Windows; using System.Windows.Forms; -using Flow.Launcher.Core.Resource; using CommunityToolkit.Mvvm.DependencyInjection; namespace Flow.Launcher.Core.ExternalPlugins.Environments @@ -55,14 +54,14 @@ internal IEnumerable Setup() } var noRuntimeMessage = string.Format( - InternationalizationManager.Instance.GetTranslation("runtimePluginInstalledChooseRuntimePrompt"), + API.GetTranslation("runtimePluginInstalledChooseRuntimePrompt"), Language, EnvName, Environment.NewLine ); if (API.ShowMsgBox(noRuntimeMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No) { - var msg = string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName); + var msg = string.Format(API.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName); string selectedFile; selectedFile = GetFileFromDialog(msg, FileDialogFilter); @@ -85,7 +84,7 @@ internal IEnumerable Setup() } else { - API.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language)); + API.ShowMsgBox(string.Format(API.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language)); Log.Error("PluginsLoader", $"Not able to successfully set {EnvName} path, setting's plugin executable path variable is still an empty string.", $"{Language}Environment"); diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 4b31904597c..03600d2b4a3 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -203,8 +203,9 @@ public static async Task InitializePluginsAsync() } } - InternationalizationManager.Instance.AddPluginLanguageDirectories(GetPluginsForInterface()); - InternationalizationManager.Instance.ChangeLanguage(Ioc.Default.GetRequiredService().Language); + var translater = Ioc.Default.GetRequiredService(); + translater.AddPluginLanguageDirectories(GetPluginsForInterface()); + translater.ChangeLanguage(Ioc.Default.GetRequiredService().Language); if (failedPlugins.Any()) { diff --git a/Flow.Launcher.Core/Resource/InternationalizationManager.cs b/Flow.Launcher.Core/Resource/InternationalizationManager.cs deleted file mode 100644 index 5d718466c4b..00000000000 --- a/Flow.Launcher.Core/Resource/InternationalizationManager.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using CommunityToolkit.Mvvm.DependencyInjection; - -namespace Flow.Launcher.Core.Resource -{ - [Obsolete("InternationalizationManager.Instance is obsolete. Use Ioc.Default.GetRequiredService() instead.")] - public static class InternationalizationManager - { - public static Internationalization Instance - => Ioc.Default.GetRequiredService(); - } -} diff --git a/Flow.Launcher.Core/Resource/LocalizedDescriptionAttribute.cs b/Flow.Launcher.Core/Resource/LocalizedDescriptionAttribute.cs index 52a23233441..cbabe3d454c 100644 --- a/Flow.Launcher.Core/Resource/LocalizedDescriptionAttribute.cs +++ b/Flow.Launcher.Core/Resource/LocalizedDescriptionAttribute.cs @@ -1,15 +1,16 @@ using System.ComponentModel; +using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Plugin; namespace Flow.Launcher.Core.Resource { public class LocalizedDescriptionAttribute : DescriptionAttribute { - private readonly Internationalization _translator; + private static readonly IPublicAPI _api = Ioc.Default.GetRequiredService(); private readonly string _resourceKey; public LocalizedDescriptionAttribute(string resourceKey) { - _translator = InternationalizationManager.Instance; _resourceKey = resourceKey; } @@ -17,7 +18,7 @@ public override string Description { get { - string description = _translator.GetTranslation(_resourceKey); + string description = _api.GetTranslation(_resourceKey); return string.IsNullOrWhiteSpace(description) ? string.Format("[[{0}]]", _resourceKey) : description; } diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 4deea1f6648..35edeb3c5fe 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -12,7 +12,6 @@ using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; -using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Plugin; namespace Flow.Launcher.Core.Resource @@ -115,7 +114,7 @@ public bool ChangeTheme(string theme) Log.Error($"|Theme.ChangeTheme|Theme <{theme}> path can't be found"); if (theme != defaultTheme) { - _api.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_path_not_exists"), theme)); + _api.ShowMsgBox(string.Format(_api.GetTranslation("theme_load_failure_path_not_exists"), theme)); ChangeTheme(defaultTheme); } return false; @@ -125,7 +124,7 @@ public bool ChangeTheme(string theme) Log.Error($"|Theme.ChangeTheme|Theme <{theme}> fail to parse"); if (theme != defaultTheme) { - _api.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_parse_error"), theme)); + _api.ShowMsgBox(string.Format(_api.GetTranslation("theme_load_failure_parse_error"), theme)); ChangeTheme(defaultTheme); } return false; diff --git a/Flow.Launcher.Core/Resource/TranslationConverter.cs b/Flow.Launcher.Core/Resource/TranslationConverter.cs index ebab99e5b81..446f27b99d0 100644 --- a/Flow.Launcher.Core/Resource/TranslationConverter.cs +++ b/Flow.Launcher.Core/Resource/TranslationConverter.cs @@ -1,19 +1,23 @@ using System; using System.Globalization; using System.Windows.Data; +using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Plugin; namespace Flow.Launcher.Core.Resource { public class TranslationConverter : IValueConverter { + private static readonly IPublicAPI _api = Ioc.Default.GetRequiredService(); + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var key = value.ToString(); - if (String.IsNullOrEmpty(key)) + if (string.IsNullOrEmpty(key)) return key; - return InternationalizationManager.Instance.GetTranslation(key); + return _api.GetTranslation(key); } - public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException(); + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException(); } } diff --git a/Flow.Launcher.Core/Updater.cs b/Flow.Launcher.Core/Updater.cs index 9a77ece3253..84e46be8d51 100644 --- a/Flow.Launcher.Core/Updater.cs +++ b/Flow.Launcher.Core/Updater.cs @@ -8,7 +8,6 @@ using System.Windows; using JetBrains.Annotations; using Squirrel; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Http; @@ -146,8 +145,7 @@ private async Task GitHubUpdateManagerAsync(string repository) public string NewVersionTips(string version) { - var translator = InternationalizationManager.Instance; - var tips = string.Format(translator.GetTranslation("newVersionTips"), version); + var tips = string.Format(_api.GetTranslation("newVersionTips"), version); return tips; } diff --git a/Flow.Launcher/ActionKeywords.xaml.cs b/Flow.Launcher/ActionKeywords.xaml.cs index c3966e61850..9839b8c7e5c 100644 --- a/Flow.Launcher/ActionKeywords.xaml.cs +++ b/Flow.Launcher/ActionKeywords.xaml.cs @@ -1,15 +1,12 @@ using System.Windows; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; -using Flow.Launcher.Core; namespace Flow.Launcher { public partial class ActionKeywords { private readonly PluginPair plugin; - private readonly Internationalization translater = InternationalizationManager.Instance; private readonly PluginViewModel pluginViewModel; public ActionKeywords(PluginViewModel pluginViewModel) @@ -43,7 +40,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _) } else { - string msg = translater.GetTranslation("newActionKeywordsHasBeenAssigned"); + string msg = App.API.GetTranslation("newActionKeywordsHasBeenAssigned"); App.API.ShowMsgBox(msg); } } diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index a788a7bfd9e..c139325ba8f 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -91,8 +91,7 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings); - // TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future - InternationalizationManager.Instance.ChangeLanguage(_settings.Language); + Ioc.Default.GetRequiredService().ChangeLanguage(_settings.Language); PluginManager.LoadPlugins(_settings.PluginSettings); @@ -142,8 +141,7 @@ private void AutoStartup() // but if it fails (permissions, etc) then don't keep retrying // this also gives the user a visual indication in the Settings widget _settings.StartFlowLauncherOnSystemStartup = false; - Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"), - e.Message); + Notification.Show(API.GetTranslation("setAutoStartFailed"), e.Message); } } } diff --git a/Flow.Launcher/Converters/TextConverter.cs b/Flow.Launcher/Converters/TextConverter.cs index 5f0e1ea82c2..2c4dad4a956 100644 --- a/Flow.Launcher/Converters/TextConverter.cs +++ b/Flow.Launcher/Converters/TextConverter.cs @@ -1,7 +1,6 @@ using System; using System.Globalization; using System.Windows.Data; -using Flow.Launcher.Core.Resource; using Flow.Launcher.ViewModel; namespace Flow.Launcher.Converters; @@ -23,7 +22,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn if (translationKey is null) return id; - return InternationalizationManager.Instance.GetTranslation(translationKey); + return App.API.GetTranslation(translationKey); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException(); diff --git a/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs b/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs index 53fa173a511..ef9f508f474 100644 --- a/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs +++ b/Flow.Launcher/CustomQueryHotkeySetting.xaml.cs @@ -1,5 +1,4 @@ -using Flow.Launcher.Core.Resource; -using Flow.Launcher.Helper; +using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.UserSettings; using System.Collections.ObjectModel; using System.Linq; @@ -60,7 +59,7 @@ public void UpdateItem(CustomPluginHotkey item) o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey); if (updateCustomHotkey == null) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey")); + App.API.ShowMsgBox(App.API.GetTranslation("invalidPluginHotkey")); Close(); return; } @@ -68,7 +67,7 @@ public void UpdateItem(CustomPluginHotkey item) tbAction.Text = updateCustomHotkey.ActionKeyword; HotkeyControl.SetHotkey(updateCustomHotkey.Hotkey, false); update = true; - lblAdd.Text = InternationalizationManager.Instance.GetTranslation("update"); + lblAdd.Text = App.API.GetTranslation("update"); } private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e) diff --git a/Flow.Launcher/CustomShortcutSetting.xaml.cs b/Flow.Launcher/CustomShortcutSetting.xaml.cs index 416f8e04951..e180f657024 100644 --- a/Flow.Launcher/CustomShortcutSetting.xaml.cs +++ b/Flow.Launcher/CustomShortcutSetting.xaml.cs @@ -1,17 +1,14 @@ -using Flow.Launcher.Core.Resource; -using System; -using System.Windows; +using System.Windows; using System.Windows.Input; using Flow.Launcher.SettingPages.ViewModels; -using Flow.Launcher.Core; namespace Flow.Launcher { public partial class CustomShortcutSetting : Window { private readonly SettingsPaneHotkeyViewModel _hotkeyVm; - public string Key { get; set; } = String.Empty; - public string Value { get; set; } = String.Empty; + public string Key { get; set; } = string.Empty; + public string Value { get; set; } = string.Empty; private string originalKey { get; } = null; private string originalValue { get; } = null; private bool update { get; } = false; @@ -41,15 +38,15 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e) private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { - if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value)) + if (string.IsNullOrEmpty(Key) || string.IsNullOrEmpty(Value)) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("emptyShortcut")); + App.API.ShowMsgBox(App.API.GetTranslation("emptyShortcut")); return; } // Check if key is modified or adding a new one if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key)) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("duplicateShortcut")); + App.API.ShowMsgBox(App.API.GetTranslation("duplicateShortcut")); return; } DialogResult = !update || originalKey != Key || originalValue != Value; diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index 7b2fdfcf499..de5f5295b18 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -3,7 +3,6 @@ using System; using NHotkey; using NHotkey.Wpf; -using Flow.Launcher.Core.Resource; using Flow.Launcher.ViewModel; using ChefKeys; using Flow.Launcher.Infrastructure.Logger; @@ -56,8 +55,8 @@ private static void SetWithChefKeys(string hotkeyStr) string.Format("|HotkeyMapper.SetWithChefKeys|Error registering hotkey: {0} \nStackTrace:{1}", e.Message, e.StackTrace)); - string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr); - string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle"); + string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr); + string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle"); MessageBoxEx.Show(errorMsg, errorMsgTitle); } } @@ -82,8 +81,8 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler e.Message, e.StackTrace, hotkeyStr)); - string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr); - string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle"); + string errorMsg = string.Format(App.API.GetTranslation("registerHotkeyFailed"), hotkeyStr); + string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle"); App.API.ShowMsgBox(errorMsg, errorMsgTitle); } } @@ -107,8 +106,8 @@ internal static void RemoveHotkey(string hotkeyStr) string.Format("|HotkeyMapper.RemoveHotkey|Error removing hotkey: {0} \nStackTrace:{1}", e.Message, e.StackTrace)); - string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("unregisterHotkeyFailed"), hotkeyStr); - string errorMsgTitle = InternationalizationManager.Instance.GetTranslation("MessageBoxTitle"); + string errorMsg = string.Format(App.API.GetTranslation("unregisterHotkeyFailed"), hotkeyStr); + string errorMsgTitle = App.API.GetTranslation("MessageBoxTitle"); MessageBoxEx.Show(errorMsg, errorMsgTitle); } } diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index e1dfc1108ef..80fd5dc59f5 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Input; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.Hotkey; @@ -114,7 +113,7 @@ public HotkeyControl() private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) => hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey); - public string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none"); + public string EmptyHotkey => App.API.GetTranslation("none"); public ObservableCollection KeysToDisplay { get; set; } = new(); diff --git a/Flow.Launcher/HotkeyControlDialog.xaml.cs b/Flow.Launcher/HotkeyControlDialog.xaml.cs index a4d21a7827b..b7b545b5aa8 100644 --- a/Flow.Launcher/HotkeyControlDialog.xaml.cs +++ b/Flow.Launcher/HotkeyControlDialog.xaml.cs @@ -4,7 +4,6 @@ using System.Windows; using System.Windows.Input; using ChefKeys; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Plugin; @@ -32,7 +31,7 @@ public enum EResultType public EResultType ResultType { get; private set; } = EResultType.Cancel; public string ResultValue { get; private set; } = string.Empty; - public static string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none"); + public static string EmptyHotkey => App.API.GetTranslation("none"); private static bool isOpenFlowHotkey; @@ -40,7 +39,7 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings { WindowTitle = windowTitle switch { - "" or null => InternationalizationManager.Instance.GetTranslation("hotkeyRegTitle"), + "" or null => App.API.GetTranslation("hotkeyRegTitle"), _ => windowTitle }; DefaultHotkey = defaultHotkey; @@ -140,14 +139,14 @@ private void SetKeysToDisplay(HotkeyModel? hotkey) if (_hotkeySettings.RegisteredHotkeys.FirstOrDefault(v => v.Hotkey == hotkey) is { } registeredHotkeyData) { var description = string.Format( - InternationalizationManager.Instance.GetTranslation(registeredHotkeyData.DescriptionResourceKey), + App.API.GetTranslation(registeredHotkeyData.DescriptionResourceKey), registeredHotkeyData.DescriptionFormatVariables ); Alert.Visibility = Visibility.Visible; if (registeredHotkeyData.RemoveHotkey is not null) { tbMsg.Text = string.Format( - InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableEditable"), + App.API.GetTranslation("hotkeyUnavailableEditable"), description ); SaveBtn.IsEnabled = false; @@ -159,7 +158,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey) else { tbMsg.Text = string.Format( - InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableUneditable"), + App.API.GetTranslation("hotkeyUnavailableUneditable"), description ); SaveBtn.IsEnabled = false; @@ -175,7 +174,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey) if (!CheckHotkeyAvailability(hotkey.Value, true)) { - tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable"); + tbMsg.Text = App.API.GetTranslation("hotkeyUnavailable"); Alert.Visibility = Visibility.Visible; SaveBtn.IsEnabled = false; SaveBtn.Visibility = Visibility.Visible; diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 3f1bae090a3..a117862162a 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -7,7 +7,6 @@ using System.Windows.Controls; using System.Windows.Forms; using Flow.Launcher.Core.Plugin; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.ViewModel; @@ -71,8 +70,6 @@ public MainWindow(Settings settings, MainViewModel mainVM) }; } - DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 500), IsEnabled = false }; - public MainWindow() { InitializeComponent(); @@ -349,19 +346,19 @@ void InitializePositionInner() private void UpdateNotifyIconText() { var menu = contextMenu; - ((MenuItem)menu.Items[0]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + + ((MenuItem)menu.Items[0]).Header = App.API.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")"; - ((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("GameMode"); - ((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("PositionReset"); - ((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"); - ((MenuItem)menu.Items[4]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"); + ((MenuItem)menu.Items[1]).Header = App.API.GetTranslation("GameMode"); + ((MenuItem)menu.Items[2]).Header = App.API.GetTranslation("PositionReset"); + ((MenuItem)menu.Items[3]).Header = App.API.GetTranslation("iconTraySettings"); + ((MenuItem)menu.Items[4]).Header = App.API.GetTranslation("iconTrayExit"); } private void InitializeNotifyIcon() { _notifyIcon = new NotifyIcon { - Text = Infrastructure.Constant.FlowLauncherFullName, + Text = Constant.FlowLauncherFullName, Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app, Visible = !_settings.HideNotifyIcon }; @@ -369,31 +366,31 @@ private void InitializeNotifyIcon() var openIcon = new FontIcon { Glyph = "\ue71e" }; var open = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + + Header = App.API.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", Icon = openIcon }; var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" }; var gamemode = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon + Header = App.API.GetTranslation("GameMode"), Icon = gamemodeIcon }; var positionresetIcon = new FontIcon { Glyph = "\ue73f" }; var positionreset = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), + Header = App.API.GetTranslation("PositionReset"), Icon = positionresetIcon }; var settingsIcon = new FontIcon { Glyph = "\ue713" }; var settings = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), + Header = App.API.GetTranslation("iconTraySettings"), Icon = settingsIcon }; var exitIcon = new FontIcon { Glyph = "\ue7e8" }; var exit = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon + Header = App.API.GetTranslation("iconTrayExit"), Icon = exitIcon }; open.Click += (o, e) => _viewModel.ToggleFlowLauncher(); @@ -402,8 +399,8 @@ private void InitializeNotifyIcon() settings.Click += (o, e) => App.API.OpenSettingDialog(); exit.Click += (o, e) => Close(); - gamemode.ToolTip = InternationalizationManager.Instance.GetTranslation("GameModeToolTip"); - positionreset.ToolTip = InternationalizationManager.Instance.GetTranslation("PositionResetToolTip"); + gamemode.ToolTip = App.API.GetTranslation("GameModeToolTip"); + positionreset.ToolTip = App.API.GetTranslation("PositionResetToolTip"); contextMenu.Items.Add(open); contextMenu.Items.Add(gamemode); diff --git a/Flow.Launcher/PriorityChangeWindow.xaml.cs b/Flow.Launcher/PriorityChangeWindow.xaml.cs index fbe2a941d26..332187ae6b6 100644 --- a/Flow.Launcher/PriorityChangeWindow.xaml.cs +++ b/Flow.Launcher/PriorityChangeWindow.xaml.cs @@ -1,11 +1,9 @@ using Flow.Launcher.Core.Plugin; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; -using Flow.Launcher.Core; namespace Flow.Launcher { @@ -15,7 +13,6 @@ namespace Flow.Launcher public partial class PriorityChangeWindow : Window { private readonly PluginPair plugin; - private readonly Internationalization translater = InternationalizationManager.Instance; private readonly PluginViewModel pluginViewModel; public PriorityChangeWindow(string pluginId, PluginViewModel pluginViewModel) { @@ -24,7 +21,7 @@ public PriorityChangeWindow(string pluginId, PluginViewModel pluginViewModel) this.pluginViewModel = pluginViewModel; if (plugin == null) { - App.API.ShowMsgBox(translater.GetTranslation("cannotFindSpecifiedPlugin")); + App.API.ShowMsgBox(App.API.GetTranslation("cannotFindSpecifiedPlugin")); Close(); } } @@ -43,10 +40,9 @@ private void btnDone_OnClick(object sender, RoutedEventArgs e) } else { - string msg = translater.GetTranslation("invalidPriority"); + string msg = App.API.GetTranslation("invalidPriority"); App.API.ShowMsgBox(msg); } - } private void PriorityChangeWindow_Loaded(object sender, RoutedEventArgs e) @@ -54,10 +50,10 @@ private void PriorityChangeWindow_Loaded(object sender, RoutedEventArgs e) tbAction.Text = pluginViewModel.Priority.ToString(); tbAction.Focus(); } + private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */ { - TextBox textBox = Keyboard.FocusedElement as TextBox; - if (textBox != null) + if (Keyboard.FocusedElement is TextBox textBox) { TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next); textBox.MoveFocus(tRequest); diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 1a08150e591..4d1e3ec609c 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -34,13 +34,15 @@ namespace Flow.Launcher public class PublicAPIInstance : IPublicAPI { private readonly Settings _settings; + private readonly Internationalization _translater; private readonly MainViewModel _mainVM; #region Constructor - public PublicAPIInstance(Settings settings, MainViewModel mainVM) + public PublicAPIInstance(Settings settings, Internationalization translater, MainViewModel mainVM) { _settings = settings; + _translater = translater; _mainVM = mainVM; GlobalHotkey.hookedKeyboardCallback = KListener_hookedKeyboardCallback; WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); @@ -153,17 +155,17 @@ public void CopyToClipboard(string stringToCopy, bool directCopy = false, bool s public void StopLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Collapsed; - public string GetTranslation(string key) => InternationalizationManager.Instance.GetTranslation(key); + public string GetTranslation(string key) => _translater.GetTranslation(key); public List GetAllPlugins() => PluginManager.AllPlugins.ToList(); public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare); - public Task HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url); + public Task HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url, token); public Task HttpGetStreamAsync(string url, CancellationToken token = default) => - Http.GetStreamAsync(url); + Http.GetStreamAsync(url, token); public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, Action reportProgress = null, CancellationToken token = default) => Http.DownloadAsync(url, filePath, reportProgress, token); diff --git a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs index 98fb47288ea..17efd5ea19c 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs @@ -3,6 +3,7 @@ using System.Windows.Navigation; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Core.Resource; +using CommunityToolkit.Mvvm.DependencyInjection; namespace Flow.Launcher.Resources.Pages { @@ -16,7 +17,8 @@ protected override void OnNavigatedTo(NavigationEventArgs e) throw new ArgumentException("Unexpected Navigation Parameter for Settings"); InitializeComponent(); } - private Internationalization _translater => InternationalizationManager.Instance; + + private readonly Internationalization _translater = Ioc.Default.GetRequiredService(); public List Languages => _translater.LoadAvailableLanguages(); public Settings Settings { get; set; } @@ -29,12 +31,11 @@ public string CustomLanguage } set { - InternationalizationManager.Instance.ChangeLanguage(value); + _translater.ChangeLanguage(value); - if (InternationalizationManager.Instance.PromptShouldUsePinyin(value)) + if (_translater.PromptShouldUsePinyin(value)) Settings.ShouldUsePinyin = true; } } - } -} \ No newline at end of file +} diff --git a/Flow.Launcher/SettingPages/ViewModels/DropdownDataGeneric.cs b/Flow.Launcher/SettingPages/ViewModels/DropdownDataGeneric.cs index 15a81443645..693bef3b4fc 100644 --- a/Flow.Launcher/SettingPages/ViewModels/DropdownDataGeneric.cs +++ b/Flow.Launcher/SettingPages/ViewModels/DropdownDataGeneric.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Plugin; namespace Flow.Launcher.SettingPages.ViewModels; @@ -19,7 +18,7 @@ public class DropdownDataGeneric : BaseModel where TValue : Enum foreach (var value in enumValues) { var key = keyPrefix + value; - var display = InternationalizationManager.Instance.GetTranslation(key); + var display = App.API.GetTranslation(key); data.Add(new TR { Display = display, Value = value, LocalizationKey = key }); } @@ -30,7 +29,7 @@ public static void UpdateLabels(List options) where TR : DropdownDataGen { foreach (var item in options) { - item.Display = InternationalizationManager.Instance.GetTranslation(item.LocalizationKey); + item.Display = App.API.GetTranslation(item.LocalizationKey); } } } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index ade65028472..725f5da43cd 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -6,7 +6,6 @@ using System.Windows; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; @@ -23,7 +22,7 @@ public string LogFolderSize get { var size = GetLogFiles().Sum(file => file.Length); - return $"{InternationalizationManager.Instance.GetTranslation("clearlogfolder")} ({BytesToReadableString(size)})"; + return $"{App.API.GetTranslation("clearlogfolder")} ({BytesToReadableString(size)})"; } } @@ -41,7 +40,7 @@ public string LogFolderSize }; public string ActivatedTimes => string.Format( - InternationalizationManager.Instance.GetTranslation("about_activate_times"), + App.API.GetTranslation("about_activate_times"), _settings.ActivateTimes ); @@ -62,8 +61,8 @@ private void OpenWelcomeWindow() private void AskClearLogFolderConfirmation() { var confirmResult = App.API.ShowMsgBox( - InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"), - InternationalizationManager.Instance.GetTranslation("clearlogfolder"), + App.API.GetTranslation("clearlogfolderMessage"), + App.API.GetTranslation("clearlogfolder"), MessageBoxButton.YesNo ); @@ -95,7 +94,7 @@ private void OpenLogsFolder() } [RelayCommand] - private Task UpdateApp() => _updater.UpdateAppAsync(false); + private Task UpdateAppAsync() => _updater.UpdateAppAsync(false); private void ClearLogFolder() { diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index 4e498ba23fa..c20385408e1 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; +using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; using Flow.Launcher.Core.Configuration; @@ -48,7 +48,7 @@ public bool StartFlowLauncherOnSystemStartup } catch (Exception e) { - Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"), + Notification.Show(App.API.GetTranslation("setAutoStartFailed"), e.Message); } } @@ -117,9 +117,9 @@ public string Language get => Settings.Language; set { - InternationalizationManager.Instance.ChangeLanguage(value); + _translater.ChangeLanguage(value); - if (InternationalizationManager.Instance.PromptShouldUsePinyin(value)) + if (_translater.PromptShouldUsePinyin(value)) ShouldUsePinyin = true; UpdateEnumDropdownLocalizations(); @@ -132,10 +132,11 @@ public bool ShouldUsePinyin set => Settings.ShouldUsePinyin = value; } - public List Languages => InternationalizationManager.Instance.LoadAvailableLanguages(); + private readonly Internationalization _translater = Ioc.Default.GetRequiredService(); + public List Languages => _translater.LoadAvailableLanguages(); public string AlwaysPreviewToolTip => string.Format( - InternationalizationManager.Instance.GetTranslation("AlwaysPreviewToolTip"), + App.API.GetTranslation("AlwaysPreviewToolTip"), Settings.PreviewHotkey ); @@ -181,7 +182,7 @@ public bool AutoUpdates private void SelectPython() { var selectedFile = GetFileFromDialog( - InternationalizationManager.Instance.GetTranslation("selectPythonExecutable"), + App.API.GetTranslation("selectPythonExecutable"), "Python|pythonw.exe" ); @@ -193,7 +194,7 @@ private void SelectPython() private void SelectNode() { var selectedFile = GetFileFromDialog( - InternationalizationManager.Instance.GetTranslation("selectNodeExecutable"), + App.API.GetTranslation("selectNodeExecutable"), "node|*.exe" ); diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs index b13aaefe3e9..7a7c19dd358 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs @@ -1,7 +1,6 @@ using System.Linq; using System.Windows; using CommunityToolkit.Mvvm.Input; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Hotkey; @@ -41,15 +40,15 @@ private void CustomHotkeyDelete() var item = SelectedCustomPluginHotkey; if (item is null) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + App.API.ShowMsgBox(App.API.GetTranslation("pleaseSelectAnItem")); return; } var result = App.API.ShowMsgBox( string.Format( - InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey + App.API.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey ), - InternationalizationManager.Instance.GetTranslation("delete"), + App.API.GetTranslation("delete"), MessageBoxButton.YesNo ); @@ -66,7 +65,7 @@ private void CustomHotkeyEdit() var item = SelectedCustomPluginHotkey; if (item is null) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + App.API.ShowMsgBox(App.API.GetTranslation("pleaseSelectAnItem")); return; } @@ -87,15 +86,15 @@ private void CustomShortcutDelete() var item = SelectedCustomShortcut; if (item is null) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + App.API.ShowMsgBox(App.API.GetTranslation("pleaseSelectAnItem")); return; } var result = App.API.ShowMsgBox( string.Format( - InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"), item.Key, item.Value + App.API.GetTranslation("deleteCustomShortcutWarning"), item.Key, item.Value ), - InternationalizationManager.Instance.GetTranslation("delete"), + App.API.GetTranslation("delete"), MessageBoxButton.YesNo ); @@ -111,7 +110,7 @@ private void CustomShortcutEdit() var item = SelectedCustomShortcut; if (item is null) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + App.API.ShowMsgBox(App.API.GetTranslation("pleaseSelectAnItem")); return; } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs index e2f9e516ca4..38a6ef31eaa 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneProxyViewModel.cs @@ -1,7 +1,6 @@ using System.Net; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; @@ -22,7 +21,7 @@ public SettingsPaneProxyViewModel(Settings settings, Updater updater) private void OnTestProxyClicked() { var message = TestProxy(); - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation(message)); + App.API.ShowMsgBox(App.API.GetTranslation(message)); } private string TestProxy() diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 7e19868e671..6a44ebef24b 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -49,7 +49,7 @@ public bool DropShadowEffect { if (_theme.BlurEnabled && value) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("shadowEffectNotAllowed")); + App.API.ShowMsgBox(App.API.GetTranslation("shadowEffectNotAllowed")); return; } @@ -240,8 +240,8 @@ public ResultsViewModel PreviewResults { new Result { - Title = InternationalizationManager.Instance.GetTranslation("SampleTitleExplorer"), - SubTitle = InternationalizationManager.Instance.GetTranslation("SampleSubTitleExplorer"), + Title = App.API.GetTranslation("SampleTitleExplorer"), + SubTitle = App.API.GetTranslation("SampleSubTitleExplorer"), IcoPath = Path.Combine( Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.Explorer\Images\explorer.png" @@ -249,8 +249,8 @@ public ResultsViewModel PreviewResults }, new Result { - Title = InternationalizationManager.Instance.GetTranslation("SampleTitleWebSearch"), - SubTitle = InternationalizationManager.Instance.GetTranslation("SampleSubTitleWebSearch"), + Title = App.API.GetTranslation("SampleTitleWebSearch"), + SubTitle = App.API.GetTranslation("SampleSubTitleWebSearch"), IcoPath = Path.Combine( Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png" @@ -258,8 +258,8 @@ public ResultsViewModel PreviewResults }, new Result { - Title = InternationalizationManager.Instance.GetTranslation("SampleTitleProgram"), - SubTitle = InternationalizationManager.Instance.GetTranslation("SampleSubTitleProgram"), + Title = App.API.GetTranslation("SampleTitleProgram"), + SubTitle = App.API.GetTranslation("SampleSubTitleProgram"), IcoPath = Path.Combine( Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png" @@ -267,8 +267,8 @@ public ResultsViewModel PreviewResults }, new Result { - Title = InternationalizationManager.Instance.GetTranslation("SampleTitleProcessKiller"), - SubTitle = InternationalizationManager.Instance.GetTranslation("SampleSubTitleProcessKiller"), + Title = App.API.GetTranslation("SampleTitleProcessKiller"), + SubTitle = App.API.GetTranslation("SampleSubTitleProcessKiller"), IcoPath = Path.Combine( Constant.ProgramDirectory, @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png" diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 6b0144a0384..eebb1e47ded 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using System.Windows; using Flow.Launcher.Core.Plugin; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Hotkey; @@ -48,8 +47,6 @@ public partial class MainViewModel : BaseModel, ISavable private CancellationTokenSource _updateSource; private CancellationToken _updateToken; - private readonly Internationalization _translator = InternationalizationManager.Instance; - private ChannelWriter _resultsUpdateChannelWriter; private Task _resultsViewUpdateTask; @@ -251,8 +248,8 @@ private async Task ReloadPluginDataAsync() Hide(); await PluginManager.ReloadDataAsync().ConfigureAwait(false); - Notification.Show(InternationalizationManager.Instance.GetTranslation("success"), - InternationalizationManager.Instance.GetTranslation("completedSuccessfully")); + Notification.Show(App.API.GetTranslation("success"), + App.API.GetTranslation("completedSuccessfully")); } [RelayCommand] @@ -1045,8 +1042,8 @@ private void QueryHistory() var results = new List(); foreach (var h in _history.Items) { - var title = _translator.GetTranslation("executeQuery"); - var time = _translator.GetTranslation("lastExecuteTime"); + var title = App.API.GetTranslation("executeQuery"); + var time = App.API.GetTranslation("lastExecuteTime"); var result = new Result { Title = string.Format(title, h.Query), @@ -1285,13 +1282,13 @@ private Result ContextMenuTopMost(Result result) { menu = new Result { - Title = InternationalizationManager.Instance.GetTranslation("cancelTopMostInThisQuery"), + Title = App.API.GetTranslation("cancelTopMostInThisQuery"), IcoPath = "Images\\down.png", PluginDirectory = Constant.ProgramDirectory, Action = _ => { _topMostRecord.Remove(result); - App.API.ShowMsg(InternationalizationManager.Instance.GetTranslation("success")); + App.API.ShowMsg(App.API.GetTranslation("success")); App.API.ReQuery(); return false; } @@ -1301,14 +1298,14 @@ private Result ContextMenuTopMost(Result result) { menu = new Result { - Title = InternationalizationManager.Instance.GetTranslation("setAsTopMostInThisQuery"), + Title = App.API.GetTranslation("setAsTopMostInThisQuery"), IcoPath = "Images\\up.png", Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xeac2"), PluginDirectory = Constant.ProgramDirectory, Action = _ => { _topMostRecord.AddOrUpdate(result); - App.API.ShowMsg(InternationalizationManager.Instance.GetTranslation("success")); + App.API.ShowMsg(App.API.GetTranslation("success")); App.API.ReQuery(); return false; } @@ -1321,12 +1318,11 @@ private Result ContextMenuTopMost(Result result) private Result ContextMenuPluginInfo(string id) { var metadata = PluginManager.GetPluginForId(id).Metadata; - var translator = InternationalizationManager.Instance; - var author = translator.GetTranslation("author"); - var website = translator.GetTranslation("website"); - var version = translator.GetTranslation("version"); - var plugin = translator.GetTranslation("plugin"); + var author = App.API.GetTranslation("author"); + var website = App.API.GetTranslation("website"); + var version = App.API.GetTranslation("version"); + var plugin = App.API.GetTranslation("plugin"); var title = $"{plugin}: {metadata.Name}"; var icon = metadata.IcoPath; var subtitle = $"{author} {metadata.Author}"; diff --git a/Flow.Launcher/ViewModel/PluginViewModel.cs b/Flow.Launcher/ViewModel/PluginViewModel.cs index 46f8e00a222..992a7f1afc9 100644 --- a/Flow.Launcher/ViewModel/PluginViewModel.cs +++ b/Flow.Launcher/ViewModel/PluginViewModel.cs @@ -6,7 +6,6 @@ using Flow.Launcher.Core.Plugin; using System.Windows.Controls; using CommunityToolkit.Mvvm.Input; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Resources.Controls; namespace Flow.Launcher.ViewModel @@ -103,8 +102,8 @@ public Control SettingControl public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count == 1 ? Visibility.Visible : Visibility.Collapsed; public string InitilizaTime => PluginPair.Metadata.InitTime + "ms"; public string QueryTime => PluginPair.Metadata.AvgQueryTime + "ms"; - public string Version => InternationalizationManager.Instance.GetTranslation("plugin_query_version") + " " + PluginPair.Metadata.Version; - public string InitAndQueryTime => InternationalizationManager.Instance.GetTranslation("plugin_init_time") + " " + PluginPair.Metadata.InitTime + "ms, " + InternationalizationManager.Instance.GetTranslation("plugin_query_time") + " " + PluginPair.Metadata.AvgQueryTime + "ms"; + public string Version => App.API.GetTranslation("plugin_query_version") + " " + PluginPair.Metadata.Version; + public string InitAndQueryTime => App.API.GetTranslation("plugin_init_time") + " " + PluginPair.Metadata.InitTime + "ms, " + App.API.GetTranslation("plugin_query_time") + " " + PluginPair.Metadata.AvgQueryTime + "ms"; public string ActionKeywordsText => string.Join(Query.ActionKeywordSeparator, PluginPair.Metadata.ActionKeywords); public int Priority => PluginPair.Metadata.Priority; public Infrastructure.UserSettings.Plugin PluginSettingsObject { get; set; } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 1add8476577..6145fbf9b83 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -1,5 +1,4 @@ -using Flow.Launcher.Core.Resource; -using Flow.Launcher.Infrastructure; +using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin.SharedCommands; using System; using System.IO; @@ -164,7 +163,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string return false; }, Score = score, - TitleToolTip = InternationalizationManager.Instance.GetTranslation("plugin_explorer_plugin_ToolTipOpenDirectory"), + TitleToolTip = Context.API.GetTranslation("plugin_explorer_plugin_ToolTipOpenDirectory"), SubTitleToolTip = path, ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path, WindowsIndexed = windowsIndexed } }; @@ -319,7 +318,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score return true; }, - TitleToolTip = InternationalizationManager.Instance.GetTranslation("plugin_explorer_plugin_ToolTipOpenContainingFolder"), + TitleToolTip = Context.API.GetTranslation("plugin_explorer_plugin_ToolTipOpenContainingFolder"), SubTitleToolTip = filePath, ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath, WindowsIndexed = windowsIndexed } }; From 143497d2841b24bd5f28548eff036b4dc0cfb70b Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 25 Feb 2025 13:31:30 +0800 Subject: [PATCH 4/5] Remove Notification.Show --- Flow.Launcher/App.xaml.cs | 2 +- .../SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs | 4 +--- Flow.Launcher/ViewModel/MainViewModel.cs | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index c139325ba8f..839a224daa2 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -141,7 +141,7 @@ private void AutoStartup() // but if it fails (permissions, etc) then don't keep retrying // this also gives the user a visual indication in the Settings widget _settings.StartFlowLauncherOnSystemStartup = false; - Notification.Show(API.GetTranslation("setAutoStartFailed"), e.Message); + API.ShowMsg(API.GetTranslation("setAutoStartFailed"), e.Message); } } } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index c20385408e1..ad9845533cb 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -48,13 +48,11 @@ public bool StartFlowLauncherOnSystemStartup } catch (Exception e) { - Notification.Show(App.API.GetTranslation("setAutoStartFailed"), - e.Message); + App.API.ShowMsg(App.API.GetTranslation("setAutoStartFailed"), e.Message); } } } - public List SearchWindowScreens { get; } = DropdownDataGeneric.GetValues("SearchWindowScreen"); diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index eebb1e47ded..e9f166e9dbe 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -248,7 +248,7 @@ private async Task ReloadPluginDataAsync() Hide(); await PluginManager.ReloadDataAsync().ConfigureAwait(false); - Notification.Show(App.API.GetTranslation("success"), + App.API.ShowMsg(App.API.GetTranslation("success"), App.API.GetTranslation("completedSuccessfully")); } From 35d5bca3bea1cf886538d4c623948c7088b3e741 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 1 Mar 2025 08:54:39 +0800 Subject: [PATCH 5/5] Fix PluginManager build issue --- Flow.Launcher.Core/Plugin/PluginManager.cs | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index c079b3c81d0..66fba1cd94d 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -65,7 +65,7 @@ public static void Save() savable?.Save(); } - _api.SavePluginSettings(); + API.SavePluginSettings(); } public static async ValueTask DisposePluginsAsync() @@ -170,7 +170,7 @@ public static async Task InitializePluginsAsync() try { var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>", - () => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, _api))); + () => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, API))); pair.Metadata.InitTime += milliseconds; Log.Info( @@ -212,10 +212,10 @@ public static async Task InitializePluginsAsync() if (failedPlugins.Any()) { var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name)); - _api.ShowMsg( - _api.GetTranslation("failedToInitializePluginsTitle"), + API.ShowMsg( + API.GetTranslation("failedToInitializePluginsTitle"), string.Format( - _api.GetTranslation("failedToInitializePluginsMessage"), + API.GetTranslation("failedToInitializePluginsMessage"), failed ), "", @@ -522,7 +522,7 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c var newPluginPath = Path.Combine(installDirectory, folderName); - FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => _api.ShowMsgBox(s)); + FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => API.ShowMsgBox(s)); try { @@ -557,8 +557,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro // if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin // so we need to remove it from the api instance - var method = _api.GetType().GetMethod("RemovePluginSettings"); - var pluginJsonStorage = method?.Invoke(_api, new object[] { assemblyName }); + var method = API.GetType().GetMethod("RemovePluginSettings"); + var pluginJsonStorage = method?.Invoke(API, new object[] { assemblyName }); // if there exists a json storage for current plugin, we need to delete the directory path if (pluginJsonStorage != null) @@ -571,8 +571,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro catch (Exception e) { Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e); - _api.ShowMsg(_api.GetTranslation("failedToRemovePluginSettingsTitle"), - string.Format(_api.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name)); + API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"), + string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name)); } } } @@ -588,8 +588,8 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro catch (Exception e) { Log.Exception($"|PluginManager.UninstallPlugin|Failed to delete plugin json folder for {plugin.Name}", e); - _api.ShowMsg(_api.GetTranslation("failedToRemovePluginSettingsTitle"), - string.Format(_api.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name)); + API.ShowMsg(API.GetTranslation("failedToRemovePluginSettingsTitle"), + string.Format(API.GetTranslation("failedToRemovePluginSettingsMessage"), plugin.Name)); } } }