From 2a15b70c229e2e654e69d11f2df2a5ccd7c22f40 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 11 Aug 2021 18:35:42 +0200 Subject: Youtube: dont update signature while youtube is running --- src/plugins/youtube/Signature.cpp | 41 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/plugins/youtube/Signature.cpp b/src/plugins/youtube/Signature.cpp index 102f56e..30c78b6 100644 --- a/src/plugins/youtube/Signature.cpp +++ b/src/plugins/youtube/Signature.cpp @@ -16,7 +16,7 @@ namespace QuickMedia { static YoutubeSignatureDecryptor *instance = nullptr; static std::mutex update_signature_mutex; - static const int timeout_default_sec = 60 * 5; // 5 minutes + static const int timeout_default_sec = 60 * 10; // 10 minutes static bool is_whitespace(char c) { switch(c) { @@ -158,42 +158,23 @@ namespace QuickMedia { } } + if(up_to_date) + return; + running = true; poll_task = AsyncTask([this]() mutable { - bool has_notified_error = false; - int decrypt_function_update_timeout_seconds = timeout_default_sec; - while(running) { - time_t time_now = time(nullptr); - if(time_now - decrypt_function_last_updated > decrypt_function_update_timeout_seconds) { - int update_res = update_decrypt_function(); - if(update_res != 0) { - if(!has_notified_error) { - if(program_is_dead_in_current_thread()) { - running = false; - return; - } else if(update_res == U_DEC_FUN_NET_ERR) { - show_notification("QuickMedia", "Failed to decrypt youtube signature. Is your internet down?", Urgency::CRITICAL); - decrypt_function_update_timeout_seconds = 10; - } else if(update_res == U_DEC_FUN_FAILED_MATCH_ERR) { - show_notification("QuickMedia", "Failed to decrypt youtube signature. Make sure you are running the latest version of QuickMedia", Urgency::CRITICAL); - running = false; - return; - } - } - has_notified_error = true; - } else { - decrypt_function_update_timeout_seconds = timeout_default_sec; - } + int update_res = update_decrypt_function(); + if(update_res != 0 && !program_is_dead_in_current_thread()) { + if(update_res == U_DEC_FUN_NET_ERR) { + show_notification("QuickMedia", "Failed to decrypt youtube signature. Is your internet down?", Urgency::CRITICAL); + } else if(update_res == U_DEC_FUN_FAILED_MATCH_ERR) { + show_notification("QuickMedia", "Failed to decrypt youtube signature. Make sure you are running the latest version of QuickMedia", Urgency::CRITICAL); } - usleep(1 * 1000 * 1000); // 1 second } + running = false; }); } - YoutubeSignatureDecryptor::~YoutubeSignatureDecryptor() { - running = false; - } - // static YoutubeSignatureDecryptor& YoutubeSignatureDecryptor::get_instance() { std::lock_guard lock(update_signature_mutex); -- cgit v1.2.3