Skip to content

Commit

Permalink
fix: panic on cancel login
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonflylee committed Jun 24, 2024
1 parent a4d8070 commit 5dd56cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/include/tab/server_login.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ class ServerLogin : public brls::Box {
BRLS_BIND(brls::Label, labelDisclaimer, "login/disclaimer");

std::string url;

void Disclaimer();
};
27 changes: 19 additions & 8 deletions app/src/tab/server_login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ ServerLogin::ServerLogin(const std::string& name, const std::string& url, const

this->hdrSigin->setTitle(brls::getStr("main/setting/server/sigin_to", name));
this->inputUser->init("main/setting/username"_i18n, user);
this->inputPass->init(
"main/setting/password"_i18n, "", [](std::string text) {}, "", "", 256);
this->inputPass->init("main/setting/password"_i18n, "", [](std::string text) {}, "", "", 256);

this->btnSignin->registerClickAction([this](...) { return this->onSignin(); });
this->btnQuickConnect->setVisibility(brls::Visibility::GONE);
Expand All @@ -111,35 +110,47 @@ ServerLogin::ServerLogin(const std::string& name, const std::string& url, const
return true;
});

brls::async([this]() {
ASYNC_RETAIN
brls::async([ASYNC_TOKEN]() {
try {
std::string resp = HTTP::get(this->url + jellyfin::apiQuickEnabled, HTTP::Timeout{});
if (resp.compare("true") == 0)
brls::sync([this]() { this->btnQuickConnect->setVisibility(brls::Visibility::VISIBLE); });
brls::sync([ASYNC_TOKEN]() {
ASYNC_RELEASE
this->btnQuickConnect->setVisibility(brls::Visibility::VISIBLE);
});
} catch (const std::exception& ex) {
ASYNC_RELEASE
brls::Logger::warning("query quickconnect: {}", ex.what());
}
});

this->Disclaimer();
}

ServerLogin::~ServerLogin() { brls::Logger::debug("ServerLogin Activity: delete"); }

void ServerLogin::Disclaimer() {
ASYNC_RETAIN
this->labelDisclaimer->setVisibility(brls::Visibility::INVISIBLE);
brls::async([this]() {
brls::async([ASYNC_TOKEN]() {
try {
auto resp = HTTP::get(this->url + jellyfin::apiBranding, HTTP::Timeout{});
jellyfin::BrandingConfig r = nlohmann::json::parse(resp);
if (!r.LoginDisclaimer.empty()) {
brls::sync([this, r]() {
brls::sync([ASYNC_TOKEN, r]() {
ASYNC_RELEASE
this->labelDisclaimer->setText(r.LoginDisclaimer);
this->labelDisclaimer->setVisibility(brls::Visibility::VISIBLE);
});
}
} catch (const std::exception& ex) {
ASYNC_RELEASE
brls::Logger::warning("get login disclaimer: {}", ex.what());
}
});
}

ServerLogin::~ServerLogin() { brls::Logger::debug("ServerLogin Activity: delete"); }

bool ServerLogin::onSignin() {
std::string username = inputUser->getValue();
std::string password = inputPass->getValue();
Expand Down

0 comments on commit 5dd56cf

Please sign in to comment.