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 09711051e24..66fba1cd94d 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -28,7 +28,7 @@ public static class PluginManager public static List AllPlugins { get; private set; } public static readonly HashSet GlobalPlugins = new(); public static readonly Dictionary NonGlobalPlugins = new(); - + // We should not initialize API in static constructor because it will create another API instance private static IPublicAPI api = null; private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService(); @@ -205,8 +205,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 cda125a39cb..d53c701c41b 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -116,7 +116,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; @@ -126,7 +126,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/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.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 550b1bdaeac..9c2e14351e4 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -127,8 +127,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); @@ -148,8 +147,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); @@ -186,8 +184,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); + API.ShowMsg(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 273d18e3f5d..2dd90e19d67 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System.Collections.ObjectModel; using System.Threading.Tasks; @@ -211,7 +211,7 @@ private void RefreshHotkeyInterface(string hotkey) 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 2f8c5eb2616..e5cb9d54ae4 100644 --- a/Flow.Launcher/HotkeyControlDialog.xaml.cs +++ b/Flow.Launcher/HotkeyControlDialog.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.ObjectModel; using System.Linq; using System.Windows; @@ -34,7 +34,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; @@ -42,7 +42,7 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, string windowTit { WindowTitle = windowTitle switch { - "" or null => InternationalizationManager.Instance.GetTranslation("hotkeyRegTitle"), + "" or null => App.API.GetTranslation("hotkeyRegTitle"), _ => windowTitle }; DefaultHotkey = defaultHotkey; @@ -141,14 +141,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; @@ -160,7 +160,7 @@ private void SetKeysToDisplay(HotkeyModel? hotkey) else { tbMsg.Text = string.Format( - InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableUneditable"), + App.API.GetTranslation("hotkeyUnavailableUneditable"), description ); SaveBtn.IsEnabled = false; @@ -176,7 +176,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 1d4a2610104..096e62057d6 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; @@ -69,7 +68,7 @@ public MainWindow(Settings settings, MainViewModel mainVM) win.AddHook(WndProc); }; } - + private int _initialWidth; private int _initialHeight; @@ -311,51 +310,51 @@ 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 }; 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"), + 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"), + Header = App.API.GetTranslation("iconTrayExit"), Icon = exitIcon }; @@ -365,8 +364,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 ac22170aeeb..2d1b31c045b 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 880bfd9bcc2..68f8fdcfae2 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Windows.Navigation; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Core.Resource; @@ -17,7 +17,8 @@ protected override void OnNavigatedTo(NavigationEventArgs e) Ioc.Default.GetRequiredService().PageNum = 1; InitializeComponent(); } - private Internationalization _translater => InternationalizationManager.Instance; + + private readonly Internationalization _translater = Ioc.Default.GetRequiredService(); public List Languages => _translater.LoadAvailableLanguages(); public Settings Settings { get; set; } @@ -30,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; } } - } } 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 f82f8e34d48..8ec91c03039 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.Logger; using Flow.Launcher.Infrastructure.UserSettings; @@ -24,7 +23,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)})"; } } @@ -42,7 +41,7 @@ public string LogFolderSize }; public string ActivatedTimes => string.Format( - InternationalizationManager.Instance.GetTranslation("about_activate_times"), + App.API.GetTranslation("about_activate_times"), _settings.ActivateTimes ); @@ -88,8 +87,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 ); @@ -121,7 +120,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 de4f158ad04..d729d34471a 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; +using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; using Flow.Launcher.Core.Configuration; @@ -58,8 +59,7 @@ public bool StartFlowLauncherOnSystemStartup } catch (Exception e) { - Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"), - e.Message); + App.API.ShowMsg(App.API.GetTranslation("setAutoStartFailed"), e.Message); } } } @@ -86,7 +86,7 @@ public bool UseLogonTaskForStartup } catch (Exception e) { - Notification.Show(InternationalizationManager.Instance.GetTranslation("setAutoStartFailed"), + App.API.ShowMsg(App.API.GetTranslation("setAutoStartFailed"), e.Message); } } @@ -155,9 +155,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(); @@ -170,10 +170,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 ); @@ -219,7 +220,7 @@ public bool AutoUpdates private void SelectPython() { var selectedFile = GetFileFromDialog( - InternationalizationManager.Instance.GetTranslation("selectPythonExecutable"), + App.API.GetTranslation("selectPythonExecutable"), "Python|pythonw.exe" ); @@ -231,7 +232,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 ed933678d46..f0d6ca30854 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Windows.Media; using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure; @@ -13,7 +14,6 @@ using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; using ModernWpf; -using ThemeManager = Flow.Launcher.Core.Resource.ThemeManager; using ThemeManagerForColorSchemeSwitch = ModernWpf.ThemeManager; namespace Flow.Launcher.SettingPages.ViewModels; @@ -22,6 +22,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"; @@ -33,9 +34,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; } } @@ -45,19 +46,19 @@ public bool DropShadowEffect get => Settings.UseDropShadowEffect; set { - if (ThemeManager.Instance.BlurEnabled && value) + if (_theme.BlurEnabled && value) { - App.API.ShowMsgBox(InternationalizationManager.Instance.GetTranslation("shadowEffectNotAllowed")); + App.API.ShowMsgBox(App.API.GetTranslation("shadowEffectNotAllowed")); return; } if (value) { - ThemeManager.Instance.AddDropShadowEffectToCurrentTheme(); + _theme.AddDropShadowEffectToCurrentTheme(); } else { - ThemeManager.Instance.RemoveDropShadowEffectFromCurrentTheme(); + _theme.RemoveDropShadowEffectFromCurrentTheme(); } Settings.UseDropShadowEffect = value; @@ -95,7 +96,7 @@ public double ResultSubItemFontSize } private List _themes; - public List Themes => _themes ??= ThemeManager.Instance.LoadAvailableThemes(); + public List Themes => _themes ??= _theme.LoadAvailableThemes(); public class ColorSchemeData : DropdownDataGeneric { } @@ -221,8 +222,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" @@ -230,8 +231,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" @@ -239,8 +240,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" @@ -248,8 +249,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" @@ -281,7 +282,7 @@ public FontFamily SelectedQueryBoxFont set { Settings.QueryBoxFont = value.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } @@ -303,7 +304,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); } } @@ -325,7 +326,7 @@ public FontFamily SelectedResultFont set { Settings.ResultFont = value.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } @@ -347,7 +348,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); } } @@ -371,7 +372,7 @@ public FontFamily SelectedResultSubFont set { Settings.ResultSubFont = value.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); + _theme.ChangeTheme(Settings.Theme); } } @@ -392,7 +393,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); } } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 6b0144a0384..e9f166e9dbe 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")); + App.API.ShowMsg(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 209a813955a..274b9fb0160 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 } };