auto select existed account when detecting

This commit is contained in:
DismissedLight
2023-10-17 20:29:14 +08:00
parent cca65635a6
commit 08cf823156
3 changed files with 15 additions and 7 deletions

View File

@@ -281,7 +281,7 @@ internal sealed partial class GameService : IGameService
}
/// <inheritdoc/>
public async ValueTask DetectGameAccountAsync()
public async ValueTask<GameAccount?> DetectGameAccountAsync()
{
ArgumentNullException.ThrowIfNull(gameAccounts);
@@ -318,7 +318,11 @@ internal sealed partial class GameService : IGameService
gameAccounts.Add(account);
}
}
return account;
}
return default;
}
/// <inheritdoc/>

View File

@@ -26,11 +26,7 @@ internal interface IGameService
/// <param name="uid">uid</param>
void AttachGameAccountToUid(GameAccount gameAccount, string uid);
/// <summary>
/// 检测并尝试添加游戏内账户
/// </summary>
/// <returns>任务</returns>
ValueTask DetectGameAccountAsync();
ValueTask<GameAccount?> DetectGameAccountAsync();
/// <summary>
/// 异步获取游戏路径

View File

@@ -236,7 +236,15 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel
{
try
{
await gameService.DetectGameAccountAsync().ConfigureAwait(false);
GameAccount? account = await gameService.DetectGameAccountAsync().ConfigureAwait(false);
// If user canceled the operation, the return is null,
// and thus we should not set SelectedAccount
if (account is not null)
{
await taskContext.SwitchToMainThreadAsync();
SelectedGameAccount = account;
}
}
catch (UserdataCorruptedException ex)
{