Skip to content

Commit

Permalink
Get Teams to actually try reauthing
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenDB committed Nov 30, 2022
1 parent 787180d commit 89ec6bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/TrayIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,10 @@ namespace logs = TimeLight::logs;
TrayIcons::TrayIcons(QObject *parent)
: QObject{parent},
m_trayIcon{new QSystemTrayIcon},
m_teamsClient{new TeamsClient{TimeLight::teamsAppId, 6942, this}},
m_recents{new QList<Project>}
{
connect(m_teamsClient.data(), &TeamsClient::accessTokenChanged, Settings::instance(), [this] {
Settings::instance()->setGraphAccessToken(m_teamsClient->accessToken());
});
connect(m_teamsClient.data(), &TeamsClient::refreshTokenChanged, Settings::instance(), [this] {
Settings::instance()->setGraphRefreshToken(m_teamsClient->refreshToken());
});
if (Settings::instance()->useTeamsIntegration())
{
m_teamsClient->setAccessToken(Settings::instance()->graphAccessToken());
m_teamsClient->setRefreshToken(Settings::instance()->graphRefreshToken());
m_teamsClient->authenticate();
}
connect(Settings::instance(), &Settings::useTeamsIntegrationChanged, this, [this] {
if (!m_teamsClient->authenticated())
m_teamsClient->authenticate();
});
setUpTeams();

auto fixApiKey = [&] {
while (!m_manager->isValid())
Expand Down Expand Up @@ -165,6 +150,13 @@ TrayIcons::TrayIcons(QObject *parent)
});

connect(this, &TrayIcons::jobStarted, this, &TrayIcons::updateTrayIcons, Qt::QueuedConnection);

connect(Settings::instance(), &Settings::useTeamsIntegrationChanged, this, [this] {
if (Settings::instance()->useTeamsIntegration())
setUpTeams();
else
m_teamsClient.clear();
});
}

TrayIcons::~TrayIcons()
Expand Down Expand Up @@ -710,6 +702,22 @@ void TrayIcons::setUpBreakIcon()
});
}

void TrayIcons::setUpTeams()
{
m_teamsClient.reset(new TeamsClient{TimeLight::teamsAppId, 6942, this});

connect(m_teamsClient.data(), &TeamsClient::accessTokenChanged, Settings::instance(), [this] {
Settings::instance()->setGraphAccessToken(m_teamsClient->accessToken());
});
connect(m_teamsClient.data(), &TeamsClient::refreshTokenChanged, Settings::instance(), [this] {
Settings::instance()->setGraphRefreshToken(m_teamsClient->refreshToken());
});

m_teamsClient->setAccessToken(Settings::instance()->graphAccessToken());
m_teamsClient->setRefreshToken(Settings::instance()->graphRefreshToken());
m_teamsClient->authenticate();
}

void TrayIcons::setTimerState(TimerState state)
{
// This is a hacky way of forcing the ratelimited icon, since otherwise it will generally get overridden
Expand Down
1 change: 1 addition & 0 deletions src/TrayIcons.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private slots:
QAction *createBreakResumeAction();
void setUpTrayIcon();
void setUpBreakIcon();
void setUpTeams();
void setTimerState(TimerState state);
void updateIconsAndTooltips();
void updateQuickStartList();
Expand Down

0 comments on commit 89ec6bd

Please sign in to comment.