Skip to content

Commit

Permalink
play time statistic & last 7 days trend chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 4, 2025
1 parent 1926d6d commit 268b5e5
Show file tree
Hide file tree
Showing 14 changed files with 1,131 additions and 72 deletions.
18 changes: 18 additions & 0 deletions src/Starward.Language/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1671,4 +1671,10 @@ Do you accept the risk and continue to use it?</value>
<data name="SettingPage_ForABetterExperiencePleaseEnableTheFollowingFeaturesInSystemSettings" xml:space="preserve">
<value>For a better experience, please enable the following features in system settings.</value>
</data>
<data name="PlayTimeButton_Last7Days" xml:space="preserve">
<value>Last 7 Days</value>
</data>
<data name="PlayTimeButton_LastStartup" xml:space="preserve">
<value>Last Startup</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/Starward.Language/Lang.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1669,4 +1669,10 @@
<data name="SettingPage_ForABetterExperiencePleaseEnableTheFollowingFeaturesInSystemSettings" xml:space="preserve">
<value>为了更好的体验,请在系统设置中启用以下功能。</value>
</data>
<data name="PlayTimeButton_Last7Days" xml:space="preserve">
<value>最近 7 天</value>
</data>
<data name="PlayTimeButton_LastStartup" xml:space="preserve">
<value>上次启动</value>
</data>
</root>
1 change: 1 addition & 0 deletions src/Starward/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
</Style>

<Style BasedOn="{StaticResource DefaultFlyoutPresenterStyle}" TargetType="FlyoutPresenter">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="{ThemeResource CustomAcrylicBrush}" />
</Style>

Expand Down
114 changes: 63 additions & 51 deletions src/Starward/Features/GameLauncher/GameLauncherPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:local="using:Starward.Features.GameLauncher"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sf="using:Starward.Frameworks"
xmlns:sfp="using:Starward.Features.PlayTime"
x:DefaultBindMode="OneWay"
mc:Ignorable="d">

Expand Down Expand Up @@ -54,57 +55,68 @@



<!-- 右下角启动游戏 -->
<Grid Margin="0,0,40,0"
HorizontalAlignment="Right"
VerticalAlignment="Bottom">
<Grid.Resources>
<cu:AttachedDropShadow x:Key="TextShadow"
BlurRadius="8"
CastTo="{x:Bind Border_TextShadowTarget}"
Offset="0,2" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="44" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>

<local:StartGameButton HorizontalAlignment="Right"
CanExecute="{x:Bind StartGameButtonCanExecute}"
Command="{x:Bind ClickStartGameButtonCommand}"
SettingCommand="{x:Bind OpenGameLauncherSettingDialogCommand}"
State="{x:Bind GameState}" />

<Border x:Name="Border_TextShadowTarget" Grid.Row="1" />

<!-- 可移动存储设备未连接 -->
<TextBlock Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
cu:Effects.Shadow="{StaticResource TextShadow}"
FontSize="12"
Visibility="{x:Bind IsInstallPathRemovableTipEnabled}">
<Run Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind lang:Lang.GameLauncherPage_RemovableStorageDeviceNotConnected}" />
<Hyperlink Click="Hyperlink_LocateGame_Click" UnderlineStyle="None">
<Run Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}" Text="{x:Bind lang:Lang.GameLauncherPage_Relocate}" />
</Hyperlink>
</TextBlock>

<!-- 定位游戏 -->
<TextBlock Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
cu:Effects.Shadow="{StaticResource TextShadow}"
FontSize="12"
Visibility="{x:Bind InstalledLocateGameEnabled}">
<Run Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind lang:Lang.InstallGameDialog_Installed}" />
<Hyperlink Click="Hyperlink_LocateGame_Click" UnderlineStyle="None">
<Run Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}" Text="{x:Bind lang:Lang.InstallGameDialog_LocateGame}" />
</Hyperlink>
</TextBlock>

</Grid>

<!-- 右下角按键 -->
<StackPanel Margin="0,0,40,40"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Orientation="Horizontal"
Spacing="12">


<!-- 游戏时间 -->
<sfp:PlayTimeButton CurrentGameBiz="{x:Bind CurrentGameBiz}" />


<!-- 启动游戏 -->
<Grid Margin="0,0,0,-40">
<Grid.Resources>
<cu:AttachedDropShadow x:Key="TextShadow"
BlurRadius="8"
CastTo="{x:Bind Border_TextShadowTarget}"
Offset="0,2" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="44" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>

