show updatelog after update

This commit is contained in:
DismissedLight
2024-07-08 10:48:10 +08:00
parent f5dbabc586
commit 04d4fa0c29
10 changed files with 130 additions and 8 deletions

View File

@@ -9,7 +9,6 @@ using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Core.LifeCycle; using Snap.Hutao.Core.LifeCycle;
using Snap.Hutao.Core.LifeCycle.InterProcess; using Snap.Hutao.Core.LifeCycle.InterProcess;
using Snap.Hutao.Core.Logging; using Snap.Hutao.Core.Logging;
using Snap.Hutao.UI.Xaml;
using System.Diagnostics; using System.Diagnostics;
namespace Snap.Hutao; namespace Snap.Hutao;

View File

@@ -39,6 +39,7 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
private readonly ICurrentXamlWindowReference currentWindowReference; private readonly ICurrentXamlWindowReference currentWindowReference;
private readonly IServiceProvider serviceProvider; private readonly IServiceProvider serviceProvider;
private readonly RuntimeOptions runtimeOptions;
private readonly ILogger<AppActivation> logger; private readonly ILogger<AppActivation> logger;
private readonly ITaskContext taskContext; private readonly ITaskContext taskContext;
@@ -257,6 +258,12 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
guideWindow.BringToForeground(); guideWindow.BringToForeground();
return; return;
} }
if (Version.Parse(LocalSetting.Get(SettingKeys.LastVersion, "0.0.0.0")) < runtimeOptions.Version)
{
XamlApplicationLifetime.IsFirstRunAfterUpdate = true;
LocalSetting.Set(SettingKeys.LastVersion, $"{runtimeOptions.Version}");
}
} }
await WaitMainWindowOrCurrentAsync().ConfigureAwait(false); await WaitMainWindowOrCurrentAsync().ConfigureAwait(false);

View File

@@ -22,6 +22,7 @@ internal static class SettingKeys
#endregion #endregion
#region Application #region Application
public const string LastVersion = "LastVersion";
public const string LaunchTimes = "LaunchTimes"; public const string LaunchTimes = "LaunchTimes";
public const string DataFolderPath = "DataFolderPath"; public const string DataFolderPath = "DataFolderPath";
public const string Major1Minor10Revision0GuideState = "Major1Minor10Revision0GuideState1"; public const string Major1Minor10Revision0GuideState = "Major1Minor10Revision0GuideState1";
@@ -63,6 +64,7 @@ internal static class SettingKeys
public const string OverrideElevationRequirement = "OverrideElevationRequirement"; public const string OverrideElevationRequirement = "OverrideElevationRequirement";
public const string OverrideUpdateVersionComparison = "OverrideUpdateVersionComparison"; public const string OverrideUpdateVersionComparison = "OverrideUpdateVersionComparison";
public const string OverridePackageConvertDirectoryPermissionsRequirement = "OverridePackageConvertDirectoryPermissionsRequirement"; public const string OverridePackageConvertDirectoryPermissionsRequirement = "OverridePackageConvertDirectoryPermissionsRequirement";
public const string AlwaysIsFirstRunAfterUpdate = "AlwaysIsFirstRunAfterUpdate";
#endregion #endregion
#region Obsolete #region Obsolete

View File

@@ -12,8 +12,13 @@ internal sealed partial class ShowWebView2WindowAction : DependencyObject, IActi
{ {
public object? Execute(object sender, object parameter) public object? Execute(object sender, object parameter)
{ {
WebView2Window window = new(((FrameworkElement)sender).XamlRoot.ContentIslandEnvironment.AppWindowId, ContentProvider); ShowAt(((FrameworkElement)sender).XamlRoot);
window.Activate();
return default!; return default!;
} }
public void ShowAt(XamlRoot xamlRoot)
{
WebView2Window window = new(xamlRoot.ContentIslandEnvironment.AppWindowId, ContentProvider);
window.Activate();
}
} }

View File

@@ -116,6 +116,10 @@
<ToggleSwitch IsOn="{Binding OverridePackageConvertDirectoryPermissionsRequirement, Mode=TwoWay}"/> <ToggleSwitch IsOn="{Binding OverridePackageConvertDirectoryPermissionsRequirement, Mode=TwoWay}"/>
</cwc:SettingsCard> </cwc:SettingsCard>
<cwc:SettingsCard Header="Always Treat As First Run After Update">
<ToggleSwitch IsOn="{Binding AlwaysIsFirstRunAfterUpdate, Mode=TwoWay}"/>
</cwc:SettingsCard>
<TextBlock Style="{ThemeResource SettingsSectionHeaderTextBlockStyle}" Text="Gacha Service"/> <TextBlock Style="{ThemeResource SettingsSectionHeaderTextBlockStyle}" Text="Gacha Service"/>
<cwc:SettingsCard <cwc:SettingsCard
Command="{Binding CompensationGachaLogServiceTimeCommand}" Command="{Binding CompensationGachaLogServiceTimeCommand}"

View File

@@ -0,0 +1,74 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.Web.WebView2.Core;
using Snap.Hutao.Core.Graphics;
using Windows.Graphics;
namespace Snap.Hutao.UI.Xaml.View.Window.WebView2;
internal sealed class UpdateLogContentProvider : IWebView2ContentProvider
{
public ElementTheme ActualTheme { get; set; }
public CoreWebView2? CoreWebView2 { get; set; }
public ValueTask InitializeAsync(IServiceProvider serviceProvider, CancellationToken token)
{
ArgumentNullException.ThrowIfNull(CoreWebView2);
CoreWebView2.Navigate("https://hut.ao/statements/latest.html");
return ValueTask.CompletedTask;
}
public RectInt32 InitializePosition(RectInt32 parentRect, double parentDpi)
{
PointInt32 center = parentRect.GetPointInt32(PointInt32Kind.Center);
SizeInt32 size = new SizeInt32(480, 800).Scale(parentDpi);
RectInt32 target = RectInt32Convert.RectInt32(new(center.X - (size.Width / 2), center.Y - (size.Height / 2)), size);
RectInt32 workArea = DisplayArea.GetFromRect(parentRect, DisplayAreaFallback.None).WorkArea;
RectInt32 workAreaShrink = new(workArea.X + 48, workArea.Y + 48, workArea.Width - 96, workArea.Height - 96);
if (target.Width > workAreaShrink.Width)
{
target.Width = workAreaShrink.Width;
}
if (target.Height > workAreaShrink.Height)
{
target.Height = workAreaShrink.Height;
}
PointInt32 topLeft = target.GetPointInt32(PointInt32Kind.TopLeft);
if (topLeft.X < workAreaShrink.X)
{
target.X = workAreaShrink.X;
}
if (topLeft.Y < workAreaShrink.Y)
{
target.Y = workAreaShrink.Y;
}
PointInt32 bottomRight = target.GetPointInt32(PointInt32Kind.BottomRight);
PointInt32 workAreeShrinkBottomRight = workAreaShrink.GetPointInt32(PointInt32Kind.BottomRight);
if (bottomRight.X > workAreeShrinkBottomRight.X)
{
target.X = workAreeShrinkBottomRight.X - target.Width;
}
if (bottomRight.Y > workAreeShrinkBottomRight.Y)
{
target.Y = workAreeShrinkBottomRight.Y - target.Height;
}
return target;
}
public void Unload()
{
}
}

View File

