Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34418f7556 | ||
|
|
69b3e787d3 | ||
|
|
4a0c3cbb56 | ||
|
|
420776768f | ||
|
|
2bf426809b | ||
|
|
75c492a44f | ||
|
|
885d5997b1 | ||
|
|
b42898cfc2 | ||
|
|
0fae5ebab3 |
No files matched your search
@@ -73,4 +73,11 @@ public partial class CommonConfig : ObservableObject
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private List<string> _onceHadRunDeviceIdList = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前看过的兑换码推送版本
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _redeemCodeFeedsUpdateVersion = "20251013";
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.UseRedeemCode;
|
||||
|
||||
public class GamePreviewLiveDateCalculator
|
||||
{
|
||||
private static readonly DateTime StartDate = new DateTime(2025, 10, 10);
|
||||
private const int IntervalDays = 42;
|
||||
private const double ValidDays = 3.5;
|
||||
|
||||
/// <summary>
|
||||
/// 计算当前日期是否是前瞻日期
|
||||
/// </summary>
|
||||
/// <returns>如果是前瞻日期,返回 true;否则返回 false。</returns>
|
||||
public static bool IsPreviewDate(DateTime date)
|
||||
{
|
||||
TimeSpan difference = date - StartDate;
|
||||
return difference.Days >= 0 && difference.Days % IntervalDays == 0;
|
||||
}
|
||||
|
||||
public static void TestIsPreviewDate()
|
||||
{
|
||||
IsPreviewDate(new DateTime(2025, 11, 21));
|
||||
}
|
||||
|
||||
public bool TestTodayIsPreviewDate()
|
||||
{
|
||||
return IsPreviewDate(DateTime.Today);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算当前时间是否在从前瞻日期开始的2.5天范围内。
|
||||
/// </summary>
|
||||
/// <returns>如果在范围内,返回 true;否则返回 false。</returns>
|
||||
public static bool IsWithinPreviewRange(DateTime now)
|
||||
{
|
||||
TimeSpan difference = now.Date - StartDate;
|
||||
int daysSinceStart = difference.Days;
|
||||
|
||||
if (daysSinceStart < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int intervalCount = daysSinceStart / IntervalDays;
|
||||
DateTime lastPreviewDate = StartDate.AddDays(intervalCount * IntervalDays);
|
||||
TimeSpan timeSinceLastPreview = now - lastPreviewDate;
|
||||
|
||||
return timeSinceLastPreview.TotalDays >= 0 && timeSinceLastPreview.TotalDays <= ValidDays;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,12 @@ namespace BetterGenshinImpact.GameTask.UseRedeemCode;
|
||||
public class RedeemCodeManager
|
||||
{
|
||||
public static HashSet<string> CancelClipboardHash { get; } = [];
|
||||
|
||||
public static void AddNotDetectClipboardText(string clipboardText)
|
||||
{
|
||||
var md5Hash = MD5Helper.ComputeMD5(clipboardText);
|
||||
CancelClipboardHash.Add(md5Hash);
|
||||
}
|
||||
|
||||
public static async Task ImportFromClipboard(string clipboardText)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,15 @@ public sealed class BooleanToVisibilityRevertConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return (value is bool v && v) ? Visibility.Collapsed : Visibility.Visible;
|
||||
if (value is string str)
|
||||
{
|
||||
return string.IsNullOrEmpty(str) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
else if (value is bool b)
|
||||
{
|
||||
return b ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
|
||||
@@ -8,6 +8,11 @@ namespace BetterGenshinImpact.View.Converters
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
|
||||
return value != null;
|
||||
}
|
||||
|
||||
|
||||
@@ -178,13 +178,22 @@
|
||||
</ui:NavigationView.ContentOverlay>
|
||||
</ui:NavigationView>
|
||||
|
||||
<ui:TitleBar Title="{Binding Title, Mode=OneWay}" Grid.Row="0">
|
||||
<ui:TitleBar Title="{Binding Title, Mode=OneWay}" Grid.Row="0" Grid.Column="0">
|
||||
<ui:TitleBar.Icon>
|
||||
<ui:ImageIcon Source="pack://application:,,,/Resources/Images/logo.png" />
|
||||
</ui:TitleBar.Icon>
|
||||
<ui:TitleBar.TrailingContent>
|
||||
<StackPanel VerticalAlignment="Top" Orientation="Horizontal">
|
||||
<ui:Button Width="46"
|
||||
<ui:Button Width="40"
|
||||
Height="32"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
Command="{Binding OpenFeedCommand}"
|
||||
CornerRadius="0"
|
||||
Icon="{ui:SymbolIcon Gift16}"
|
||||
Foreground="{Binding RedeemCodeButtonForeground}"
|
||||
ToolTip="获取兑换码信息" />
|
||||
<ui:Button Width="40"
|
||||
Height="32"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
@@ -192,7 +201,7 @@
|
||||
CornerRadius="0"
|
||||
Icon="{ui:SymbolIcon Blur24}"
|
||||
ToolTip="切换深浅主题或背景样式" />
|
||||
<ui:Button Width="46"
|
||||
<ui:Button Width="32"
|
||||
Height="32"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
@@ -204,7 +213,7 @@
|
||||
</ui:TitleBar.TrailingContent>
|
||||
</ui:TitleBar>
|
||||
|
||||
<tray:NotifyIcon Grid.Row="0"
|
||||
<tray:NotifyIcon Grid.Row="0" Grid.Column="0"
|
||||
FocusOnLeftClick="False"
|
||||
Icon="pack://application:,,,/Resources/Images/logo.ico"
|
||||
LeftDoubleClick="OnNotifyIconLeftDoubleClick"
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
<ui:FluentWindow x:Class="BetterGenshinImpact.View.Windows.FeedWindow"
|
||||
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Width="400"
|
||||
Height="700"
|
||||
MinWidth="400"
|
||||
MinHeight="250"
|
||||
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
|
||||
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ExtendsContentIntoTitleBar="True"
|
||||
FontFamily="{DynamicResource TextThemeFontFamily}"
|
||||
WindowBackdropType="Mica"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
WindowStyle="SingleBorderWindow"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<ui:TitleBar Name="MyTitleBar" Grid.Row="0" Title="兑换码">
|
||||
<ui:TitleBar.Icon>
|
||||
<ui:ImageIcon Source="pack://application:,,,/Resources/Images/logo.png" />
|
||||
</ui:TitleBar.Icon>
|
||||
</ui:TitleBar>
|
||||
|
||||
<!-- 主要内容区域 -->
|
||||
<Grid Grid.Row="1" Margin="20,10,20,10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题和描述 -->
|
||||
<StackPanel Grid.Row="0" Margin="0,0,0,15">
|
||||
<ui:TextBlock FontSize="24"
|
||||
FontWeight="SemiBold"
|
||||
Text="最新兑换码动态"
|
||||
Margin="0,0,0,5" />
|
||||
<ui:TextBlock FontSize="14"
|
||||
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}"
|
||||
Text="查看最新的国服原神的兑换码,一键自动兑换"
|
||||
TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- 加载状态 -->
|
||||
<StackPanel Grid.Row="1"
|
||||
VerticalAlignment="Top"
|
||||
Height="16"
|
||||
Orientation="Horizontal"
|
||||
Margin="0,0,0,10"
|
||||
Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<ui:ProgressRing Width="16" Height="16" IsIndeterminate="True" Margin="0,0,8,0" />
|
||||
<ui:TextBlock Text="正在加载兑换码..." Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Feed 列表 -->
|
||||
<ScrollViewer Grid.Row="2"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Disabled">
|
||||
<ItemsControl ItemsSource="{Binding FeedItems}" Padding="0,0,16,0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ui:Card Margin="0,0,0,12"
|
||||
Padding="16">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题 -->
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
FontSize="16"
|
||||
FontWeight="SemiBold"
|
||||
Text="{Binding Title}"
|
||||
TextWrapping="Wrap"
|
||||
Margin="0,0,0,8" />
|
||||
|
||||
<!-- 时间与有效期:同一行更紧凑(Valid 为空或 null 时隐藏) -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,0,0,6">
|
||||
<ui:TextBlock FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="{Binding Time}" />
|
||||
<ui:TextBlock FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text=" | "
|
||||
Margin="8,0,8,0">
|
||||
<ui:TextBlock.Style>
|
||||
<Style TargetType="{x:Type ui:TextBlock}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ui:TextBlock.Style>
|
||||
</ui:TextBlock>
|
||||
<ui:TextBlock FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="有效期至">
|
||||
<ui:TextBlock.Style>
|
||||
<Style TargetType="{x:Type ui:TextBlock}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ui:TextBlock.Style>
|
||||
</ui:TextBlock>
|
||||
<ui:TextBlock FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="{Binding Valid}"
|
||||
Margin="4,0,0,0">
|
||||
<ui:TextBlock.Style>
|
||||
<Style TargetType="{x:Type ui:TextBlock}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Valid}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ui:TextBlock.Style>
|
||||
</ui:TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 内容:卡片式展示,增强层次与可读性 -->
|
||||
<StackPanel Grid.Row="2"
|
||||
Visibility="{Binding Content, Converter={StaticResource BooleanToVisibilityRevertConverter}}"
|
||||
Margin="0,0,0,12">
|
||||
<!--<ui:TextBlock Text="内容"
|
||||
FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Margin="0,0,0,6"/>-->
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
|
||||
CornerRadius="{DynamicResource ControlCornerRadius}"
|
||||
BorderThickness="1"
|
||||
Padding="12">
|
||||
<ui:TextBlock FontSize="14"
|
||||
Text="{Binding Content}"
|
||||
TextWrapping="Wrap"
|
||||
LineHeight="20" />
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 兑换码列表:胶囊标签,WrapPanel自动换行 -->
|
||||
<StackPanel Grid.Row="3" Margin="0,0,0,8">
|
||||
<!--<ui:TextBlock Text="兑换码"
|
||||
FontSize="12"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Margin="0,0,0,6"/>-->
|
||||
<ItemsControl ItemsSource="{Binding Codes}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
BorderBrush="{DynamicResource ControlElevationBorderBrush}"
|
||||
CornerRadius="4"
|
||||
BorderThickness="1"
|
||||
Padding="8,4"
|
||||
Margin="0,0,8,8">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<ui:SymbolIcon Symbol="TicketDiagonal24" Margin="0,0,6,0" />
|
||||
<ui:TextBlock FontSize="14"
|
||||
LineHeight="16"
|
||||
FontFamily="Consolas"
|
||||
Text="{Binding}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 标签 -->
|
||||
<StackPanel Grid.Row="4"
|
||||
Orientation="Horizontal"
|
||||
Visibility="{Binding HasTag, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Border CornerRadius="10"
|
||||
Background="{DynamicResource CardBackground}"
|
||||
BorderBrush="{DynamicResource CardBorderBrush}">
|
||||
<ui:TextBlock FontSize="11"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="White"
|
||||
Text="{Binding Tag}" />
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 按钮组 -->
|
||||
<StackPanel Grid.Row="5"
|
||||
Orientation="Horizontal"
|
||||
Margin="0,0,0,8">
|
||||
<ui:Button Content="复制"
|
||||
Appearance="Secondary"
|
||||
FontSize="12"
|
||||
Padding="12,6"
|
||||
Margin="0,0,8,0"
|
||||
Command="{Binding DataContext.CopyItemCodesCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding}" />
|
||||
<ui:Button Content="一键兑换"
|
||||
Appearance="Primary"
|
||||
FontSize="12"
|
||||
Padding="12,6"
|
||||
Command="{Binding DataContext.AutoRedeemItemCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding}" />
|
||||
</StackPanel>
|
||||
|
||||
|
||||
</Grid>
|
||||
</ui:Card>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<Grid Grid.Row="2" Margin="40,10,20,20">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Right">
|
||||
<ui:Button Name="BtnGetLiveCodes"
|
||||
Margin="0,0,10,0"
|
||||
Appearance="Secondary"
|
||||
Content="实时获取前瞻兑换码"
|
||||
Command="{Binding GetLiveRedeemCodesCommand}"
|
||||
Visibility="{Binding IsDisplayBtnGetLiveCodes, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
/>
|
||||
<ui:Button Name="BtnClose"
|
||||
Content="关闭"
|
||||
Click="BtnCloseClick" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Window.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
</Window.Resources>
|
||||
</ui:FluentWindow>
|
||||
@@ -0,0 +1,41 @@
|
||||
using BetterGenshinImpact.Helpers.Ui;
|
||||
using BetterGenshinImpact.ViewModel.Windows;
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace BetterGenshinImpact.View.Windows;
|
||||
|
||||
public partial class FeedWindow
|
||||
{
|
||||
public FeedWindowViewModel ViewModel { get; }
|
||||
|
||||
public FeedWindow(FeedWindowViewModel viewModel)
|
||||
{
|
||||
DataContext = ViewModel = viewModel;
|
||||
InitializeComponent();
|
||||
|
||||
this.Loaded += FeedWindow_Loaded;
|
||||
this.SourceInitialized += FeedWindow_SourceInitialized;
|
||||
}
|
||||
|
||||
public FeedWindow() : this(new FeedWindowViewModel())
|
||||
{
|
||||
}
|
||||
|
||||
private void FeedWindow_SourceInitialized(object? sender, EventArgs e)
|
||||
{
|
||||
// 应用与主窗口相同的背景主题
|
||||
WindowHelper.TryApplySystemBackdrop(this);
|
||||
}
|
||||
|
||||
private void FeedWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 窗口加载完成后拉取远程兑换码数据
|
||||
_ = ViewModel.LoadRemoteDataAsync();
|
||||
}
|
||||
|
||||
private void BtnCloseClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Recognition.OCR;
|
||||
using BetterGenshinImpact.Core.Script;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
@@ -8,6 +8,7 @@ using BetterGenshinImpact.Helpers.Ui;
|
||||
using BetterGenshinImpact.Model;
|
||||
using BetterGenshinImpact.Service.Interface;
|
||||
using BetterGenshinImpact.View;
|
||||
using BetterGenshinImpact.View.Pages;
|
||||
using BetterGenshinImpact.View.Windows;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -28,6 +29,8 @@ using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using BetterGenshinImpact.Helpers.Http;
|
||||
using BetterGenshinImpact.ViewModel.Windows;
|
||||
using Wpf.Ui;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
@@ -37,6 +40,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
private readonly ILogger<MainWindowViewModel> _logger;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly INavigationService _navigationService;
|
||||
public string Title => $"BetterGI · 更好的原神 · {Global.Version}{(RuntimeHelper.IsDebug ? " · Dev" : string.Empty)}";
|
||||
|
||||
[ObservableProperty] private bool _isVisible = true;
|
||||
@@ -46,6 +50,10 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
[ObservableProperty] private WindowBackdropType _currentBackdropType = WindowBackdropType.Auto;
|
||||
|
||||
[ObservableProperty] private bool _isWin11Later = OsVersionHelper.IsWindows11_OrGreater;
|
||||
|
||||
[ObservableProperty] private Brush _redeemCodeButtonForeground = Brushes.White;
|
||||
|
||||
private string? _redeemCodeUpdateNewVersion;
|
||||
|
||||
private bool _firstActivated = true;
|
||||
|
||||
@@ -53,6 +61,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
|
||||
public MainWindowViewModel(INavigationService navigationService, IConfigService configService)
|
||||
{
|
||||
_navigationService = navigationService;
|
||||
_configService = configService;
|
||||
Config = _configService.Get();
|
||||
_logger = App.GetLogger<MainWindowViewModel>();
|
||||
@@ -200,6 +209,19 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnOpenFeed()
|
||||
{
|
||||
if (_redeemCodeUpdateNewVersion != null)
|
||||
{
|
||||
Config.CommonConfig.RedeemCodeFeedsUpdateVersion = _redeemCodeUpdateNewVersion;
|
||||
RedeemCodeButtonForeground = Brushes.White;
|
||||
}
|
||||
|
||||
var feedWindow = new FeedWindow(new FeedWindowViewModel());
|
||||
feedWindow.Show();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task OnLoaded()
|
||||
{
|
||||
@@ -242,6 +264,9 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
|
||||
// 检查更新
|
||||
await App.GetService<IUpdateService>()!.CheckUpdateAsync(new UpdateOption());
|
||||
|
||||
// 检查兑换码更新
|
||||
await CheckRedeemCodeFeedsUpdateAsync();
|
||||
|
||||
// Win11下 BitBlt截图方式不可用,需要关闭窗口优化功能
|
||||
if (OsVersionHelper.IsWindows11_OrGreater && TaskContext.Instance().Config.AutoFixWin11BitBlt)
|
||||
@@ -410,4 +435,34 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
_configService.Save();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CheckRedeemCodeFeedsUpdateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, "https://cnb.cool/bettergi/genshin-redeem-code/-/git/raw/main/update_time.txt");
|
||||
var response = await HttpClientFactory.GetCommonSendClient().SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var txt = await response.Content.ReadAsStringAsync();
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(txt))
|
||||
{
|
||||
if (long.TryParse(txt, out long v2)
|
||||
&& long.TryParse(Config.CommonConfig.RedeemCodeFeedsUpdateVersion, out long v1))
|
||||
{
|
||||
if (v2 > v1)
|
||||
{
|
||||
RedeemCodeButtonForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1E9BFA"));
|
||||
_redeemCodeUpdateNewVersion = txt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogDebug(ex, $"获取兑换码是否存在更新失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
using BetterGenshinImpact.ViewModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.UseRedeemCode;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using BetterGenshinImpact.Helpers.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Windows;
|
||||
|
||||
public partial class FeedWindowViewModel : ViewModel
|
||||
{
|
||||
[ObservableProperty] private ObservableCollection<FeedItem> _feedItems = new();
|
||||
[ObservableProperty] private bool _isLoading;
|
||||
[ObservableProperty] private bool _isDisplayBtnGetLiveCodes;
|
||||
|
||||
private readonly HttpClient _httpClient = HttpClientFactory.GetCommonSendClient();
|
||||
private const string CodesJsonUrl = "https://cnb.cool/bettergi/genshin-redeem-code/-/git/raw/main/codes.json";
|
||||
|
||||
public FeedWindowViewModel()
|
||||
{
|
||||
IsDisplayBtnGetLiveCodes = GamePreviewLiveDateCalculator.IsWithinPreviewRange(DateTime.Now);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task GetLiveRedeemCodes()
|
||||
{
|
||||
IsLoading = true;
|
||||
try
|
||||
{
|
||||
var getter = new GetLiveRedeemCode();
|
||||
var codeList = await getter.GetCodeMsgAsync();
|
||||
|
||||
if (codeList.Count == 0)
|
||||
{
|
||||
Toast.Warning("暂无前瞻兑换码信息");
|
||||
return;
|
||||
}
|
||||
|
||||
var displayItems = codeList
|
||||
.Select(c => string.IsNullOrWhiteSpace(c.Items) ? null : c.Items)
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s))
|
||||
.ToList();
|
||||
|
||||
var item = new FeedItem
|
||||
{
|
||||
Title = "【实时获取】前瞻直播兑换码",
|
||||
Content = displayItems.Count > 0 ? string.Join("\n", displayItems) : string.Empty,
|
||||
Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
|
||||
Codes = codeList.Select(c => c.Code).ToList()
|
||||
};
|
||||
|
||||
// 插入到列表顶部,方便查看
|
||||
if (FeedItems.Count > 0 && FeedItems[0].Title == item.Title)
|
||||
{
|
||||
// 如果已经存在相同标题的项,则更新内容和时间
|
||||
FeedItems[0].Content = item.Content;
|
||||
FeedItems[0].Time = item.Time;
|
||||
FeedItems[0].Codes = item.Codes;
|
||||
}
|
||||
else
|
||||
{
|
||||
FeedItems.Insert(0, item);
|
||||
}
|
||||
|
||||
|
||||
Toast.Success("已实时获取前瞻兑换码");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"获取前瞻兑换码失败: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task Refresh()
|
||||
{
|
||||
await LoadRemoteDataAsync();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CopyItemCodes(FeedItem item)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (item?.Codes != null && item.Codes.Any())
|
||||
{
|
||||
var codes = string.Join("\n", item.Codes);
|
||||
UIDispatcherHelper.Invoke(() => Clipboard.SetDataObject(codes));
|
||||
RedeemCodeManager.AddNotDetectClipboardText(codes);
|
||||
Toast.Information("兑换码已复制到剪贴板");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"复制兑换码失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task AutoRedeemItem(FeedItem item)
|
||||
{
|
||||
if (item?.Codes != null && item.Codes.Count != 0)
|
||||
{
|
||||
await new TaskRunner().RunSoloTaskAsync(new UseRedemptionCodeTask(item.Codes));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LoadRemoteDataAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
try
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, CodesJsonUrl);
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var items = JsonConvert.DeserializeObject<List<FeedItem>>(json) ?? [];
|
||||
|
||||
FeedItems.Clear();
|
||||
foreach (var feed in items)
|
||||
{
|
||||
// 若存在标签文本,设置 HasTag
|
||||
feed.HasTag = !string.IsNullOrWhiteSpace(feed.Tag);
|
||||
FeedItems.Add(feed);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"获取兑换码失败: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class FeedItem : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private string _title = string.Empty;
|
||||
|
||||
[ObservableProperty] private string _content = string.Empty;
|
||||
|
||||
[ObservableProperty] private string _time = string.Empty;
|
||||
|
||||
[ObservableProperty] private string _tag = string.Empty;
|
||||
|
||||
[ObservableProperty] private bool _hasTag = false;
|
||||
|
||||
[ObservableProperty] private List<string> _codes = new();
|
||||
|
||||
[ObservableProperty] private string _valid = string.Empty;
|
||||
}
|
||||
Reference in new issue
Block a user