mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75c25cec53 | ||
|
|
22251ca937 | ||
|
|
57c9531db8 | ||
|
|
6594d9032d | ||
|
|
ae1b452697 | ||
|
|
bc3df782e4 |
@@ -132,13 +132,6 @@ internal static class DiscordController
|
||||
return;
|
||||
}
|
||||
|
||||
// Actually requires a discord client to be running on Windows platform.
|
||||
// If not, the following creation code will throw.
|
||||
if (System.Diagnostics.Process.GetProcessesByName("Discord").Length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (SyncRoot)
|
||||
{
|
||||
DiscordCreateParams @params = default;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Service.Notification;
|
||||
|
||||
namespace Snap.Hutao.Service.Discord;
|
||||
|
||||
@@ -9,22 +10,77 @@ namespace Snap.Hutao.Service.Discord;
|
||||
[Injection(InjectAs.Singleton, typeof(IDiscordService))]
|
||||
internal sealed partial class DiscordService : IDiscordService, IDisposable
|
||||
{
|
||||
private readonly IInfoBarService infoBarService;
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
|
||||
private bool isInitialized;
|
||||
|
||||
public async ValueTask SetPlayingActivityAsync(bool isOversea)
|
||||
{
|
||||
_ = isOversea
|
||||
? await DiscordController.SetPlayingGenshinImpactAsync().ConfigureAwait(false)
|
||||
: await DiscordController.SetPlayingYuanShenAsync().ConfigureAwait(false);
|
||||
if (CheckDiscordStatus())
|
||||
{
|
||||
_ = isOversea
|
||||
? await DiscordController.SetPlayingGenshinImpactAsync().ConfigureAwait(false)
|
||||
: await DiscordController.SetPlayingYuanShenAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask SetNormalActivityAsync()
|
||||
{
|
||||
_ = await DiscordController.SetDefaultActivityAsync(runtimeOptions.AppLaunchTime).ConfigureAwait(false);
|
||||
if (CheckDiscordStatus())
|
||||
{
|
||||
_ = await DiscordController.SetDefaultActivityAsync(runtimeOptions.AppLaunchTime).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DiscordController.Stop();
|
||||
}
|
||||
|
||||
private bool CheckDiscordStatus()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Actually requires a discord client to be running on Windows platform.
|
||||
// If not, discord core creation code will throw.
|
||||
System.Diagnostics.Process[] discordProcesses = System.Diagnostics.Process.GetProcessesByName("Discord");
|
||||
|
||||
if (discordProcesses.Length <= 0)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
infoBarService.Warning("Discord 未运行,将无法设置 Discord Activity 状态。");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (System.Diagnostics.Process process in discordProcesses)
|
||||
{
|
||||
try
|
||||
{
|
||||
_ = process.Handle;
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
infoBarService.Warning("权限不足,将无法设置 Discord Activity 状态。");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,7 @@ internal sealed class LaunchOptions : DbStoreOptions
|
||||
get => selectedAspectRatio;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref selectedAspectRatio, value) && value is AspectRatio aspectRatio)
|
||||
if (SetProperty(ref selectedAspectRatio, value) && value is { } aspectRatio)
|
||||
{
|
||||
(ScreenWidth, ScreenHeight) = ((int)aspectRatio.Width, (int)aspectRatio.Height);
|
||||
}
|
||||
|
||||
@@ -149,20 +149,22 @@
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="AnnouncementPivotItemContentTemplate">
|
||||
<ItemsRepeater
|
||||
Margin="16,16,16,16"
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemTemplate="{StaticResource AnnouncementTemplate}"
|
||||
ItemsSource="{Binding List}">
|
||||
<ItemsRepeater.Layout>
|
||||
<UniformGridLayout
|
||||
ItemsJustification="Start"
|
||||
ItemsStretch="Fill"
|
||||
MinColumnSpacing="12"
|
||||
MinItemWidth="300"
|
||||
MinRowSpacing="12"/>
|
||||
</ItemsRepeater.Layout>
|
||||
</ItemsRepeater>
|
||||
<ScrollViewer>
|
||||
<ItemsRepeater
|
||||
Margin="16,16,16,16"
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemTemplate="{StaticResource AnnouncementTemplate}"
|
||||
ItemsSource="{Binding List}">
|
||||
<ItemsRepeater.Layout>
|
||||
<UniformGridLayout
|
||||
ItemsJustification="Start"
|
||||
ItemsStretch="Fill"
|
||||
MinColumnSpacing="12"
|
||||
MinItemWidth="300"
|
||||
MinRowSpacing="12"/>
|
||||
</ItemsRepeater.Layout>
|
||||
</ItemsRepeater>
|
||||
</ScrollViewer>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="HutaoAnnouncementTemplate">
|
||||
|
||||
@@ -221,7 +221,7 @@
|
||||
<shct:DescriptionTextBlock
|
||||
Margin="0,8,0,16"
|
||||
Description="{Binding Description}"
|
||||
Style="{StaticResource CaptionTextBlockStyle}"/>
|
||||
TextStyle="{StaticResource CaptionTextBlockStyle}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
@@ -291,7 +291,7 @@
|
||||
ProfilePicture="{Binding UserInfo.AvatarUrl, Mode=OneWay}"/>
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="10,0,0,0"
|
||||
Margin="12,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding UserInfo.Nickname}"/>
|
||||
<TextBlock
|
||||
|
||||
@@ -167,13 +167,13 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
if (await dialog.ConfirmAsync(SH.ViewPageSettingIsAdvancedLaunchOptionsEnabledHeader).ConfigureAwait(true))
|
||||
{
|
||||
launchOptions.IsAdvancedLaunchOptionsEnabled = true;
|
||||
OnPropertyChanged(nameof(IsAllocConsoleDebugModeEnabled));
|
||||
OnPropertyChanged(nameof(IsAdvancedLaunchOptionsEnabled));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
launchOptions.IsAdvancedLaunchOptionsEnabled = false;
|
||||
OnPropertyChanged(nameof(IsAllocConsoleDebugModeEnabled));
|
||||
OnPropertyChanged(nameof(IsAdvancedLaunchOptionsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user