aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/AsyncTask.hpp13
-rw-r--r--include/GoogleCaptcha.hpp5
-rw-r--r--include/QuickMedia.hpp11
3 files changed, 22 insertions, 7 deletions
diff --git a/include/AsyncTask.hpp b/include/AsyncTask.hpp
index 0d9c453..abdc0f8 100644
--- a/include/AsyncTask.hpp
+++ b/include/AsyncTask.hpp
@@ -26,6 +26,19 @@ namespace QuickMedia {
return *this;
}
+ AsyncTask(AsyncTask &&other) {
+ cancel();
+ thread = std::move(other.thread);
+ future = std::move(other.future);
+ }
+
+ AsyncTask& operator=(AsyncTask &&other) {
+ cancel();
+ thread = std::move(other.thread);
+ future = std::move(other.future);
+ return *this;
+ }
+
~AsyncTask() {
cancel();
}
diff --git a/include/GoogleCaptcha.hpp b/include/GoogleCaptcha.hpp
index 62e47fa..f8063f3 100644
--- a/include/GoogleCaptcha.hpp
+++ b/include/GoogleCaptcha.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "AsyncTask.hpp"
#include <string>
#include <optional>
#include <functional>
@@ -15,7 +16,7 @@ namespace QuickMedia {
};
using RequestChallengeResponse = std::function<void(std::optional<GoogleCaptchaChallengeInfo>)>;
- std::future<bool> google_captcha_request_challenge(const std::string &api_key, const std::string &referer, RequestChallengeResponse challenge_response_callback);
+ AsyncTask<bool> google_captcha_request_challenge(const std::string &api_key, const std::string &referer, RequestChallengeResponse challenge_response_callback);
using PostSolutionResponse = std::function<void(std::optional<std::string>, std::optional<GoogleCaptchaChallengeInfo>)>;
- std::future<bool> google_captcha_post_solution(const std::string &api_key, const std::string &captcha_id, std::array<bool, 9> selected_images, PostSolutionResponse solution_response_callback);
+ AsyncTask<bool> google_captcha_post_solution(const std::string &api_key, const std::string &captcha_id, std::array<bool, 9> selected_images, PostSolutionResponse solution_response_callback);
} \ No newline at end of file
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp
index 3e8e7c7..497f202 100644
--- a/include/QuickMedia.hpp
+++ b/include/QuickMedia.hpp
@@ -6,6 +6,7 @@
#include "Storage.hpp"
#include "Tab.hpp"
#include "MessageQueue.hpp"
+#include "AsyncTask.hpp"
#include <vector>
#include <memory>
#include <SFML/Graphics/Font.hpp>
@@ -65,8 +66,8 @@ namespace QuickMedia {
bool fetching_next_page_running = false;
int fetched_page = 0;
sf::Text search_result_text;
- std::future<FetchResult> fetch_future;
- std::future<BodyItems> next_page_future;
+ AsyncTask<FetchResult> fetch_future;
+ AsyncTask<BodyItems> next_page_future;
};
class Program {
@@ -152,9 +153,9 @@ namespace QuickMedia {
std::string manga_id_base64;
Json::Value content_storage_json;
std::unordered_set<std::string> watched_videos;
- std::future<BodyItems> search_suggestion_future;
- std::future<std::string> autocomplete_future;
- std::future<void> image_download_future;
+ AsyncTask<BodyItems> search_suggestion_future;
+ AsyncTask<std::string> autocomplete_future;
+ AsyncTask<void> image_download_future;
std::thread image_upscale_thead;
MessageQueue<CopyOp> images_to_upscale_queue;
std::vector<char> image_upscale_status;