WIP fixes startup (a first one ...)
This commit is contained in:
parent
73dfd48f20
commit
9d22a93eb0
2 changed files with 42 additions and 36 deletions
|
|
@ -67,9 +67,10 @@ namespace BookAStar
|
||||||
MainSettings.UserChanged += MainSettings_UserChanged;
|
MainSettings.UserChanged += MainSettings_UserChanged;
|
||||||
CrossConnectivity.Current.ConnectivityChanged += (conSender, args) =>
|
CrossConnectivity.Current.ConnectivityChanged += (conSender, args) =>
|
||||||
{ App.IsConnected = args.IsConnected; };
|
{ App.IsConnected = args.IsConnected; };
|
||||||
|
SetupHubConnection();
|
||||||
MainSettings_UserChanged(this, null);
|
MainSettings_UserChanged(this, null);
|
||||||
if (CrossConnectivity.Current.IsConnected)
|
|
||||||
StartHubConnection();
|
StartConnexion();
|
||||||
}
|
}
|
||||||
|
|
||||||
// omg
|
// omg
|
||||||
|
|
@ -106,7 +107,7 @@ namespace BookAStar
|
||||||
// Called on rotation
|
// Called on rotation
|
||||||
private void OnSuspended(object sender, EventArgs e)
|
private void OnSuspended(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
StopHubConnection();
|
StopConnection();
|
||||||
int position = 0;
|
int position = 0;
|
||||||
DataManager.Instance.AppState.Clear();
|
DataManager.Instance.AppState.Clear();
|
||||||
foreach (Page page in Navigation.NavigationStack)
|
foreach (Page page in Navigation.NavigationStack)
|
||||||
|
|
@ -125,7 +126,7 @@ namespace BookAStar
|
||||||
// called on app startup, after OnStartup, not on rotation
|
// called on app startup, after OnStartup, not on rotation
|
||||||
private void OnAppResumed(object sender, EventArgs e)
|
private void OnAppResumed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
StartHubConnection();
|
StartConnexion();
|
||||||
// TODO restore the navigation stack
|
// TODO restore the navigation stack
|
||||||
base.OnResume();
|
base.OnResume();
|
||||||
foreach (var pageState in DataManager.Instance.AppState)
|
foreach (var pageState in DataManager.Instance.AppState)
|
||||||
|
|
@ -316,7 +317,7 @@ namespace BookAStar
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
// TODO Start all cloud related stuff
|
// TODO Start all cloud related stuff
|
||||||
StartHubConnection();
|
StartConnexion();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -331,8 +332,9 @@ namespace BookAStar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Start the Hub connection
|
// Start the Hub connection
|
||||||
public static async void StartHubConnection ()
|
public static async void StartConnexion ()
|
||||||
{
|
{
|
||||||
|
if (CrossConnectivity.Current.IsConnected)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await chatHubConnection.Start();
|
await chatHubConnection.Start();
|
||||||
|
|
@ -350,6 +352,8 @@ namespace BookAStar
|
||||||
|
|
||||||
public void SetupHubConnection()
|
public void SetupHubConnection()
|
||||||
{
|
{
|
||||||
|
if (chatHubConnection != null)
|
||||||
|
chatHubConnection.Dispose();
|
||||||
chatHubConnection = new HubConnection(Constants.SignalRHubsUrl);
|
chatHubConnection = new HubConnection(Constants.SignalRHubsUrl);
|
||||||
chatHubConnection.Error += ChatHubConnection_Error;
|
chatHubConnection.Error += ChatHubConnection_Error;
|
||||||
|
|
||||||
|
|
@ -367,7 +371,7 @@ namespace BookAStar
|
||||||
DataManager.Instance.ChatUsers.OnPrivateMessage(msg);
|
DataManager.Instance.ChatUsers.OnPrivateMessage(msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public static void StopHubConnection()
|
public static void StopConnection()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -385,18 +389,13 @@ namespace BookAStar
|
||||||
}
|
}
|
||||||
private void MainSettings_UserChanged(object sender, EventArgs e)
|
private void MainSettings_UserChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (chatHubConnection != null)
|
StopConnection();
|
||||||
{
|
|
||||||
chatHubConnection.Dispose();
|
|
||||||
chatHubConnection = null;
|
|
||||||
chatHubProxy = null;
|
|
||||||
}
|
|
||||||
if (MainSettings.CurrentUser != null)
|
if (MainSettings.CurrentUser != null)
|
||||||
{
|
{
|
||||||
var token = MainSettings.CurrentUser.YavscTokens.AccessToken;
|
var token = MainSettings.CurrentUser.YavscTokens.AccessToken;
|
||||||
SetupHubConnection();
|
|
||||||
chatHubConnection.Headers.Add("Authorization", $"Bearer {token}");
|
chatHubConnection.Headers.Add("Authorization", $"Bearer {token}");
|
||||||
}
|
}
|
||||||
|
StartConnexion();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChatHubConnection_Error(Exception obj)
|
private void ChatHubConnection_Error(Exception obj)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,11 @@ namespace BookAStar.Pages.UserProfile
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void OnRefreshQuery(object sender, EventArgs e)
|
public async void OnRefreshQuery(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// TODO disable the button when current user is not registered
|
||||||
|
if (MainSettings.CurrentUser==null)
|
||||||
|
ShowPage<AccountChooserPage>(null, true);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
IsBusy = true;
|
IsBusy = true;
|
||||||
using (var client = UserHelpers.CreateJsonClient())
|
using (var client = UserHelpers.CreateJsonClient())
|
||||||
|
|
@ -55,6 +60,8 @@ namespace BookAStar.Pages.UserProfile
|
||||||
IsBusy = false;
|
IsBusy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void OnManageFiles(object sender, EventArgs e)
|
public void OnManageFiles(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ShowPage<UserFiles>(null, true);
|
ShowPage<UserFiles>(null, true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue