forked from Scighost/Starward
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
257 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Starward.Messages; | ||
|
||
public record UpdateGachaLogMessage(string Url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<local:WindowEx x:Class="Starward.MyWindows.CloudGameGachaWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:lang="using:Starward.Language" | ||
xmlns:local="using:Starward.MyWindows" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<Grid x:Name="RootGrid" | ||
Padding="0,32,0,0" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" | ||
Loaded="RootGrid_Loaded"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<TextBlock x:Name="TextBlock_Info" | ||
Margin="12,0,12,0" | ||
VerticalAlignment="Center" | ||
Foreground="{ThemeResource TextFillColorSecondaryBrush}" | ||
Text="{x:Bind lang:Lang.CloudGameGachaWindow_OpenTheGachaRecordsPageInGameAndThenClickTheButtonOnTheRight}" | ||
TextWrapping="Wrap" /> | ||
<TextBlock x:Name="TextBlock_Error" | ||
Margin="12,0,12,0" | ||
VerticalAlignment="Center" | ||
Foreground="{ThemeResource SystemFillColorCriticalBrush}" | ||
TextWrapping="Wrap" | ||
Visibility="Collapsed" /> | ||
<Button Grid.Column="1" | ||
Click="Button_Click" | ||
Content="获取抽卡记录" /> | ||
|
||
<WebView2 x:Name="webview" | ||
Grid.Row="1" | ||
Grid.ColumnSpan="2" /> | ||
|
||
</Grid> | ||
|
||
</local:WindowEx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
using CommunityToolkit.Mvvm.Messaging; | ||
using Microsoft.UI.Xaml; | ||
using Starward.Core; | ||
using Starward.Messages; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Text.Json.Nodes; | ||
using System.Web; | ||
|
||
// To learn more about WinUI, the WinUI project structure, | ||
// and more about our project templates, see: http://aka.ms/winui-project-info. | ||
|
||
namespace Starward.MyWindows; | ||
|
||
/// <summary> | ||
/// An empty window that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class CloudGameGachaWindow : WindowEx | ||
{ | ||
|
||
|
||
private const string SPAN_WEB_PREFIX_YS_CN = "https://webstatic.mihoyo.com/hk4e/event/e20190909gacha-v3/index.html"; | ||
|
||
private const string SPAN_WEB_PREFIX_SR_CN = "https://webstatic.mihoyo.com/hkrpg/event/e20211215gacha-v2/index.html"; | ||
|
||
|
||
|
||
public GameBiz GameBiz { get; set; } | ||
|
||
|
||
|
||
|
||
public CloudGameGachaWindow() | ||
{ | ||
this.InitializeComponent(); | ||
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true; | ||
if (ShouldSystemUseDarkMode()) | ||
{ | ||
RootGrid.RequestedTheme = ElementTheme.Dark; | ||
} | ||
else | ||
{ | ||
RootGrid.RequestedTheme = ElementTheme.Light; | ||
} | ||
AdaptTitleBarButtonColorToActuallTheme(); | ||
} | ||
|
||
|
||
|
||
private void RootGrid_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
try | ||
{ | ||
// todo WinAppSDK 升级到 1.5 后,为云游戏的网页缓存设置单独的文件夹 | ||
if (GameBiz.ToGame() is GameBiz.GenshinImpact) | ||
{ | ||
webview.Source = new Uri("https://ys.mihoyo.com/cloud/"); | ||
} | ||
if (GameBiz.ToGame() is GameBiz.StarRail) | ||
{ | ||
webview.Source = new Uri("https://sr.mihoyo.com/cloud/"); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
private async void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
try | ||
{ | ||
await webview.EnsureCoreWebView2Async(); | ||
string result = await webview.CoreWebView2.ExecuteScriptAsync("document.documentElement.outerHTML"); | ||
string? html = JsonNode.Parse(result)?.ToString(); | ||
if (!string.IsNullOrWhiteSpace(html)) | ||
{ | ||
string? url = GetMatchUrl(GameBiz, html); | ||
if (!string.IsNullOrWhiteSpace(url)) | ||
{ | ||
url = HttpUtility.HtmlDecode(url); | ||
WeakReferenceMessenger.Default.Send(new UpdateGachaLogMessage(url)); | ||
TextBlock_Info.Visibility = Visibility.Visible; | ||
TextBlock_Error.Visibility = Visibility.Collapsed; | ||
return; | ||
} | ||
} | ||
TextBlock_Info.Visibility = Visibility.Collapsed; | ||
TextBlock_Error.Visibility = Visibility.Visible; | ||
TextBlock_Error.Text = Lang.GachaLogPage_CannotFindURL; | ||
} | ||
catch (Exception ex) | ||
{ | ||
TextBlock_Info.Visibility = Visibility.Collapsed; | ||
TextBlock_Error.Visibility = Visibility.Visible; | ||
TextBlock_Error.Text = ex.Message; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
private static string? GetMatchUrl(GameBiz gameBiz, string html) | ||
{ | ||
string? prefix = gameBiz.ToGame() switch | ||
{ | ||
GameBiz.GenshinImpact => SPAN_WEB_PREFIX_YS_CN, | ||
GameBiz.StarRail => SPAN_WEB_PREFIX_SR_CN, | ||
_ => null | ||
}; | ||
if (prefix is not null) | ||
{ | ||
ReadOnlySpan<char> span = html.AsSpan(); | ||
int index = span.LastIndexOf(prefix); | ||
if (index >= 0) | ||
{ | ||
var length = span[index..].IndexOfAny("\""); | ||
return new(span.Slice(index, length)); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
[return: MarshalAs(UnmanagedType.Bool)] | ||
[LibraryImport("uxtheme.dll", EntryPoint = "#138", SetLastError = true)] | ||
private static partial bool ShouldSystemUseDarkMode(); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters