Compare commits

..

6 Commits

Author SHA1 Message Date
qhy040404
75c25cec53 show warning if discord is not available 2024-02-17 14:00:23 +08:00
qhy040404
22251ca937 fix #1400 2024-02-17 11:28:36 +08:00
qhy040404
57c9531db8 fix #1365 again 2024-02-16 22:19:55 +08:00
qhy040404
6594d9032d fix wrong setting state 2024-02-12 11:29:25 +08:00
DismissedLight
ae1b452697 minor fix 2024-02-09 15:40:48 +08:00
DismissedLight
bc3df782e4 Merge pull request #1380 from DGP-Studio/fix/1379
fix #1379
2024-02-09 14:16:39 +08:00
7 changed files with 81 additions and 30 deletions

View File

@@ -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;

View File

@@ -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;
}
}
}
}

View File

@@ -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);
}

View File

@@ -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">

View File

@@ -221,7 +221,7 @@
<shct:DescriptionTextBlock
Margin="0,8,0,16"
Description="{Binding Description}"
Style="{StaticResource CaptionTextBlockStyle}"/>
TextStyle="{StaticResource CaptionTextBlockStyle}"/>
</StackPanel>
</Grid>
</DataTemplate>

View File

@@ -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

View File

@@ -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));
}
}
}