From b202e1609e168f7c26acf1785ac0700f2467bdbe Mon Sep 17 00:00:00 2001 From: wherewhere Date: Tue, 7 Nov 2023 19:58:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E8=BF=9B=E7=A8=8B=E4=BF=9D?= =?UTF-8?q?=E6=8C=81=E5=90=8E=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E7=AA=97=E5=8F=A3=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreAppUWP/Controls/DesktopWindow.cs | 9 ++-- .../Pages/SettingsPages/SettingsPage.xaml | 12 ++--- .../Pages/SettingsPages/SettingsPage.xaml.cs | 30 ++++++------ .../SettingsPages/SettingsViewModel.cs | 46 ++++++++----------- 4 files changed, 47 insertions(+), 50 deletions(-) diff --git a/CoreAppUWP/Controls/DesktopWindow.cs b/CoreAppUWP/Controls/DesktopWindow.cs index f8ad338..e185b9d 100644 --- a/CoreAppUWP/Controls/DesktopWindow.cs +++ b/CoreAppUWP/Controls/DesktopWindow.cs @@ -119,7 +119,7 @@ public static Task CreateAsync(Action la { TaskCompletionSource taskCompletionSource = new(); - Thread thread = new(async () => + new Thread(async () => { try { @@ -158,8 +158,10 @@ public static Task CreateAsync(Action la { taskCompletionSource.SetException(e); } - }); - thread.Start(); + }) + { + Name = nameof(DesktopWindowXamlSource) + }.Start(); return taskCompletionSource.Task; } @@ -204,7 +206,6 @@ public static Task CreateAsync(DispatcherQueue dispatcherQueue, A WindowXamlSource = source }; taskCompletionSource.SetResult(desktopWindow); - dispatcherQueue.RunEventLoop(); } catch (Exception e) { diff --git a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml index fdbc10a..c9485ea 100644 --- a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml +++ b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml @@ -225,7 +225,7 @@ Grid.Column="1" Padding="32,0,0,8" Foreground="{ThemeResource TextFillColorSecondaryBrush}" - Text="{Binding DeviceFamily}" + Text="{x:Bind settingspages:SettingsViewModel.DeviceFamily}" TextWrapping="WrapWholeWords" /> - + diff --git a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs index 30a1ef0..1aa529a 100644 --- a/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs +++ b/CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs @@ -6,6 +6,7 @@ using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Hosting; using Microsoft.UI.Xaml.Media.Animation; using Microsoft.UI.Xaml.Navigation; using System; @@ -92,6 +93,7 @@ private async void Button_Click(object sender, RoutedEventArgs e) { desktopWindow.AppWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay); } break; case "NewWindow": + bool isProcessKept = Provider.IsProcessKept; _ = await WindowHelper.CreateWindowAsync(window => { if (SettingsHelper.Get(SettingsHelper.IsExtendsTitleBar)) @@ -99,25 +101,25 @@ private async void Button_Click(object sender, RoutedEventArgs e) Frame _frame = new(); window.Content = _frame; ThemeHelper.Initialize(window); - try { _ = _frame.Navigate(typeof(MainPage), null, new DrillInNavigationTransitionInfo()); } - catch { _ = _frame.Navigate(typeof(MainPage)); } + NavigationTransitionInfo transitionInfo = null; + if (!isProcessKept) { try { transitionInfo = new DrillInNavigationTransitionInfo(); } catch { } } + _ = _frame.Navigate(typeof(MainPage), null, transitionInfo); BackdropHelper.SetBackdrop(window, SettingsHelper.Get(SettingsHelper.SelectedBackdrop)); }); break; case "NewAppWindow": + isProcessKept = Provider.IsProcessKept; DesktopWindow window = await (IsCoreWindow - ? WindowHelper.CreateDesktopWindowAsync(window => - { - Frame _frame = new(); - window.Content = _frame; - _ = _frame.Navigate(typeof(MainPage), null, new DrillInNavigationTransitionInfo()); - }) - : DispatcherQueue.CreateDesktopWindowAsync(window => - { - Frame _frame = new(); - window.Content = _frame; - _ = _frame.Navigate(typeof(MainPage), null, new DrillInNavigationTransitionInfo()); - })).ConfigureAwait(false); + ? WindowHelper.CreateDesktopWindowAsync(OnLaunched) + : DispatcherQueue.CreateDesktopWindowAsync(OnLaunched)).ConfigureAwait(false); + void OnLaunched(DesktopWindowXamlSource source) + { + Frame _frame = new(); + source.Content = _frame; + NavigationTransitionInfo transitionInfo = null; + if (!isProcessKept) { try { transitionInfo = new DrillInNavigationTransitionInfo(); } catch { } } + _ = _frame.Navigate(typeof(MainPage), null, transitionInfo); + } if (AppWindowTitleBar.IsCustomizationSupported() && SettingsHelper.Get(SettingsHelper.IsExtendsTitleBar)) { window.ExtendsContentIntoTitleBar = true; } diff --git a/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs b/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs index cb8598f..bf6237a 100644 --- a/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs +++ b/CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs @@ -23,15 +23,17 @@ public class SettingsViewModel : INotifyPropertyChanged { public static Dictionary Caches { get; } = []; - public static string WASVersion => Assembly.GetAssembly(typeof(ExtendedActivationKind)).GetName().Version.ToString(3); + public static string WASVersion { get; } = Assembly.GetAssembly(typeof(ExtendedActivationKind)).GetName().Version.ToString(3); - public static string SDKVersion => Assembly.GetAssembly(typeof(PackageSignatureKind)).GetName().Version.ToString(); + public static string SDKVersion { get; } = Assembly.GetAssembly(typeof(PackageSignatureKind)).GetName().Version.ToString(); - public static string WinRTVersion => Assembly.GetAssembly(typeof(TrustLevel)).GetName().Version.ToString(3); + public static string WinRTVersion { get; } = Assembly.GetAssembly(typeof(TrustLevel)).GetName().Version.ToString(3); - public static string DeviceFamily => AnalyticsInfo.VersionInfo.DeviceFamily.Replace('.', ' '); + public static string DeviceFamily { get; } = AnalyticsInfo.VersionInfo.DeviceFamily.Replace('.', ' '); - public static string ToolkitVersion => Assembly.GetAssembly(typeof(HsvColor)).GetName().Version.ToString(3); + public static string ToolkitVersion { get; } = Assembly.GetAssembly(typeof(HsvColor)).GetName().Version.ToString(3); + + public static string VersionTextBlockText { get; } = $"{Package.Current.DisplayName} v{Package.Current.Id.Version.ToFormattedString(3)}"; public DispatcherQueue Dispatcher { get; } @@ -134,33 +136,25 @@ protected void SetProperty(ref TProperty property, TProperty value, [ } } - public string VersionTextBlockText - { - get - { - string ver = Package.Current.Id.Version.ToFormattedString(3); - string name = Package.Current.DisplayName; - _ = GetAboutTextBlockTextAsync(); - return $"{name} v{ver}"; - } - } - public SettingsViewModel(DispatcherQueue dispatcher) { Dispatcher = dispatcher ?? DispatcherQueue.GetForCurrentThread(); Caches[dispatcher] = this; } - private async Task GetAboutTextBlockTextAsync() + private async Task GetAboutTextBlockTextAsync(bool reset) { - await ThreadSwitcher.ResumeBackgroundAsync(); - const string langCode = "en-US"; - Uri dataUri = new($"ms-appx:///Assets/About/About.{langCode}.md"); - StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri); - if (file != null) + if (reset || string.IsNullOrWhiteSpace(_aboutTextBlockText)) { - string markdown = await FileIO.ReadTextAsync(file); - AboutTextBlockText = markdown; + await ThreadSwitcher.ResumeBackgroundAsync(); + const string langCode = "en-US"; + Uri dataUri = new($"ms-appx:///Assets/About/About.{langCode}.md"); + StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri); + if (file != null) + { + string markdown = await FileIO.ReadTextAsync(file); + AboutTextBlockText = markdown; + } } } @@ -168,8 +162,8 @@ public void KeepProcess() { if (!_isProcessKept) { - _ = Dispatcher.TryEnqueue(() => Dispatcher.RunEventLoop(DispatcherRunOptions.ContinueOnQuit, new DispatcherExitDeferral())); IsProcessKept = true; + Dispatcher.RunEventLoop(DispatcherRunOptions.ContinueOnQuit, new DispatcherExitDeferral()); } } @@ -182,7 +176,7 @@ public async Task Refresh(bool reset) nameof(SelectedBackdrop), nameof(IsExtendsTitleBar)); } - await GetAboutTextBlockTextAsync(); + await GetAboutTextBlockTextAsync(reset); } } }