From f7e94fe2f2a865a47507542874bc6e898a37afd9 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Wed, 22 May 2024 16:46:06 +0800 Subject: [PATCH] refine view --- src/Snap.Hutao/Snap.Hutao/App.xaml.cs | 2 +- .../Core/LifeCycle/AppActivation.cs | 26 ++++-- .../Core/Threading/SemaphoreSlimExtension.cs | 4 +- .../Snap.Hutao/View/Guide/GuideView.xaml | 86 +++++++++++-------- 4 files changed, 72 insertions(+), 46 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/App.xaml.cs b/src/Snap.Hutao/Snap.Hutao/App.xaml.cs index c68ae860..ad1a653f 100644 --- a/src/Snap.Hutao/Snap.Hutao/App.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/App.xaml.cs @@ -85,7 +85,7 @@ public sealed partial class App : Application } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine(ex); + Debug.WriteLine(ex); Process.GetCurrentProcess().Kill(); } } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs index d88ac044..076bf8ed 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/AppActivation.cs @@ -44,6 +44,7 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi private readonly IServiceProvider serviceProvider; private readonly ICurrentXamlWindowReference currentWindowReference; private readonly ITaskContext taskContext; + private readonly SemaphoreSlim activateSemaphore = new(1); /// @@ -65,16 +66,24 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi serviceProvider.GetRequiredService().RunAsync().SafeForget(); ToastNotificationManagerCompat.OnActivated += NotificationActivate; - serviceProvider.GetRequiredService().RegisterAll(); - if (serviceProvider.GetRequiredService().IsNotifyIconEnabled) + using (activateSemaphore.Enter()) { - XamlWindowLifetime.ApplicationLaunchedWithNotifyIcon = true; - serviceProvider.GetRequiredService().DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown; - _ = serviceProvider.GetRequiredService(); - } + serviceProvider.GetRequiredService().RegisterAll(); + if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed) + { + return; + } - serviceProvider.GetRequiredService().UnregisterAllTasks(); - serviceProvider.GetRequiredService().StartAsync(default).SafeForget(); + if (serviceProvider.GetRequiredService().IsNotifyIconEnabled) + { + XamlWindowLifetime.ApplicationLaunchedWithNotifyIcon = true; + serviceProvider.GetRequiredService().DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown; + _ = serviceProvider.GetRequiredService(); + } + + serviceProvider.GetRequiredService().UnregisterAllTasks(); + serviceProvider.GetRequiredService().StartAsync(default).SafeForget(); + } } public void Dispose() @@ -172,7 +181,6 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi } } - // If it's the first time launch, show the guide window anyway. if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed) { await taskContext.SwitchToMainThreadAsync(); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Threading/SemaphoreSlimExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/Threading/SemaphoreSlimExtension.cs index 8dd74e1b..870ecc5a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Threading/SemaphoreSlimExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Threading/SemaphoreSlimExtension.cs @@ -15,7 +15,7 @@ internal static class SemaphoreSlimExtension } catch (ObjectDisposedException ex) { - ThrowHelper.OperationCanceled(SH.CoreThreadingSemaphoreSlimDisposed, ex); + HutaoException.OperationCanceled(SH.CoreThreadingSemaphoreSlimDisposed, ex); } return new SemaphoreSlimToken(semaphoreSlim); @@ -29,7 +29,7 @@ internal static class SemaphoreSlimExtension } catch (ObjectDisposedException ex) { - ThrowHelper.OperationCanceled(SH.CoreThreadingSemaphoreSlimDisposed, ex); + HutaoException.OperationCanceled(SH.CoreThreadingSemaphoreSlimDisposed, ex); } return new SemaphoreSlimToken(semaphoreSlim); diff --git a/src/Snap.Hutao/Snap.Hutao/View/Guide/GuideView.xaml b/src/Snap.Hutao/Snap.Hutao/View/Guide/GuideView.xaml index fdce769b..b6e79770 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Guide/GuideView.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Guide/GuideView.xaml @@ -2,6 +2,7 @@ x:Class="Snap.Hutao.View.Guide.GuideView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:cw="using:CommunityToolkit.WinUI" xmlns:cwc="using:CommunityToolkit.WinUI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -210,14 +211,58 @@ - - + ColumnSpacing="32"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - +