diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Discord/DiscordService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Discord/DiscordService.cs index c977e243..66ff3517 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Discord/DiscordService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Discord/DiscordService.cs @@ -41,39 +41,33 @@ internal sealed partial class DiscordService : IDiscordService, IDisposable private bool IsSupported() { - try - { - // Actually requires a discord client to be running on Windows platform. - // If not, discord core creation code will throw. - Process[] discordProcesses = Process.GetProcessesByName("Discord"); + // Actually requires a discord client to be running on Windows platform. + // If not, discord core creation code will throw. + Process[] discordProcesses = Process.GetProcessesByName("Discord"); - if (discordProcesses.Length <= 0) + if (discordProcesses.Length <= 0) + { + return false; + } + + foreach (Process process in discordProcesses) + { + try { + _ = process.Handle; + } + catch (Exception) + { + if (!isInitialized) + { + isInitialized = true; + infoBarService.Warning(SH.ServiceDiscordActivityElevationRequiredHint); + } + return false; } - - foreach (Process process in discordProcesses) - { - try - { - _ = process.Handle; - } - catch (Exception) - { - if (!isInitialized) - { - infoBarService.Warning(SH.ServiceDiscordActivityElevationRequiredHint); - } - - return false; - } - } - - return true; - } - finally - { - isInitialized = true; } + + return true; } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionBetterGenshinImpactAutomationHandlder.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionBetterGenshinImpactAutomationHandlder.cs index 0a25990d..00dd94c2 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionBetterGenshinImpactAutomationHandlder.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionBetterGenshinImpactAutomationHandlder.cs @@ -23,8 +23,15 @@ internal sealed class LaunchExecutionBetterGenshinImpactAutomationHandlder : ILa Uri betterGenshinImpactUri = "bettergi://start".ToUri(); if (await Launcher.QueryUriSupportAsync(betterGenshinImpactUri, LaunchQuerySupportType.Uri) is LaunchQuerySupportStatus.Available) { - context.Logger.LogInformation("Waiting game window to be ready"); - context.Process.WaitForInputIdle(); + try + { + context.Logger.LogInformation("Waiting game window to be ready"); + context.Process.WaitForInputIdle(); + } + catch (InvalidOperationException) + { + return; + } context.Logger.LogInformation("Launching BetterGI"); await Launcher.LaunchUriAsync(betterGenshinImpactUri);