App UI development
Updated and enchanced MainPage Updated Core
This commit is contained in:
@@ -22,7 +22,7 @@ namespace FoxTube
|
||||
{
|
||||
public static class UserManagement
|
||||
{
|
||||
public const int MaxUsersCount = 2;
|
||||
public const int MaxUsersCount = 1;
|
||||
|
||||
#region Private members
|
||||
private static readonly ApplicationDataContainer storage = ApplicationData.Current.LocalSettings;
|
||||
@@ -48,16 +48,13 @@ namespace FoxTube
|
||||
{
|
||||
ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com",
|
||||
ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_"
|
||||
},
|
||||
new ClientSecrets // DISABLED
|
||||
{
|
||||
ClientId = "1096685398208-u95rcpkqb4e1ijfmb8jdq3jsg37l8igv.apps.googleusercontent.com",
|
||||
ClientSecret = "IU5bbdjwvmx8ttJoXQ7e6JWd"
|
||||
}
|
||||
};
|
||||
#endregion
|
||||
|
||||
public static Userinfoplus[] Users { get; private set; } = new Userinfoplus[MaxUsersCount];
|
||||
|
||||
public static bool CanAddAccounts => Users.Any(i => i == null);
|
||||
public static User CurrentUser { get; set; }
|
||||
public static bool Authorized => CurrentUser != null;
|
||||
public static ExtendedYouTubeService Service => CurrentUser?.Service ?? _defaultService;
|
||||
@@ -108,7 +105,7 @@ namespace FoxTube
|
||||
|
||||
public static async Task Initialize()
|
||||
{
|
||||
Users = JsonConvert.DeserializeObject<Userinfoplus[]>(storage.Values["UserManagement.Users"] as string);
|
||||
Users = JsonConvert.DeserializeObject<Userinfoplus[]>(storage.Values["UserManagement.Users"] as string ?? "") ?? new Userinfoplus[MaxUsersCount];
|
||||
int? lastUserIndex = storage.Values["UserManagement.LastUser"] as int?;
|
||||
|
||||
if (lastUserIndex.HasValue && Users[lastUserIndex.Value] != null ||
|
||||
@@ -126,8 +123,12 @@ namespace FoxTube
|
||||
string userId = CurrentUser.UserInfo.Id;
|
||||
|
||||
PasswordVault passwordVault = new PasswordVault();
|
||||
PasswordCredential credential = passwordVault.Retrieve("foxtube", userId);
|
||||
passwordVault.Remove(credential);
|
||||
try
|
||||
{
|
||||
PasswordCredential credential = passwordVault.Retrieve("foxtube", userId);
|
||||
passwordVault.Remove(credential);
|
||||
}
|
||||
catch { }
|
||||
|
||||
await CurrentUser.Credential.RevokeTokenAsync(CancellationToken.None);
|
||||
|
||||
@@ -159,20 +160,27 @@ namespace FoxTube
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task SwitchUser(int userIndex)
|
||||
public static async Task<bool> SwitchUser(int userIndex)
|
||||
{
|
||||
Userinfoplus userInfo = Users[userIndex];
|
||||
|
||||
PasswordVault valut = new PasswordVault();
|
||||
PasswordCredential vaultCredential = valut.Retrieve("foxtube", userInfo.Id);
|
||||
if (vaultCredential == null)
|
||||
throw new NullReferenceException("No user found to switch on");
|
||||
try
|
||||
{
|
||||
PasswordCredential vaultCredential = valut.Retrieve("foxtube", userInfo.Id);
|
||||
|
||||
vaultCredential.RetrievePassword();
|
||||
string token = vaultCredential.Password;
|
||||
YouTube.Authorization.UserCredential credential = await AuthorizationHelpers.RestoreUser(ClientSecrets[userIndex], token);
|
||||
vaultCredential.RetrievePassword();
|
||||
string token = vaultCredential.Password;
|
||||
YouTube.Authorization.UserCredential credential = await AuthorizationHelpers.RestoreUser(ClientSecrets[userIndex], token);
|
||||
|
||||
await LoadUser(credential, userIndex);
|
||||
await LoadUser(credential, userIndex);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task LoadUser(YouTube.Authorization.UserCredential credential, int userIndex)
|
||||
@@ -192,15 +200,16 @@ namespace FoxTube
|
||||
private static void UpdateToken(string id, string refreshToken)
|
||||
{
|
||||
PasswordVault passwordVault = new PasswordVault();
|
||||
PasswordCredential vaultCredential = passwordVault.Retrieve("foxtube", id);
|
||||
|
||||
if (vaultCredential == null)
|
||||
try
|
||||
{
|
||||
vaultCredential = new PasswordCredential("foxtube", CurrentUser.UserInfo.Id, refreshToken);
|
||||
PasswordCredential vaultCredential = passwordVault.Retrieve("foxtube", id);
|
||||
vaultCredential.Password = refreshToken;
|
||||
}
|
||||
catch
|
||||
{
|
||||
PasswordCredential vaultCredential = new PasswordCredential("foxtube", CurrentUser.UserInfo.Id, refreshToken);
|
||||
passwordVault.Add(vaultCredential);
|
||||
}
|
||||
else
|
||||
vaultCredential.Password = refreshToken;
|
||||
}
|
||||
|
||||
internal static void SubscriptionsChangedInvoker(User sender, Subscription subscription) =>
|
||||
|
||||
Reference in New Issue
Block a user