Skip to content

Commit

Permalink
feat: add load animation when login
Browse files Browse the repository at this point in the history
  • Loading branch information
Serein207 committed Oct 17, 2024
1 parent 7969141 commit 04f6637
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Controller/AsyncExecutor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ private:
AsyncExecutor() {
_iocThread = std::thread([this] {
net::signal_set signals{_ioc, SIGINT, SIGTERM};
signals.async_wait([&](auto, auto) { _ioc.stop(); });
signals.async_wait([&](auto, auto) {
_ioc.stop();
slint::quit_event_loop();
});
net::executor_work_guard<decltype(_ioc.get_executor())> work{_ioc.get_executor()};
_ioc.run();
});
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/Core/AccountManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void AccountManager::tryLoginDirectly() {
}

spdlog::info("Try login directly, expired time: {}", _expiredTime.time_since_epoch().count());
self->set_loading(true);

#ifdef EVENTO_API_V1
if (auto token = getKeychainAccessToken()) {
Expand All @@ -179,6 +180,7 @@ void AccountManager::tryLoginDirectly() {
}
#endif
else {
self->set_loading(false);
self.bridge.getMessageManager().showMessage("登录过期,请重新登录", MessageType::Info);
}
}
Expand Down Expand Up @@ -289,6 +291,7 @@ void AccountManager::setKeychainAccessToken(const std::string& accessToken) cons

void AccountManager::setLoginState(bool newState) {
auto& self = *this;
self->set_loading(false);
if (_loginState != newState) {
_loginState = newState;
self->set_is_login(newState);
Expand Down
1 change: 1 addition & 0 deletions src/Controller/View/LoginOverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void LoginOverlay::onShow() {
}

void LoginOverlay::onLogin() {
auto& self = *this;
if (bridge.getViewManager().isVisible(ViewName::LoginOverlay)) {
bridge.getViewManager().priorView();
}
Expand Down
1 change: 1 addition & 0 deletions ui/logic/account_manager.slint
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export global AccountManagerBridge {
in-out property <bool> is-login;
in-out property <bool> loading: false;
callback request-login();
callback request-logout();
}
Expand Down
8 changes: 6 additions & 2 deletions ui/views/overlay/login.slint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Token } from "../../global.slint";
import { Overlay, Empty, StyledText } from "../../components/index.slint";
import { ViewManager, MessageManager, MessageType, AccountManagerBridge } from "../../logic/index.slint";
import { SButton } from "../../modules/surrealism-ui/index.slint";
import { Button, ButtonType } from "../../components/index.slint";
import { Button, ButtonType, LoadingAnimation } from "../../components/index.slint";

export global LoginOverlayBridge {
in-out property <string> version:"v0.0.0-00000000";
Expand Down Expand Up @@ -72,7 +72,8 @@ export component LoginOverlay inherits Overlay {
icon-size: 31px;
filled-surface: Token.color.inverse-surface;
filled-on-surface: Token.color.inverse-on-surface;
Path {
// disable: AccountManagerBridge.loading;
if !AccountManagerBridge.loading: Path {
width: 31px;
height: 26px;
viewbox-width: 31;
Expand All @@ -82,6 +83,9 @@ export component LoginOverlay inherits Overlay {
stroke-width: 2px;
fill-rule: FillRule.evenodd;
}
if AccountManagerBridge.loading: LoadingAnimation {
color: parent.filled-on-surface;
}

clicked => {
LoginOverlayBridge.link-login();
Expand Down

0 comments on commit 04f6637

Please sign in to comment.