aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-04-20 20:38:49 +0200
committerdec05eba <dec05eba@protonmail.com>2021-04-20 23:41:26 +0200
commitde93c6ef39de46cc4078135dfa13954181be6f1b (patch)
tree65f83c16d305c6ed134351244d4906bd09ec7b34
parentc1db97f057e8f20aa26a2342da94eeff1d7a7725 (diff)
Fix random crash when displaying chapter progress
-rw-r--r--include/QuickMedia.hpp1
-rw-r--r--src/QuickMedia.cpp52
-rw-r--r--src/plugins/Matrix.cpp2
3 files changed, 33 insertions, 22 deletions
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp
index bd3b316..e61c2ff 100644
--- a/include/QuickMedia.hpp
+++ b/include/QuickMedia.hpp
@@ -158,6 +158,7 @@ namespace QuickMedia {
Path content_cache_dir;
std::string manga_id_base64;
Json::Value content_storage_json;
+ bool content_storage_file_modified = false;
std::unordered_set<std::string> watched_videos;
AsyncTask<BodyItems> search_suggestion_future;
AsyncTask<std::string> autocomplete_future;
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 8d02b95..a954353 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1193,15 +1193,21 @@ namespace QuickMedia {
manga_id_base64 = base64_encode(manga_id);
content_storage_file = content_storage_dir.join(manga_id_base64);
content_storage_json.clear();
- content_storage_json["name"] = manga_title;
+ content_storage_file_modified = true;
+
+ bool result = true;
FileType file_type = get_file_type(content_storage_file);
if(file_type == FileType::REGULAR) {
- if(read_file_as_json(content_storage_file, content_storage_json) && content_storage_json.isObject())
- return true;
- return false;
+ result = read_file_as_json(content_storage_file, content_storage_json) && content_storage_json.isObject();
} else {
- return true;
+ result = true;
}
+
+ if(!content_storage_json.isObject())
+ content_storage_json = Json::Value(Json::objectValue);
+
+ content_storage_json["name"] = manga_title;
+ return result;
}
void Program::select_file(const std::string &filepath) {
@@ -1288,11 +1294,6 @@ namespace QuickMedia {
};
const Json::Value *json_chapters = &Json::Value::nullSingleton();
- if(content_storage_json.isObject()) {
- const Json::Value &chapters_json = content_storage_json["chapters"];
- if(chapters_json.isObject())
- json_chapters = &chapters_json;
- }
std::vector<TabAssociatedData> tab_associated_data;
for(size_t i = 0; i < tabs.size(); ++i) {
@@ -1313,7 +1314,7 @@ namespace QuickMedia {
std::function<void(const std::string&)> submit_handler;
- submit_handler = [this, &submit_handler, &after_submit_handler, &json_chapters, &tabs, &tab_associated_data, &ui_tabs, &loop_running, &redraw](const std::string &search_text) {
+ submit_handler = [this, &submit_handler, &after_submit_handler, &tabs, &tab_associated_data, &ui_tabs, &loop_running, &redraw](const std::string &search_text) {
const int selected_tab = ui_tabs.get_selected();
auto selected_item = tabs[selected_tab].body->get_selected_shared();
if(!selected_item && !tabs[selected_tab].page->allow_submit_no_selection())
@@ -1399,6 +1400,8 @@ namespace QuickMedia {
}
}
+ content_storage_file_modified = true;
+
image_download_cancel = true;
image_download_future.cancel();
image_download_cancel = false;
@@ -1445,12 +1448,6 @@ namespace QuickMedia {
tab.page->on_navigate_to_page(tab.body.get());
}
- if(content_storage_json.isObject()) {
- const Json::Value &chapters_json = content_storage_json["chapters"];
- if(chapters_json.isObject())
- json_chapters = &chapters_json;
- }
-
tabs[selected_tab].page->submit_body_item = prev_selected_item;
redraw = true;
hide_virtual_keyboard();
@@ -1703,6 +1700,19 @@ namespace QuickMedia {
}
}
+ if(content_storage_file_modified) {
+ content_storage_file_modified = false;
+ if(content_storage_json.isObject()) {
+ const Json::Value &chapters_json = content_storage_json["chapters"];
+ if(chapters_json.isObject())
+ json_chapters = &chapters_json;
+ else
+ json_chapters = &Json::Value::nullSingleton();
+ } else {
+ json_chapters = &Json::Value::nullSingleton();
+ }
+ }
+
window.clear(back_color);
page_loop_render(window, tabs, selected_tab, tab_associated_data[selected_tab], json_chapters, ui_tabs);
window.display();
@@ -3434,7 +3444,7 @@ namespace QuickMedia {
*body_item->embedded_item = *related_body_item;
body_item->embedded_item->embedded_item = nullptr;
body_item->embedded_item->reactions.clear();
- if((related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user.get() == me) || message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, my_user_id))
+ if((related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user.get() == me) || message_contains_user_mention(body_item->get_description(), my_display_name) || message_contains_user_mention(body_item->get_description(), my_user_id))
body_item->set_description_color(sf::Color(255, 100, 100));
else
body_item->set_description_color(sf::Color::White);
@@ -3469,7 +3479,7 @@ namespace QuickMedia {
body_item->userdata = (void*)message; // Note: message has to be valid as long as body_item is used!
if(message->related_event_type == RelatedEventType::REDACTION || message->related_event_type == RelatedEventType::EDIT || message->related_event_type == RelatedEventType::REACTION)
body_item->visible = false;
- if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, my_user_id))
+ if(message_contains_user_mention(body_item->get_description(), my_display_name) || message_contains_user_mention(body_item->get_description(), my_user_id))
body_item->set_description_color(sf::Color(255, 100, 100));
return body_item;
}
@@ -3696,7 +3706,7 @@ namespace QuickMedia {
} else {
Message *orig_message = static_cast<Message*>(body_item->userdata);
body_item->set_description(message_get_body_remove_formatting(message.get()));
- if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id) || (orig_message && orig_message->user == me && message->user != me))
+ if(message_contains_user_mention(body_item->get_description(), my_display_name) || message_contains_user_mention(body_item->get_description(), me->user_id) || (orig_message && orig_message->user == me && message->user != me))
body_item->set_description_color(sf::Color(255, 100, 100));
else
body_item->set_description_color(sf::Color::White);
@@ -3732,7 +3742,7 @@ namespace QuickMedia {
} else {
Message *orig_message = static_cast<Message*>(body_item->userdata);
body_item->set_description(message_get_body_remove_formatting(message.get()));
- if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id) || (orig_message && orig_message->user == me && message->user != me))
+ if(message_contains_user_mention(body_item->get_description(), my_display_name) || message_contains_user_mention(body_item->get_description(), me->user_id) || (orig_message && orig_message->user == me && message->user != me))
body_item->set_description_color(sf::Color(255, 100, 100));
else
body_item->set_description_color(sf::Color::White);
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 147dbdf..57c879e 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -494,7 +494,7 @@ namespace QuickMedia {
else if(message->related_event_type == RelatedEventType::REPLY)
return extract_first_line_elipses(remove_reply_formatting(message->body), 150);
else if(message->related_event_type == RelatedEventType::EDIT)
- return "Edited: " + extract_first_line_elipses(message->body, 150);
+ return "Edited: " + extract_first_line_elipses(remove_reply_formatting(message->body), 150);
else
return extract_first_line_elipses(message->body, 150);
}