Fix of sending refreshed token to Connect

Improved timeout logic
This commit is contained in:
David Kocik 2024-11-20 10:09:06 +01:00
parent 5ba8f21c77
commit 0503733694
3 changed files with 21 additions and 3 deletions

View File

@ -553,9 +553,10 @@ void UserAccountCommunication::set_refresh_time(int seconds)
{
assert(m_token_timer);
m_token_timer->Stop();
const auto prior_expiration_secs = 5 * 60;
int milliseconds = std::max((seconds - prior_expiration_secs) * 1000, 50000);
const auto prior_expiration_secs = std::max(seconds / 24, 10);
int milliseconds = std::max((seconds - prior_expiration_secs) * 1000, 1000);
m_next_token_refresh_at = std::time(nullptr) + milliseconds / 1000;
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << " " << milliseconds / 1000;
m_token_timer->StartOnce(milliseconds);
}

View File

@ -576,12 +576,13 @@ ConnectWebViewPanel::ConnectWebViewPanel(wxWindow* parent)
{
auto* plater = wxGetApp().plater();
plater->Bind(EVT_UA_LOGGEDOUT, &ConnectWebViewPanel::on_user_logged_out, this);
plater->Bind(EVT_UA_ID_USER_SUCCESS, &ConnectWebViewPanel::on_user_token, this);
}
void ConnectWebViewPanel::late_create()
{
WebViewPanel::late_create();
if (!m_browser) {
if (!m_browser) {
return;
}
@ -595,6 +596,21 @@ void ConnectWebViewPanel::late_create()
resend_config();
}
void ConnectWebViewPanel::on_user_token(UserAccountSuccessEvent& e)
{
e.Skip();
if (!m_browser) {
return;
}
auto access_token = wxGetApp().plater()->get_user_account()->get_access_token();
assert(!access_token.empty());
wxString javascript = get_login_script(true);
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << "\n";
m_browser->RunScriptAsync(javascript);
resend_config();
}
ConnectWebViewPanel::~ConnectWebViewPanel()
{
}

View File

@ -142,6 +142,7 @@ protected:
void on_connect_action_error(const std::string &message_data) override;
void on_reload_event(const std::string& message_data) override;
void on_connect_action_close_dialog(const std::string& message_data) override {assert(true);}
void on_user_token(UserAccountSuccessEvent& e);
private:
static wxString get_login_script(bool refresh);
static wxString get_logout_script();