Improve code quality

This commit is contained in:
Jack251970 2025-03-17 09:35:42 +08:00
parent 0bcc187b5d
commit 2b6e1bf1c7
3 changed files with 16 additions and 15 deletions

View file

@ -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">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

View file

@ -101,15 +101,15 @@ namespace Flow.Launcher
{
if (SingleInstance<App>.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<Internationalization>().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<Theme>().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);
}
}
}

View file

@ -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