[gnome-software] shell: Limit the number of lines shown in the in-app notification
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] shell: Limit the number of lines shown in the in-app notification
- Date: Fri, 2 Mar 2018 20:06:10 +0000 (UTC)
commit c4b239ff24e9048a067377f7c8d550095f6cc867
Author: Kalev Lember <klember redhat com>
Date: Fri Mar 2 20:59:36 2018 +0100
shell: Limit the number of lines shown in the in-app notification
I managed to get a 1000 line message printed as an in-app notification
when a distro upgrade transaction depsolve failed with out of space
errors. This took about a minute to render ...
As a fix, this limits the notification to two lines: one from
gnome-software, and one from the GError.
src/gs-shell.c | 68 ++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 52 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 6b0eccb4..55acf184 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -866,6 +866,18 @@ gs_shell_show_detailed_error (GsShell *shell, const GError *error)
return FALSE;
}
+static gchar *
+get_first_line (const gchar *str)
+{
+ g_auto(GStrv) lines;
+
+ lines = g_strsplit (str, "\n", 2);
+ if (lines != NULL && g_strv_length (lines) != 0)
+ return g_strdup (lines[0]);
+
+ return NULL;
+}
+
static gboolean
gs_shell_show_event_refresh (GsShell *shell, GsPluginEvent *event)
{
@@ -957,8 +969,11 @@ gs_shell_show_event_refresh (GsShell *shell, GsPluginEvent *event)
}
/* add extra debugging for debug builds */
- if (gs_shell_show_detailed_error (shell, error))
- g_string_append_printf (str, "\n%s", error->message);
+ if (gs_shell_show_detailed_error (shell, error)) {
+ g_autofree gchar *first_line = get_first_line (error->message);
+ if (first_line != NULL)
+ g_string_append_printf (str, ":\n%s", first_line);
+ }
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1113,8 +1128,11 @@ gs_shell_show_event_install (GsShell *shell, GsPluginEvent *event)
}
/* add extra debugging for debug builds */
- if (gs_shell_show_detailed_error (shell, error))
- g_string_append_printf (str, "\n%s", error->message);
+ if (gs_shell_show_detailed_error (shell, error)) {
+ g_autofree gchar *first_line = get_first_line (error->message);
+ if (first_line != NULL)
+ g_string_append_printf (str, ":\n%s", first_line);
+ }
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1219,8 +1237,11 @@ gs_shell_show_event_update (GsShell *shell, GsPluginEvent *event)
}
/* add extra debugging for debug builds */
- if (gs_shell_show_detailed_error (shell, error))
- g_string_append_printf (str, "\n%s", error->message);
+ if (gs_shell_show_detailed_error (shell, error)) {
+ g_autofree gchar *first_line = get_first_line (error->message);
+ if (first_line != NULL)
+ g_string_append_printf (str, ":\n%s", first_line);
+ }
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1323,8 +1344,11 @@ gs_shell_show_event_upgrade (GsShell *shell, GsPluginEvent *event)
}
/* add extra debugging for debug builds */
- if (gs_shell_show_detailed_error (shell, error))
- g_string_append_printf (str, "\n%s", error->message);
+ if (gs_shell_show_detailed_error (shell, error)) {
+ g_autofree gchar *first_line = get_first_line (error->message);
+ if (first_line != NULL)
+ g_string_append_printf (str, ":\n%s", first_line);
+ }
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1393,8 +1417,11 @@ gs_shell_show_event_remove (GsShell *shell, GsPluginEvent *event)
}
/* add extra debugging for debug builds */
- if (gs_shell_show_detailed_error (shell, error))
- g_string_append_printf (str, "\n%s", error->message);
+ if (gs_shell_show_detailed_error (shell, error)) {
+ g_autofree gchar *first_line = get_first_line (error->message);
+ if (first_line != NULL)
+ g_string_append_printf (str, ":\n%s", first_line);
+ }
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1454,8 +1481,11 @@ gs_shell_show_event_launch (GsShell *shell, GsPluginEvent *event)
}
/* add extra debugging for debug builds */
- if (gs_shell_show_detailed_error (shell, error))
- g_string_append_printf (str, "\n%s", error->message);
+ if (gs_shell_show_detailed_error (shell, error)) {
+ g_autofree gchar *first_line = get_first_line (error->message);
+ if (first_line != NULL)
+ g_string_append_printf (str, ":\n%s", first_line);
+ }
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1492,8 +1522,11 @@ gs_shell_show_event_file_to_app (GsShell *shell, GsPluginEvent *event)
return FALSE;
/* add extra debugging for debug builds */
- if (gs_shell_show_detailed_error (shell, error))
- g_string_append_printf (str, "\n%s", error->message);
+ if (gs_shell_show_detailed_error (shell, error)) {
+ g_autofree gchar *first_line = get_first_line (error->message);
+ if (first_line != NULL)
+ g_string_append_printf (str, ":\n%s", first_line);
+ }
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1569,8 +1602,11 @@ gs_shell_show_event_fallback (GsShell *shell, GsPluginEvent *event)
}
/* add extra debugging for debug builds */
- if (gs_shell_show_detailed_error (shell, error))
- g_string_append_printf (str, "\n%s", error->message);
+ if (gs_shell_show_detailed_error (shell, error)) {
+ g_autofree gchar *first_line = get_first_line (error->message);
+ if (first_line != NULL)
+ g_string_append_printf (str, ":\n%s", first_line);
+ }
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]