From 2b6e1bf1c73d321909937e3cd31dd974654ffcae Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 17 Mar 2025 09:35:42 +0800 Subject: [PATCH] Improve code quality --- Flow.Launcher/App.xaml | 2 +- Flow.Launcher/App.xaml.cs | 21 +++++++++++---------- Flow.Launcher/MainWindow.xaml.cs | 8 ++++---- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher/App.xaml b/Flow.Launcher/App.xaml index 17c0ae0d5..565bbe3c7 100644 --- a/Flow.Launcher/App.xaml +++ b/Flow.Launcher/App.xaml @@ -4,7 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.modernwpf.com/2019" ShutdownMode="OnMainWindowClose" - Startup="OnStartupAsync"> + Startup="OnStartup"> diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 7d094a0af..23c77618f 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -101,15 +101,15 @@ namespace Flow.Launcher { if (SingleInstance.InitializeAsFirstInstance(Unique)) { - using (var application = new App()) - { - application.InitializeComponent(); - application.Run(); - } + using var application = new App(); + application.InitializeComponent(); + application.Run(); } } - private async void OnStartupAsync(object sender, StartupEventArgs e) +#pragma warning disable VSTHRD100 // Avoid async void methods + + private async void OnStartup(object sender, StartupEventArgs e) { await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () => { @@ -128,7 +128,7 @@ namespace Flow.Launcher 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,7 +148,7 @@ namespace Flow.Launcher // 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(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); @@ -163,6 +163,8 @@ namespace Flow.Launcher }); } +#pragma warning restore VSTHRD100 // Avoid async void methods + private void AutoStartup() { // we try to enable auto-startup on first launch, or reenable if it was removed @@ -185,8 +187,7 @@ namespace Flow.Launcher // 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/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 3bc9be83f..3fd13afdf 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -77,7 +77,7 @@ namespace Flow.Launcher #region Window Event -#pragma warning disable VSTHRD100 +#pragma warning disable VSTHRD100 // Avoid async void methods private void OnSourceInitialized(object sender, EventArgs e) { @@ -346,7 +346,7 @@ namespace Flow.Launcher } } -#pragma warning restore VSTHRD100 +#pragma warning restore VSTHRD100 // Avoid async void methods #endregion @@ -361,7 +361,7 @@ namespace Flow.Launcher #region Window Context Menu Event -#pragma warning disable VSTHRD100 +#pragma warning disable VSTHRD100 // Avoid async void methods private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e) { @@ -373,7 +373,7 @@ namespace Flow.Launcher App.API.OpenSettingDialog(); } -#pragma warning restore VSTHRD100 +#pragma warning restore VSTHRD100 // Avoid async void methods #endregion