//Prepare a new session
        public void PrepareSession(Session session = null)
        {
            SessionThread?.Join();

            if (session == null)
            {
                CurrentSession = new Session
                {
                    Username = SettingsManager.Instance.Settings["api"]["user"]
                };
            }
            else
            {
                CurrentSession = session;
            }

            if (CurrentSession.ReadOnly)
            {
                OsuUser currentUserData = null;
                try
                {
                    currentUserData = OsuApi.GetUser(CurrentSession.Username, (OsuMode)Enum.Parse(typeof(OsuMode), SettingsManager.Instance.Settings["api"]["gamemode"]));
                }
                catch (Exception)
                {
                    BrowserViewModel.Instance.SendNotification(NotificationType.Danger, StringStorage.Get("Message.UserDataError"));
                    return;
                }
                BrowserViewModel.Instance.ApplySession(CurrentSession);
                BrowserViewModel.Instance.ApplyUser(currentUserData);

                StopProgressHandler();
                BrowserViewModel.Instance.AttachedJavascriptWrapper.Hide("#sessionProgressTime");
                BrowserViewModel.Instance.AttachedJavascriptWrapper.Show("#sessionProgressReadonly");

                string startDate = DateTimeOffset.FromUnixTimeSeconds(CurrentSession.SessionDate).ToString("MMMM dd yyyy HH:mm:ss");
                string endDate   = DateTimeOffset.FromUnixTimeSeconds(CurrentSession.SessionEndDate).ToString("MMMM dd yyyy HH:mm:ss");

                BrowserViewModel.Instance.AttachedJavascriptWrapper.SetHtml("#sessionProgressReadonlyText", startDate + " to " + endDate);
            }
            else
            {
                SessionThread = new ExtendedThread(() => OnUpdate(), Convert.ToInt32(SettingsManager.Instance.Settings["api"]["updateRate"]));

                lastIteration = DateTimeOffset.Now.ToUnixTimeSeconds();
                nextIteration = DateTimeOffset.Now.ToUnixTimeSeconds() + SessionThread.SleepTime;

                StartProgressHandler();
                SessionThread.Start();

                BrowserViewModel.Instance.AttachedJavascriptWrapper.Hide("#sessionProgressReadonly");

                if (SettingsManager.Instance.Settings["display"]["showTimer"] == "true")
                {
                    BrowserViewModel.Instance.AttachedJavascriptWrapper.Show("#sessionProgressTime");
                }
            }
        }
        public void StartProgressHandler()
        {
            StopProgressHandler();
            ProgressThread = new ExtendedThread(() =>
            {
                float perc         = 0;
                float seconds_left = 0;

                if (nextIteration != -1 && lastIteration != -1)
                {
                    long currentTime = DateTimeOffset.Now.ToUnixTimeSeconds();

                    long normalizedTime    = nextIteration - lastIteration;
                    long normalizedCurrent = nextIteration - currentTime;

                    if (normalizedTime < 0)
                    {
                        normalizedTime = 0;
                    }

                    if (normalizedCurrent < 0)
                    {
                        normalizedCurrent = 0;
                    }

                    if (normalizedTime == 0 || normalizedCurrent == 0)
                    {
                        perc = 0;
                    }
                    else
                    {
                        perc = (float)normalizedCurrent / (float)normalizedTime;
                    }

                    seconds_left = normalizedCurrent + 1;
                }

                int actualPerc = 100 - Convert.ToInt32(Math.Round(perc * 100));

                actualPerc = Math.Min(100, Math.Max(0, actualPerc));

                BrowserViewModel.Instance.AttachedBrowser.ExecuteScriptAsyncWhenPageLoaded("$('#progressbarSessionTimer').css('width', '" + actualPerc + "%');");
                BrowserViewModel.Instance.AttachedBrowser.ExecuteScriptAsyncWhenPageLoaded("$('#sessionProgressTimeText').html('" + seconds_left + " seconds');");
            }, 1);
            ProgressThread.Start();
        }