Skip to content

Commit

Permalink
🐛 修复判断打开广告地址带登录信息错误判断
Browse files Browse the repository at this point in the history
  • Loading branch information
Mossimos committed Nov 20, 2024
1 parent e32c0bb commit 6cf351b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/BD.WTTS.Client.Avalonia/UI/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public async void OpenBrowserCommandCore(object? url)
try
{
Uri uri = new(urlString);
if (uri.Host.EndsWith("steampp.net", StringComparison.OrdinalIgnoreCase) ||
uri.Host.EndsWith("mossimo.net", StringComparison.OrdinalIgnoreCase))
if (uri.Host.EndsWith(Constants.Urls.OfficialWebsiteHost, StringComparison.OrdinalIgnoreCase) &&
uri.Query.EndsWith(Constants.Urls.Komaasharu_IsAuthQuery, StringComparison.OrdinalIgnoreCase))
{
await UserService.Current.OpenAuthUrl(urlString);
return;
Expand Down
59 changes: 25 additions & 34 deletions src/BD.WTTS.Client/Services/Mvvm/Identity/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ private UserService()
CurrentSteamUser = null;
AvatarPath = null;
};
OpenAuthWattGameCommand = ReactiveCommand.Create<string>(url => OpenAuthUrl(url, FastLoginWebChannel.WattGame));
OpenAuthOfficialCommand = ReactiveCommand.Create<string>(url => OpenAuthUrl(url, FastLoginWebChannel.OfficialWebsite));
OpenAuthWattGameCommand = ReactiveCommand.CreateFromTask<string>(async url => await OpenAuthUrl(url, FastLoginWebChannel.WattGame));
OpenAuthOfficialCommand = ReactiveCommand.CreateFromTask<string>(async url => await OpenAuthUrl(url, FastLoginWebChannel.OfficialWebsite));
Task.Run(Initialize).ForgetAndDispose();
}

Expand Down Expand Up @@ -224,21 +224,22 @@ public async void RefreshShopToken(bool refreshToken = true)
/// <returns></returns>
public async Task OpenAuthUrl(string url)
{
if (url.StartsWith(Constants.Urls.WattGame, StringComparison.OrdinalIgnoreCase))
{
OpenAuthUrl(url, FastLoginWebChannel.WattGame);
return;
}

var token = await userManager.GetAuthTokenAsync();
if (token == null)
{
Browser2.Open(url.ToString());
}
else
{
Browser2.Open(string.Format(Constants.Urls.OfficialWebsite_Fast_Login_, token.AccessToken, HttpUtility.UrlEncode(token.ExpiresIn.ToString("R")), HttpUtility.UrlEncode(url)));
}
await OpenAuthUrl(url, url.StartsWith(Constants.Urls.WattGame, StringComparison.OrdinalIgnoreCase) ? FastLoginWebChannel.WattGame : FastLoginWebChannel.OfficialWebsite);
//if (url.StartsWith(Constants.Urls.WattGame, StringComparison.OrdinalIgnoreCase))
//{
// return;
//}

//var token = await userManager.GetAuthTokenAsync();
//if (token == null)
//{
// Browser2.Open(url.ToString());
//}
//else
//{
// Browser2.Open(string.Format(Constants.Urls.OfficialWebsite_Fast_Login_, token.AccessToken, HttpUtility.UrlEncode(token.ExpiresIn.ToString("R")), HttpUtility.UrlEncode(url)));
//}
}

public async Task RefreshUserAvatarAsync()
Expand Down Expand Up @@ -322,38 +323,28 @@ async Task<bool> RefreshSteamUserAvatarAsync()
/// </summary>
/// <param name="url">跳转地址</param>
/// <param name="channel">Web 跳转渠道</param>
public async void OpenAuthUrl(string url, FastLoginWebChannel channel = FastLoginWebChannel.OfficialWebsite)
public async Task OpenAuthUrl(string url, FastLoginWebChannel channel = FastLoginWebChannel.OfficialWebsite)
{
switch (channel)
{

case FastLoginWebChannel.OfficialWebsite:
var token = await userManager.GetAuthTokenAsync();
if (token == null)
{
Browser2.Open(url.ToString());
}
else
if (token != null)
{
Browser2.Open(string.Format(Constants.Urls.OfficialWebsite_Fast_Login_, token.AccessToken, HttpUtility.UrlEncode(token.ExpiresIn.ToString()), HttpUtility.UrlEncode(url)));
await Browser2.OpenAsync(string.Format(Constants.Urls.OfficialWebsite_Fast_Login_, token.AccessToken, HttpUtility.UrlEncode(token.ExpiresIn.ToString("R")), HttpUtility.UrlEncode(url)));
}
break;
return;
case FastLoginWebChannel.WattGame:
var shopToken = await userManager.GetShopAuthTokenAsync();
if (shopToken == null)
{
Browser2.Open(url.ToString());
}
else
if (shopToken != null)
{
var cookieMaxAge = (shopToken.ExpiresIn - DateTimeOffset.Now).TotalSeconds;
Browser2.Open(string.Format(Constants.Urls.WattGame_Fast_Login_, shopToken.AccessToken, HttpUtility.UrlEncode(cookieMaxAge.ToString()), HttpUtility.UrlEncode(url)));
await Browser2.OpenAsync(string.Format(Constants.Urls.WattGame_Fast_Login_, shopToken.AccessToken, HttpUtility.UrlEncode(cookieMaxAge.ToString()), HttpUtility.UrlEncode(url)));
}
break;
default:
Browser2.Open(url.ToString());
break;
return;
}
await Browser2.OpenAsync(url.ToString());
}

/// <summary>
Expand Down

0 comments on commit 6cf351b

Please sign in to comment.