aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-06-09 16:41:10 +0200
committerdec05eba <dec05eba@protonmail.com>2021-06-09 16:41:10 +0200
commit78fce9e810e48095be9d1a81a31df49db9a4d5b3 (patch)
tree233a7943ffa63a1cbba675a8cad2c497862ebbc7 /src
parent9409d8f67f856da0ecfb2a485c2a757c2338469e (diff)
Show critical notification before abort on critical error
Diffstat (limited to 'src')
-rw-r--r--src/Notification.cpp2
-rw-r--r--src/QuickMedia.cpp18
-rw-r--r--src/Storage.cpp3
-rw-r--r--src/Text.cpp2
-rw-r--r--src/VideoPlayer.cpp3
-rw-r--r--src/plugins/Matrix.cpp14
6 files changed, 16 insertions, 26 deletions
diff --git a/src/Notification.cpp b/src/Notification.cpp
index 0507a98..791f4b2 100644
--- a/src/Notification.cpp
+++ b/src/Notification.cpp
@@ -18,8 +18,8 @@ namespace QuickMedia {
}
void show_notification(const std::string &title, const std::string &description, Urgency urgency) {
+ fprintf(stderr, "Notification: title: %s, description: %s\n", title.c_str(), description.c_str());
const char *args[] = { "notify-send", "-t", "10000", "-u", urgency_string(urgency), "--", title.c_str(), description.c_str(), nullptr };
exec_program_async(args, nullptr);
- fprintf(stderr, "Notification: title: %s, description: %s\n", title.c_str(), description.c_str());
}
} \ No newline at end of file
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 3338048..fa0f0d8 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -590,7 +590,7 @@ namespace QuickMedia {
void Program::init(Window parent_window, std::string &program_path) {
disp = XOpenDisplay(NULL);
if (!disp) {
- fprintf(stderr, "Failed to open display to X11 server\n");
+ show_notification("QuickMedia", "Failed to open display to X11 server", Urgency::CRITICAL);
abort();
}
@@ -615,7 +615,7 @@ namespace QuickMedia {
DefaultVisual(disp, screen),
0, nullptr);
if(!x11_window) {
- fprintf(stderr, "Failed to create window\n");
+ show_notification("QuickMedia", "Failed to create window", Urgency::CRITICAL);
abort();
}
@@ -654,23 +654,23 @@ namespace QuickMedia {
if(!is_touch_enabled()) {
if(!circle_mask_shader.loadFromFile(resources_root + "shaders/circle_mask.glsl", sf::Shader::Type::Fragment)) {
- fprintf(stderr, "Failed to load %s/shaders/circle_mask.glsl\n", resources_root.c_str());
+ show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/circle_mask.glsl", Urgency::CRITICAL);
abort();
}
if(!rounded_rectangle_shader.loadFromFile(resources_root + "shaders/rounded_rectangle.glsl", sf::Shader::Type::Fragment)) {
- fprintf(stderr, "Failed to load %s/shaders/rounded_rectangle.glsl\n", resources_root.c_str());
+ show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle.glsl", Urgency::CRITICAL);
abort();
}
if(!rounded_rectangle_mask_shader.loadFromFile(resources_root + "shaders/rounded_rectangle_mask.glsl", sf::Shader::Type::Fragment)) {
- fprintf(stderr, "Failed to load %s/shaders/rounded_rectangle_mask.glsl\n", resources_root.c_str());
+ show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_mask.glsl", Urgency::CRITICAL);
abort();
}
}
if(!loading_icon.loadFromFile(resources_root + "images/loading_icon.png")) {
- fprintf(stderr, "Failed to load %s/images/loading_icon.png\n", resources_root.c_str());
+ show_notification("QuickMedia", "Failed to load " + resources_root + "/images/loading_icon.png", Urgency::CRITICAL);
abort();
}
loading_icon.setSmooth(true);
@@ -703,17 +703,17 @@ namespace QuickMedia {
fprintf(stderr, "Monitor hz: %d\n", monitor_hz);
if(create_directory_recursive(get_cache_dir().join("media")) != 0) {
- fprintf(stderr, "Failed to create media directory\n");
+ show_notification("QuickMedia", "Failed to create media directory", Urgency::CRITICAL);
abort();
}
if(create_directory_recursive(get_cache_dir().join("thumbnails")) != 0) {
- fprintf(stderr, "Failed to create thumbnails directory\n");
+ show_notification("QuickMedia", "Failed to create thumbnails directory", Urgency::CRITICAL);
abort();
}
//if(create_directory_recursive(get_storage_dir().join("file-manager")) != 0) {
- // fprintf(stderr, "Failed to create file-manager directory\n");
+ // show_notification("QuickMedia", "Failed to create file-manager directory", Urgency::CRITICAL);
// abort();
//}
diff --git a/src/Storage.cpp b/src/Storage.cpp
index 7103b7a..8ef8e5f 100644
--- a/src/Storage.cpp
+++ b/src/Storage.cpp
@@ -1,5 +1,6 @@
#include "../include/Storage.hpp"
#include "../include/StringUtils.hpp"
+#include "../include/Notification.hpp"
#include <stdio.h>
#include <assert.h>
#include <json/reader.h>
@@ -29,7 +30,7 @@ namespace QuickMedia {
homeDir = pw->pw_dir;
}
if(!homeDir) {
- fprintf(stderr, "Failed to get home directory of user!\n");
+ show_notification("QuickMedia", "Failed to get home directory of user", Urgency::CRITICAL);
abort();
}
return homeDir;
diff --git a/src/Text.cpp b/src/Text.cpp
index 7859c7a..138cd9d 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -611,7 +611,7 @@ namespace QuickMedia
vertices[i].resize(0);
}
vertices_linear.clear();
- vertices_linear.resize(0);
+ vertices_linear.shrink_to_fit();
}
}
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index 95a3bd4..adebddc 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -2,6 +2,7 @@
#include "../include/Storage.hpp"
#include "../include/Program.hpp"
#include "../include/Utils.hpp"
+#include "../include/Notification.hpp"
#include <string>
#include <json/reader.h>
#include <json/writer.h>
@@ -43,7 +44,7 @@ namespace QuickMedia {
{
display = XOpenDisplay(NULL);
if (!display) {
- fprintf(stderr, "Failed to open display to X11 server\n");
+ show_notification("QuickMedia", "Failed to open display to X11 server", Urgency::CRITICAL);
abort();
}
fprintf(stderr, "Video max height: %d\n", monitor_height);
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 6c7e4bd..89c9984 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -1957,18 +1957,6 @@ namespace QuickMedia {
return false;
}
- static size_t string_find_case_insensitive(const char *haystack, size_t index, size_t length, const std::string &needle) {
- const char *haystack_end = haystack + length;
- auto it = std::search(haystack + index, haystack_end, needle.begin(), needle.end(),
- [](char c1, char c2) {
- return std::toupper(c1) == std::toupper(c2);
- });
- if(it != haystack_end)
- return it - haystack;
- else
- return std::string::npos;
- }
-
// TODO: Do not show notification if mention is a reply to somebody else that replies to me? also dont show notification everytime a mention is edited
bool message_contains_user_mention(const std::string &msg, const std::string &username) {
if(msg.empty() || username.empty())
@@ -1976,7 +1964,7 @@ namespace QuickMedia {
size_t index = 0;
while(index < msg.size()) {
- size_t found_index = string_find_case_insensitive(&msg[0], index, msg.size(), username);
+ size_t found_index = str_find_case_insensitive(msg, index, username.c_str(), username.size());
if(found_index == std::string::npos)
break;