mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	Merge pull request #4211 from wwylele/web-cleanup
web_service: stop using std::future + callback style async
This commit is contained in:
		
						commit
						4a30a502a0
					
				
					 23 changed files with 333 additions and 458 deletions
				
			
		|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| #include <QIcon> | ||||
| #include <QMessageBox> | ||||
| #include <QtConcurrent/QtConcurrentRun> | ||||
| #include "citra_qt/configuration/configure_web.h" | ||||
| #include "citra_qt/ui_settings.h" | ||||
| #include "core/settings.h" | ||||
|  | @ -16,7 +17,7 @@ ConfigureWeb::ConfigureWeb(QWidget* parent) | |||
|     connect(ui->button_regenerate_telemetry_id, &QPushButton::clicked, this, | ||||
|             &ConfigureWeb::RefreshTelemetryID); | ||||
|     connect(ui->button_verify_login, &QPushButton::clicked, this, &ConfigureWeb::VerifyLogin); | ||||
|     connect(this, &ConfigureWeb::LoginVerified, this, &ConfigureWeb::OnLoginVerified); | ||||
|     connect(&verify_watcher, &QFutureWatcher<bool>::finished, this, &ConfigureWeb::OnLoginVerified); | ||||
| 
 | ||||
| #ifndef USE_DISCORD_PRESENCE | ||||
|     ui->discord_group->setVisible(false); | ||||
|  | @ -89,17 +90,19 @@ void ConfigureWeb::OnLoginChanged() { | |||
| } | ||||
| 
 | ||||
| void ConfigureWeb::VerifyLogin() { | ||||
|     verified = | ||||
|         Core::VerifyLogin(ui->edit_username->text().toStdString(), | ||||
|                           ui->edit_token->text().toStdString(), [&]() { emit LoginVerified(); }); | ||||
|     ui->button_verify_login->setDisabled(true); | ||||
|     ui->button_verify_login->setText(tr("Verifying")); | ||||
|     verify_watcher.setFuture( | ||||
|         QtConcurrent::run([this, username = ui->edit_username->text().toStdString(), | ||||
|                            token = ui->edit_token->text().toStdString()]() { | ||||
|             return Core::VerifyLogin(username, token); | ||||
|         })); | ||||
| } | ||||
| 
 | ||||
| void ConfigureWeb::OnLoginVerified() { | ||||
|     ui->button_verify_login->setEnabled(true); | ||||
|     ui->button_verify_login->setText(tr("Verify")); | ||||
|     if (verified.get()) { | ||||
|     if (verify_watcher.result()) { | ||||
|         user_verified = true; | ||||
|         ui->label_username_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16)); | ||||
|         ui->label_token_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16)); | ||||
|  |  | |||
|  | @ -4,8 +4,8 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <future> | ||||
| #include <memory> | ||||
| #include <QFutureWatcher> | ||||
| #include <QWidget> | ||||
| 
 | ||||