@@ -95,6 +95,20 @@ internal sealed partial class TestViewModel : Abstraction.ViewModel
} }
} }
public bool AlwaysIsFirstRunAfterUpdate
{
get => LocalSetting.Get(SettingKeys.AlwaysIsFirstRunAfterUpdate, false);
set
{
if (IsViewDisposed)
{
return;
}
LocalSetting.Set(SettingKeys.AlwaysIsFirstRunAfterUpdate, value);
}
}
[Command("ResetGuideStateCommand")] [Command("ResetGuideStateCommand")]
private static void ResetGuideState() private static void ResetGuideState()
{ {

View File

@@ -3,14 +3,18 @@
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Core; using Snap.Hutao.Core;
using Snap.Hutao.Core.LifeCycle;
using Snap.Hutao.Core.Setting;
using Snap.Hutao.Factory.ContentDialog; using Snap.Hutao.Factory.ContentDialog;
using Snap.Hutao.Factory.Progress; using Snap.Hutao.Factory.Progress;
using Snap.Hutao.Service.Abstraction; using Snap.Hutao.Service.Abstraction;
using Snap.Hutao.Service.Notification; using Snap.Hutao.Service.Notification;
using Snap.Hutao.Service.Update; using Snap.Hutao.Service.Update;
using Snap.Hutao.UI.Input.HotKey; using Snap.Hutao.UI.Input.HotKey;
using Snap.Hutao.UI.Xaml.Behavior.Action;
using Snap.Hutao.UI.Xaml.Control; using Snap.Hutao.UI.Xaml.Control;
using Snap.Hutao.UI.Xaml.View.Dialog; using Snap.Hutao.UI.Xaml.View.Dialog;
using Snap.Hutao.UI.Xaml.View.Window.WebView2;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
@@ -20,6 +24,7 @@ namespace Snap.Hutao.ViewModel;
[Injection(InjectAs.Singleton)] [Injection(InjectAs.Singleton)]
internal sealed partial class TitleViewModel : Abstraction.ViewModel internal sealed partial class TitleViewModel : Abstraction.ViewModel
{ {
private readonly ICurrentXamlWindowReference currentXamlWindowReference;
private readonly IContentDialogFactory contentDialogFactory; private readonly IContentDialogFactory contentDialogFactory;
private readonly IProgressFactory progressFactory; private readonly IProgressFactory progressFactory;
private readonly IInfoBarService infoBarService; private readonly IInfoBarService infoBarService;
@@ -58,10 +63,22 @@ internal sealed partial class TitleViewModel : Abstraction.ViewModel
protected override async ValueTask<bool> InitializeOverrideAsync() protected override async ValueTask<bool> InitializeOverrideAsync()
{ {
ShowUpdateLogWindowAfterUpdate();
await DoCheckUpdateAsync().ConfigureAwait(false); await DoCheckUpdateAsync().ConfigureAwait(false);
return true; return true;
} }
private void ShowUpdateLogWindowAfterUpdate()
{
if (LocalSetting.Get(SettingKeys.AlwaysIsFirstRunAfterUpdate, false) || XamlApplicationLifetime.IsFirstRunAfterUpdate)
{
new ShowWebView2WindowAction()
{
ContentProvider = new UpdateLogContentProvider(),
}.ShowAt(currentXamlWindowReference.GetXamlRoot());
}
}
private async ValueTask DoCheckUpdateAsync() private async ValueTask DoCheckUpdateAsync()
{ {
IProgress<UpdateStatus> progress = progressFactory.CreateForMainThread<UpdateStatus>(status => UpdateStatus = status); IProgress<UpdateStatus> progress = progressFactory.CreateForMainThread<UpdateStatus>(status => UpdateStatus = status);

View File

@@ -260,14 +260,12 @@ internal sealed partial class UserViewModel : ObservableObject
// Manual webview // Manual webview
await taskContext.SwitchToMainThreadAsync(); await taskContext.SwitchToMainThreadAsync();
ShowWebView2WindowAction action = new() new ShowWebView2WindowAction()
{ {
ContentProvider = new MiHoYoJSBridgeWebView2ContentProvider() ContentProvider = new MiHoYoJSBridgeWebView2ContentProvider()
{ {
SourceProvider = new SignInJSBridgeUriSourceProvider(), SourceProvider = new SignInJSBridgeUriSourceProvider(),
}, },
}; }.ShowAt(appBarButton.XamlRoot);
action.Execute(appBarButton, default!);
} }
} }

View File

@@ -1,11 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved. // Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license. // Licensed under the MIT license.
namespace Snap.Hutao.UI.Xaml; namespace Snap.Hutao;
internal static class XamlApplicationLifetime internal static class XamlApplicationLifetime
{ {
public static bool LaunchedWithNotifyIcon { get; set; } public static bool LaunchedWithNotifyIcon { get; set; }
public static bool Exiting { get; set; } public static bool Exiting { get; set; }
public static bool IsFirstRunAfterUpdate { get; set; }
} }