Skip to content

Commit

Permalink
optimize checking agreement procedure of hoyolab toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 16, 2024
1 parent 1a572f0 commit 49e34b0
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Starward.Services;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
Expand Down Expand Up @@ -111,29 +110,42 @@ private async Task CheckAgreementAsync()
{
Title = Lang.Common_Disclaimer,
Content = Lang.HoyolabToolboxPage_DisclaimerContent,
PrimaryButtonText = Lang.Common_Accept,
PrimaryButtonText = Lang.Common_Accept + " (5s)",
SecondaryButtonText = Lang.Common_Reject,
IsPrimaryButtonEnabled = false,
DefaultButton = ContentDialogButton.Secondary,
XamlRoot = this.XamlRoot,
};
var sw = Stopwatch.StartNew();
var result = await dialog.ShowAsync();
sw.Stop();
if (result is ContentDialogResult.Secondary)
var resultTask = dialog.ShowAsync();
bool cancel = false;
for (int i = 0; i < 5; i++)
{
WeakReferenceMessenger.Default.Send(new MainPageNavigateMessage(typeof(LauncherPage)));
return;
}
if (sw.ElapsedMilliseconds < 5000)
{
dialog.Title = Lang.HoyolabToolboxPage_WarningAgain;
result = await dialog.ShowAsync();
if (result is ContentDialogResult.Secondary)
for (int j = 0; j < 10; j++)
{
await Task.Delay(100);
if (resultTask.Status is Windows.Foundation.AsyncStatus.Completed)
{
cancel = true;
break;
}
}
if (cancel)
{
WeakReferenceMessenger.Default.Send(new MainPageNavigateMessage(typeof(LauncherPage)));
return;
break;
}
dialog.PrimaryButtonText = Lang.Common_Accept + $" ({4 - i}s)";
}
dialog.PrimaryButtonText = Lang.Common_Accept;
dialog.IsPrimaryButtonEnabled = true;
var result = await resultTask;
if (result is ContentDialogResult.Primary)
{
AppConfig.AcceptHoyolabToolboxAgreement = true;
}
else
{
WeakReferenceMessenger.Default.Send(new MainPageNavigateMessage(typeof(LauncherPage)));
}
AppConfig.AcceptHoyolabToolboxAgreement = true;
}
}
catch (Exception ex)
Expand Down

0 comments on commit 49e34b0

Please sign in to comment.