| namespace Ui { | ||||
|  | @ -28,14 +28,11 @@ public slots: | |||
|     void VerifyLogin(); | ||||
|     void OnLoginVerified(); | ||||
| 
 | ||||
| signals: | ||||
|     void LoginVerified(); | ||||
| 
 | ||||
| private: | ||||
|     void setConfiguration(); | ||||
| 
 | ||||
|     bool user_verified = true; | ||||
|     std::future<bool> verified; | ||||
|     QFutureWatcher<bool> verify_watcher; | ||||
| 
 | ||||
|     std::unique_ptr<Ui::ConfigureWeb> ui; | ||||
| }; | ||||
|  |  | |||
|  | @ -43,6 +43,7 @@ | |||
| #include "citra_qt/updater/updater.h" | ||||
| #include "citra_qt/util/clickable_label.h" | ||||
| #include "common/common_paths.h" | ||||
| #include "common/detached_tasks.h" | ||||
| #include "common/logging/backend.h" | ||||
| #include "common/logging/filter.h" | ||||
| #include "common/logging/log.h" | ||||
|  | @ -1666,6 +1667,7 @@ void GMainWindow::SetDiscordEnabled(bool state) { | |||
| #endif | ||||
| 
 | ||||
| int main(int argc, char* argv[]) { | ||||
|     Common::DetachedTasks detached_tasks; | ||||
|     MicroProfileOnThreadCreate("Frontend"); | ||||
|     SCOPE_EXIT({ MicroProfileShutdown(); }); | ||||
| 
 | ||||
|  | @ -1691,5 +1693,7 @@ int main(int argc, char* argv[]) { | |||
|     Frontend::RegisterSoftwareKeyboard(std::make_shared<QtKeyboard>(main_window)); | ||||
| 
 | ||||
|     main_window.show(); | ||||
|     return app.exec(); | ||||
|     int result = app.exec(); | ||||
|     detached_tasks.WaitForAllTasks(); | ||||
|     return result; | ||||
| } | ||||
|  |  | |||
|  | @ -74,7 +74,8 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, | |||
|     connect(ui->room_list, &QTreeView::clicked, this, &Lobby::OnExpandRoom); | ||||
| 
 | ||||
|     // Actions
 | ||||
|     connect(this, &Lobby::LobbyRefreshed, this, &Lobby::OnRefreshLobby); | ||||
|     connect(&room_list_watcher, &QFutureWatcher<AnnounceMultiplayerRoom::RoomList>::finished, this, | ||||
|             &Lobby::OnRefreshLobby); | ||||
| 
 | ||||
|     // manually start a refresh when the window is opening
 | ||||
|     // TODO(jroweboy): if this refresh is slow for people with bad internet, then don't do it as
 | ||||
|  | @ -161,16 +162,17 @@ void Lobby::ResetModel() { | |||
| void Lobby::RefreshLobby() { | ||||
|     if (auto session = announce_multiplayer_session.lock()) { | ||||
|         ResetModel(); | ||||
|         room_list_future = session->GetRoomList([&]() { emit LobbyRefreshed(); }); | ||||
|         ui->refresh_list->setEnabled(false); | ||||
|         ui->refresh_list->setText(tr("Refreshing")); | ||||
|         room_list_watcher.setFuture( | ||||
|             QtConcurrent::run([session]() { return session->GetRoomList(); })); | ||||
|     } else { | ||||
|         // TODO(jroweboy): Display an error box about announce couldn't be started
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void Lobby::OnRefreshLobby() { | ||||
|     AnnounceMultiplayerRoom::RoomList new_room_list = room_list_future.get(); | ||||
|     AnnounceMultiplayerRoom::RoomList new_room_list = room_list_watcher.result(); | ||||
|     for (auto room : new_room_list) { | ||||
|         // find the icon for the game if this person owns that game.
 | ||||
|         QPixmap smdh_icon; | ||||
|  |  | |||
|  | @ -4,7 +4,6 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <future> | ||||
| #include <memory> | ||||
| #include <QDialog> | ||||
| #include <QFutureWatcher> | ||||
|  | @ -61,11 +60,6 @@ private slots: | |||
|     void OnJoinRoom(const QModelIndex&); | ||||
| 
 | ||||
| signals: | ||||
|     /**
 | ||||
|      * Signalled when the latest lobby data is retrieved. | ||||
|      */ | ||||
|     void LobbyRefreshed(); | ||||
| 
 | ||||
|     void StateChanged(const Network::RoomMember::State&); | ||||
| 
 | ||||
| private: | ||||
|  | @ -84,7 +78,7 @@ private: | |||
|     QStandardItemModel* game_list; | ||||
|     LobbyFilterProxyModel* proxy; | ||||
| 
 | ||||
|     std::future<AnnounceMultiplayerRoom::RoomList> room_list_future; | ||||
|     QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher; | ||||
|     std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session; | ||||
|     std::unique_ptr<Ui::Lobby> ui; | ||||
|     QFutureWatcher<void>* watcher; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue