修复同步失败:手机号登录后释放客户端,避免 session 文件被占用
This commit is contained in:
1 parent
ec96545f10
commit
146ce08454
3 files changed
+35
-2
No files matched your search
@@ -41,6 +41,11 @@ public interface IAccountService
|
||||
/// 检查账号状态
|
||||
/// </summary>
|
||||
Task<AccountStatus> CheckStatusAsync(int accountId);
|
||||
|
||||
/// <summary>
|
||||
/// 释放并移除指定账号的 Telegram 客户端(用于避免 session 文件长期被占用)。
|
||||
/// </summary>
|
||||
Task ReleaseClientAsync(int accountId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -230,6 +230,11 @@ public class AccountService : IAccountService
|
||||
return Task.FromResult(AccountStatus.Active);
|
||||
}
|
||||
|
||||
public Task ReleaseClientAsync(int accountId)
|
||||
{
|
||||
return _clientPool.RemoveClientAsync(accountId);
|
||||
}
|
||||
|
||||
private static AccountInfo MapToAccountInfo(int accountId, WTelegram.Client client)
|
||||
{
|
||||
var user = client.User!;
|
||||
|
||||
@@ -156,8 +156,20 @@
|
||||
_ => "下一步"
|
||||
};
|
||||
|
||||
private Task ResetAsync()
|
||||
private async Task ResetAsync()
|
||||
{
|
||||
if (accountId != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
await AccountService.ReleaseClientAsync(accountId);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略释放失败,避免影响 UI 重置
|
||||
}
|
||||
}
|
||||
|
||||
accountId = 0;
|
||||
phoneNumber = "";
|
||||
verificationCode = "";
|
||||
@@ -165,7 +177,6 @@
|
||||
username = "";
|
||||
userId = 0;
|
||||
currentStep = LoginStep.Phone;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task PreviousAsync()
|
||||
@@ -374,6 +385,18 @@
|
||||
|
||||
// 跳转到完成步骤
|
||||
currentStep = LoginStep.Done;
|
||||
|
||||
if (accountId != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
await AccountService.ReleaseClientAsync(accountId);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略释放失败
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user