Skip to content

Commit

Permalink
UI: Delete config section when disconnecting account
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod committed Jun 24, 2023
1 parent 6c5fdc1 commit 91096b9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions UI/auth-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,20 @@ void Auth::Save()
auth->SaveInternal();
config_save_safe(main->Config(), "tmp", nullptr);
}

void Auth::Delete()
{
OBSBasic *main = OBSBasic::Get();
Auth *auth = main->auth.get();
if (!auth) {
if (config_has_user_value(main->Config(), "Auth", "Type")) {
config_remove_value(main->Config(), "Auth", "Type");
config_save_safe(main->Config(), "tmp", nullptr);
}
return;
}

config_remove_value(main->Config(), "Auth", "type");
auth->DeleteInternal();
config_save_safe(main->Config(), "tmp", nullptr);
}
2 changes: 2 additions & 0 deletions UI/auth-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Auth : public QObject {
protected:
virtual void SaveInternal() = 0;
virtual bool LoadInternal() = 0;
virtual void DeleteInternal() = 0;

bool firstLoad = true;

Expand Down Expand Up @@ -56,6 +57,7 @@ class Auth : public QObject {
static bool External(const std::string &service);
static void Load();
static void Save();
static void Delete();

protected:
static void RegisterAuth(const Def &d, create_cb create);
Expand Down
12 changes: 12 additions & 0 deletions UI/auth-oauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ bool OAuth::LoadInternal()
return implicit ? !token.empty() : !refresh_token.empty();
}

void OAuth::DeleteInternal()
{
OBSBasic *main = OBSBasic::Get();

/* Delete keychain item (if it exists) */
os_keychain_delete(
config_get_string(main->Config(), service(), "KeychainItem"));

/* Delete OAuth config section */
config_remove_section(main->Config(), service());
}

bool OAuth::TokenExpired()
{
if (token.empty())
Expand Down
1 change: 1 addition & 0 deletions UI/auth-oauth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class OAuth : public Auth {

virtual void SaveInternal() override;
virtual bool LoadInternal() override;
virtual void DeleteInternal() override;

virtual bool RetryLogin() = 0;
bool TokenExpired();
Expand Down
3 changes: 3 additions & 0 deletions UI/window-basic-auto-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ void AutoConfigStreamPage::on_disconnectAccount_clicked()

OBSBasic *main = OBSBasic::Get();

if (auth)
auth->Delete();

main->auth.reset();
auth.reset();

Expand Down
3 changes: 3 additions & 0 deletions UI/window-basic-settings-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,9 @@ void OBSBasicSettings::on_disconnectAccount_clicked()
return;
}

if (auth)
auth->Delete();

main->auth.reset();
auth.reset();
main->SetBroadcastFlowEnabled(false);
Expand Down

0 comments on commit 91096b9

Please sign in to comment.