code style

This commit is contained in:
Lightczx
2023-12-27 13:31:21 +08:00
parent b106fe4729
commit 4001cc7051
7 changed files with 140 additions and 111 deletions

View File

@@ -93,6 +93,10 @@ internal static class AvatarIds
public static readonly AvatarId Neuvillette = 10000087;
public static readonly AvatarId Charlotte = 10000088;
public static readonly AvatarId Furina = 10000089;
public static readonly AvatarId Chevreuse = 10000090;
public static readonly AvatarId Navia = 10000091;
public static readonly AvatarId Gaming = 10000092;
public static readonly AvatarId Xianyun = 10000093;
/// <summary>
/// 检查该角色是否为主角

View File

@@ -120,6 +120,12 @@
<data name="AppDevNameAndVersion" xml:space="preserve">
<value>胡桃 Dev {0}</value>
</data>
<data name="AppElevatedDevNameAndVersion" xml:space="preserve">
<value>胡桃Dev {0} [管理员]</value>
</data>
<data name="AppElevatedNameAndVersion" xml:space="preserve">
<value>胡桃 {0} [管理员]</value>
</data>
<data name="AppName" xml:space="preserve">
<value>胡桃</value>
</data>
@@ -2280,7 +2286,7 @@
<value>设备 IP</value>
</data>
<data name="ViewPageSettingElevatedModeDescription" xml:space="preserve">
<value>管理员模式会影响部分功能的可用性</value>
<value>管理员模式会影响部分功能的可用性与行为</value>
</data>
<data name="ViewPageSettingElevatedModeHeader" xml:space="preserve">
<value>管理员模式</value>

View File

@@ -23,7 +23,10 @@
<ScrollViewer shch:ScrollViewerHelper.LeftPanelMaxWidth="800" Style="{StaticResource TwoPanelScrollViewerStyle}">
<shch:ScrollViewerHelper.RightPanel>
<StackPanel Width="360" Margin="0,16,16,16">
<StackPanel
Width="360"
Margin="0,16,16,16"
Spacing="{StaticResource SettingsCardSpacing}">
<Border cw:Effects.Shadow="{ThemeResource CompatCardShadow}">
<Grid Style="{ThemeResource GridCardStyle}">
<Border
@@ -83,6 +86,27 @@
</Grid>
</Grid>
</Border>
<cwc:SettingsExpander
Header="{shcm:ResourceString Name=ViewPageSettingElevatedModeHeader}"
HeaderIcon="{shcm:FontIcon Glyph=&#xE7EF;}"
IsExpanded="True">
<cwc:SettingsExpander.Items>
<cwc:SettingsCard
Command="{Binding RestartAsElevatedCommand}"
Description="{shcm:ResourceString Name=ViewPageSettingElevatedModeDescription}"
Header="{shcm:ResourceString Name=ViewPageSettingElevatedModeRestartAction}"
IsClickEnabled="True"
IsEnabled="{Binding HutaoOptions.IsElevated, Converter={StaticResource BoolNegationConverter}}"/>
<cwc:SettingsCard
ActionIconToolTip="{shcm:ResourceString Name=ViewPageSettingCreateDesktopShortcutAction}"
Command="{Binding CreateDesktopShortcutCommand}"
Description="{shcm:ResourceString Name=ViewPageSettingCreateDesktopShortcutDescription}"
Header="{shcm:ResourceString Name=ViewPageSettingCreateDesktopShortcutHeader}"
IsClickEnabled="True"/>
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>
</StackPanel>
</shch:ScrollViewerHelper.RightPanel>
<Grid Padding="16" HorizontalAlignment="Left">
@@ -181,27 +205,6 @@
HeaderIcon="{shcm:FontIcon Glyph=&#xE776;}"
IsClickEnabled="True"/>
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageSettingElevatedModeHeader}"/>
<cwc:SettingsExpander
Description="{shcm:ResourceString Name=ViewPageSettingElevatedModeDescription}"
Header="{Binding ElevatedModeHeader}"
HeaderIcon="{shcm:FontIcon Glyph=&#xE7EF;}"
IsExpanded="True">
<Button
Command="{Binding RestartAsElevatedCommand}"
Content="{shcm:ResourceString Name=ViewPageSettingElevatedModeRestartAction}"
IsEnabled="{Binding HutaoOptions.IsElevated, Converter={StaticResource BoolNegationConverter}}"
Style="{ThemeResource SettingButtonStyle}"/>
<cwc:SettingsExpander.Items>
<cwc:SettingsCard
ActionIconToolTip="{shcm:ResourceString Name=ViewPageSettingCreateDesktopShortcutAction}"
Command="{Binding CreateDesktopShortcutCommand}"
Description="{shcm:ResourceString Name=ViewPageSettingCreateDesktopShortcutDescription}"
Header="{shcm:ResourceString Name=ViewPageSettingCreateDesktopShortcutHeader}"
IsClickEnabled="True"/>
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageSettingApperanceHeader}"/>
<cwc:SettingsCard
Description="{shcm:ResourceString Name=ViewPageSettingApperanceLanguageDescription}"

View File

@@ -4,10 +4,19 @@
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:mxi="using:Microsoft.Xaml.Interactivity"
xmlns:shcb="using:Snap.Hutao.Control.Behavior"
xmlns:shcm="using:Snap.Hutao.Control.Markup"
xmlns:shv="using:Snap.Hutao.ViewModel"
Height="44"
VerticalAlignment="Top"
d:DataContext="{d:DesignInstance shv:TitleViewModel}"
mc:Ignorable="d">
<mxi:Interaction.Behaviors>
<shcb:InvokeCommandOnLoadedBehavior Command="{Binding OpenUICommand}"/>
</mxi:Interaction.Behaviors>
<Grid x:Name="DragableGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
@@ -19,7 +28,7 @@
Margin="4,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind Title}"
Text="{Binding Title}"
TextWrapping="NoWrap"/>
<StackPanel
@@ -30,12 +39,12 @@
<StackPanel
Orientation="Horizontal"
Spacing="6"
Visibility="{x:Bind RuntimeOptions.IsElevated, Converter={StaticResource BoolToVisibilityConverter}}">
Visibility="{Binding RuntimeOptions.IsElevated, Converter={StaticResource BoolToVisibilityConverter}}">
<ToggleButton
VerticalAlignment="Center"
IsChecked="{x:Bind HotKeyOptions.IsMouseClickRepeatForeverOn, Mode=OneWay}"
IsChecked="{Binding HotKeyOptions.IsMouseClickRepeatForeverOn, Mode=OneWay}"
IsHitTestVisible="False"
Visibility="{x:Bind HotKeyOptions.MouseClickRepeatForeverKeyCombination.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
Visibility="{Binding HotKeyOptions.MouseClickRepeatForeverKeyCombination.IsEnabled, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
@@ -49,7 +58,7 @@
Grid.Column="1"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind HotKeyOptions.MouseClickRepeatForeverKeyCombination.DisplayName, Mode=OneWay}"/>
Text="{Binding HotKeyOptions.MouseClickRepeatForeverKeyCombination.DisplayName, Mode=OneWay}"/>
</Grid>
</ToggleButton>
</StackPanel>
@@ -59,7 +68,7 @@
Padding="12,0"
ColumnSpacing="12"
Style="{ThemeResource GridCardStyle}"
Visibility="{x:Bind UpdateStatus, Converter={StaticResource EmptyObjectToVisibilityConverter}, Mode=OneWay}">
Visibility="{Binding UpdateStatus, Converter={StaticResource EmptyObjectToVisibilityConverter}, Mode=OneWay}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
@@ -71,17 +80,17 @@
HorizontalAlignment="Stretch"
Background="Transparent"
CornerRadius="{ThemeResource ControlCornerRadius}"
Maximum="{x:Bind UpdateStatus.TotalBytes, Mode=OneWay}"
Maximum="{Binding UpdateStatus.TotalBytes, Mode=OneWay}"
Opacity="{ThemeResource LargeBackgroundProgressBarOpacity}"
Value="{x:Bind UpdateStatus.BytesRead, Mode=OneWay}"/>
Value="{Binding UpdateStatus.BytesRead, Mode=OneWay}"/>
<TextBlock
Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind UpdateStatus.ProgressDescription, Mode=OneWay}"/>
Text="{Binding UpdateStatus.ProgressDescription, Mode=OneWay}"/>
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Text="{x:Bind UpdateStatus.VersionDescription, Mode=OneWay}"/>
Text="{Binding UpdateStatus.VersionDescription, Mode=OneWay}"/>
</Grid>
</StackPanel>
</Grid>

View File

@@ -4,12 +4,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Core;
using Snap.Hutao.Core.Windowing.HotKey;
using Snap.Hutao.Factory.ContentDialog;
using Snap.Hutao.Factory.Progress;
using Snap.Hutao.Service.Abstraction;
using Snap.Hutao.Service.Update;
using Snap.Hutao.ViewModel;
namespace Snap.Hutao.View;
@@ -20,75 +15,14 @@ namespace Snap.Hutao.View;
[INotifyPropertyChanged]
internal sealed partial class TitleView : UserControl
{
private readonly CancellationTokenSource checkUpdateTaskCancellationTokenSource = new();
private UpdateStatus? updateStatus;
public TitleView()
{
Loaded += OnTitleViewLoaded;
Unloaded += OnTitleViewUnloaded;
DataContext = Ioc.Default.GetRequiredService<TitleViewModel>();
InitializeComponent();
}
public string Title
{
[SuppressMessage("", "IDE0027")]
get
{
#if DEBUG
return SH.FormatAppDevNameAndVersion(RuntimeOptions.Version);
#else
return SH.FormatAppNameAndVersion(RuntimeOptions.Version);
#endif
}
}
public FrameworkElement DragArea
{
get => DragableGrid;
}
public RuntimeOptions RuntimeOptions { get; } = Ioc.Default.GetRequiredService<RuntimeOptions>();
public HotKeyOptions HotKeyOptions { get; } = Ioc.Default.GetRequiredService<HotKeyOptions>();
public UpdateStatus? UpdateStatus { get => updateStatus; set => SetProperty(ref updateStatus, value); }
private void OnTitleViewLoaded(object sender, RoutedEventArgs e)
{
DoCheckUpdateAsync(checkUpdateTaskCancellationTokenSource.Token).SafeForget();
Loaded -= OnTitleViewLoaded;
}
private void OnTitleViewUnloaded(object sender, RoutedEventArgs e)
{
checkUpdateTaskCancellationTokenSource.Cancel();
Unloaded -= OnTitleViewUnloaded;
}
private async ValueTask DoCheckUpdateAsync(CancellationToken token)
{
IServiceProvider serviceProvider = Ioc.Default;
IUpdateService updateService = serviceProvider.GetRequiredService<IUpdateService>();
IProgressFactory progressFactory = serviceProvider.GetRequiredService<IProgressFactory>();
IProgress<UpdateStatus> progress = progressFactory.CreateForMainThread<UpdateStatus>(status => UpdateStatus = status);
if (await updateService.CheckForUpdateAndDownloadAsync(progress, token).ConfigureAwait(false))
{
ContentDialogResult result = await serviceProvider
.GetRequiredService<IContentDialogFactory>()
.CreateForConfirmCancelAsync(
SH.FormatViewTitileUpdatePackageReadyTitle(UpdateStatus?.Version),
SH.ViewTitileUpdatePackageReadyContent,
ContentDialogButton.Primary)
.ConfigureAwait(false);
if (result == ContentDialogResult.Primary)
{
await updateService.LaunchUpdaterAsync().ConfigureAwait(false);
}
}
await serviceProvider.GetRequiredService<ITaskContext>().SwitchToMainThreadAsync();
UpdateStatus = null;
}
}

View File

@@ -131,13 +131,6 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
set => LocalSetting.Set(SettingKeys.IsAllocConsoleDebugModeEnabled, value);
}
public string ElevatedModeHeader
{
get => HutaoOptions.IsElevated
? SH.ViewModelSettingRunningInElevatedMode
: SH.ViewModelSettingNotRunningInElevatedMode;
}
protected override async ValueTask<bool> InitializeUIAsync()
{
CacheFolderView = new(taskContext, runtimeOptions.LocalCache);
@@ -293,14 +286,13 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
[Command("RestartAsElevatedCommand")]
private void RestartAsElevated()
{
ProcessStartInfo info = new()
Process.Start(new ProcessStartInfo()
{
FileName = $"shell:AppsFolder\\{runtimeOptions.FamilyName}!App",
UseShellExecute = true,
Verb = "runas",
};
});
Process.Start(info);
Process.GetCurrentProcess().Kill();
}
}

View File

@@ -0,0 +1,81 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Core;
using Snap.Hutao.Core.Windowing.HotKey;
using Snap.Hutao.Factory.ContentDialog;
using Snap.Hutao.Factory.Progress;
using Snap.Hutao.Service.Abstraction;
using Snap.Hutao.Service.Update;
using System.Globalization;
using System.Text;
namespace Snap.Hutao.ViewModel;
[ConstructorGenerated]
[Injection(InjectAs.Singleton)]
internal sealed partial class TitleViewModel : Abstraction.ViewModel
{
private readonly IContentDialogFactory contentDialogFactory;
private readonly IProgressFactory progressFactory;
private readonly RuntimeOptions runtimeOptions;
private readonly HotKeyOptions hotKeyOptions;
private readonly IUpdateService updateService;
private readonly ITaskContext taskContext;
private UpdateStatus? updateStatus;
public RuntimeOptions RuntimeOptions { get => runtimeOptions; }
public HotKeyOptions HotKeyOptions { get => hotKeyOptions; }
public string Title
{
[SuppressMessage("", "IDE0027")]
get
{
string name = new StringBuilder()
.Append("App")
.AppendIf(runtimeOptions.IsElevated, "Elevated")
#if DEBUG
.Append("Dev")
#endif
.Append("NameAndVersion")
.ToString();
string? format = SH.GetString(CultureInfo.CurrentCulture, name);
ArgumentException.ThrowIfNullOrEmpty(format);
return string.Format(CultureInfo.CurrentCulture, format, runtimeOptions.Version);
}
}
public UpdateStatus? UpdateStatus { get => updateStatus; set => SetProperty(ref updateStatus, value); }
protected override async ValueTask<bool> InitializeUIAsync()
{
await DoCheckUpdateAsync().ConfigureAwait(false);
return true;
}
private async ValueTask DoCheckUpdateAsync()
{
IProgress<UpdateStatus> progress = progressFactory.CreateForMainThread<UpdateStatus>(status => UpdateStatus = status);
if (await updateService.CheckForUpdateAndDownloadAsync(progress).ConfigureAwait(false))
{
ContentDialogResult result = await contentDialogFactory
.CreateForConfirmCancelAsync(
SH.FormatViewTitileUpdatePackageReadyTitle(UpdateStatus?.Version),
SH.ViewTitileUpdatePackageReadyContent,
ContentDialogButton.Primary)
.ConfigureAwait(false);
if (result == ContentDialogResult.Primary)
{
await updateService.LaunchUpdaterAsync().ConfigureAwait(false);
}
}
await taskContext.SwitchToMainThreadAsync();
UpdateStatus = null;
}
}