<local:StartGameButton HorizontalAlignment="Right"
CanExecute="{x:Bind StartGameButtonCanExecute}"
Command="{x:Bind ClickStartGameButtonCommand}"
SettingCommand="{x:Bind OpenGameLauncherSettingDialogCommand}"
State="{x:Bind GameState}" />

<Border x:Name="Border_TextShadowTarget" Grid.Row="1" />

<!-- 可移动存储设备未连接 -->
<TextBlock Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
cu:Effects.Shadow="{StaticResource TextShadow}"
FontSize="12"
Visibility="{x:Bind IsInstallPathRemovableTipEnabled}">
<Run Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind lang:Lang.GameLauncherPage_RemovableStorageDeviceNotConnected}" />
<Hyperlink Click="Hyperlink_LocateGame_Click" UnderlineStyle="None">
<Run Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}" Text="{x:Bind lang:Lang.GameLauncherPage_Relocate}" />
</Hyperlink>
</TextBlock>

<!-- 定位游戏 -->
<TextBlock Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
cu:Effects.Shadow="{StaticResource TextShadow}"
FontSize="12"
Visibility="{x:Bind InstalledLocateGameEnabled}">
<Run Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind lang:Lang.InstallGameDialog_Installed}" />
<Hyperlink Click="Hyperlink_LocateGame_Click" UnderlineStyle="None">
<Run Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}" Text="{x:Bind lang:Lang.InstallGameDialog_LocateGame}" />
</Hyperlink>
</TextBlock>

</Grid>

</StackPanel>


</Grid>
Expand Down
37 changes: 19 additions & 18 deletions src/Starward/Features/GameLauncher/GameLauncherService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
using Starward.Core;
using Starward.Core.HoYoPlay;
using Starward.Features.HoYoPlay;
using Starward.Features.PlayTime;
using Starward.Frameworks;
using Starward.Helpers;
using System;
using System.ComponentModel;
using System.Diagnostics;
Expand All @@ -24,13 +23,14 @@ internal class GameLauncherService

private readonly HoYoPlayService _hoYoPlayService;

private readonly PlayTimeService _playTimeService;



public GameLauncherService(ILogger<GameLauncherService> logger, HoYoPlayService hoYoPlayService)
public GameLauncherService(ILogger<GameLauncherService> logger, HoYoPlayService hoYoPlayService, PlayTimeService playTimeService)
{
_logger = logger;
_hoYoPlayService = hoYoPlayService;
_playTimeService = playTimeService;
}


Expand Down Expand Up @@ -211,11 +211,13 @@ public async Task<bool> IsGameExeExistsAsync(GameId gameId, string? installPath
exe = e;
}
}
bool thirdPartyTool = false;
if (string.IsNullOrWhiteSpace(exe) && AppSetting.GetEnableThirdPartyTool(gameId.GameBiz))
{
exe = AppSetting.GetThirdPartyToolPath(gameId.GameBiz);
if (File.Exists(exe))
{
thirdPartyTool = true;
verb = Path.GetExtension(exe) is ".exe" or ".bat" ? "runas" : "";
}
else
Expand Down Expand Up @@ -247,7 +249,19 @@ public async Task<bool> IsGameExeExistsAsync(GameId gameId, string? installPath
Verb = verb,
WorkingDirectory = Path.GetDirectoryName(exe),
};
return Process.Start(info);
Process? process = Process.Start(info);
if (process != null)
{
if (thirdPartyTool)
{
return await _playTimeService.StartProcessToLogAsync(gameId);
}
else
{
await _playTimeService.StartProcessToLogAsync(gameId, process.Id);
return process;
}
}
}
catch (Win32Exception ex) when (ex.NativeErrorCode == ERROR_CANCELLED)
{
Expand All @@ -259,19 +273,6 @@ public async Task<bool> IsGameExeExistsAsync(GameId gameId, string? installPath



/// <summary>
/// 选择游戏安装目录
/// </summary>
/// <param name="xamlRoot"></param>
/// <returns></returns>
public async Task<string?> LocateGameInstallFolderAsync(XamlRoot xamlRoot)
{
// 判断是否为可移动存储设备,使用 DriveHelper.IsDeviceRemovableOrOnUSB
string? folder = await FileDialogHelper.PickFolderAsync(xamlRoot);
return Directory.Exists(folder) ? folder : null;
}





Expand Down
Loading

0 comments on commit 268b5e5

Please sign in to comment.