From 353620c3fa8635c36b266575ec641bf2bebae1fd Mon Sep 17 00:00:00 2001 From: Serein <118594118+Serein207@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:58:48 +0800 Subject: [PATCH] fix: logout failed (#24) * fix: logout failed * build: remove warning info --- CMakeLists.txt | 5 +++-- src/ViewModel/LoginViewModel.cpp | 1 - src/ViewModel/UserProfileViewModel.cpp | 7 ++++++- src/ViewModel/UserProfileViewModel.h | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a15453a..d914799 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,9 @@ endif() find_package(Qt6 6.5 REQUIRED COMPONENTS Quick Multimedia) +add_subdirectory(libs/FluentUI) +add_subdirectory(libs/mbedtls) + qt_standard_project_setup(REQUIRES 6.5) set(CMAKE_AUTORCC ON) @@ -27,8 +30,6 @@ set(FLUENTUI_BUILD_EXAMPLES OFF) if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND LINUX) set(FLUENTUI_QML_PLUGIN_DIRECTORY /usr/lib/qt6/qml/FluentUI) endif() -add_subdirectory(libs/FluentUI) -add_subdirectory(libs/mbedtls) file(GLOB_RECURSE SOURCE_FILES ${CMAKE_SOURCE_DIR}/src/*.cpp diff --git a/src/ViewModel/LoginViewModel.cpp b/src/ViewModel/LoginViewModel.cpp index 87944db..e25d4ee 100644 --- a/src/ViewModel/LoginViewModel.cpp +++ b/src/ViewModel/LoginViewModel.cpp @@ -32,7 +32,6 @@ void LoginViewModel::logout() { emit logoutFailed(result.unwrapErr().message); return; } - auto entity = result.unwrap(); emit logoutSuccess(); }); } diff --git a/src/ViewModel/UserProfileViewModel.cpp b/src/ViewModel/UserProfileViewModel.cpp index 7d85588..c2093e9 100644 --- a/src/ViewModel/UserProfileViewModel.cpp +++ b/src/ViewModel/UserProfileViewModel.cpp @@ -16,6 +16,11 @@ UserProfileViewModel* UserProfileViewModel::create(QQmlEngine*, QJSEngine*) { } void UserProfileViewModel::loadUserProfile() { + if (!getIsLogin()) { // when logout + setUserProfileModel(UserProfile()); + emit loadUserProfileSuccess(); + return; + } CloudMusicClient::getInstance()->getLoginStatus([=](Result result) { if (result.isErr()) { emit loadUserProfileFailed(result.unwrapErr().message); @@ -59,7 +64,7 @@ bool UserProfileViewModel::getDefaultAvatar() const { return userProfileModel.defaultAvatar; } -void UserProfileViewModel::setUserProfileModel(const UserProfile& model) { +void UserProfileViewModel::setUserProfileModel(UserProfile model) { userProfileModel = std::move(model); emit userIdChanged(); emit nicknameChanged(); diff --git a/src/ViewModel/UserProfileViewModel.h b/src/ViewModel/UserProfileViewModel.h index 358e0a7..99bc862 100644 --- a/src/ViewModel/UserProfileViewModel.h +++ b/src/ViewModel/UserProfileViewModel.h @@ -27,7 +27,7 @@ class UserProfileViewModel : public QObject { bool getDefaultAvatar() const; - void setUserProfileModel(const UserProfile& model); + void setUserProfileModel(UserProfile model); signals: void isLoginChanged();