-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libworkbench: implement GLogWriterFunc and library initialization
Add `Workbench.init()` to initialize resources and other setup tasks. Currently, this only implements a `GLogWriterFunc` for silencing specific messages that Workbench users shouldn't see. This method has some limitations running on other threads in GJS, and should be more performant in C anyways.
- Loading branch information
1 parent
5a2840e
commit eae9ff0
Showing
7 changed files
with
146 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
// SPDX-FileCopyrightText: Workbench Contributors | ||
// SPDX-FileContributor: Andy Holmes <[email protected]> | ||
|
||
#include <glib.h> | ||
|
||
#include "workbench-global.h" | ||
|
||
|
||
/* | ||
* Silenced log messages | ||
*/ | ||
struct | ||
{ | ||
const char *log_domain; | ||
GLogLevelFlags log_level; | ||
const char *message; | ||
} ignored_messages[] = { | ||
/* GDK4 */ | ||
{ | ||
"Gdk", | ||
G_LOG_LEVEL_CRITICAL, | ||
"gdk_scroll_event_get_direction: assertion 'GDK_IS_EVENT_TYPE (event, GDK_SCROLL)' failed", | ||
}, | ||
{ | ||
"Gdk", | ||
G_LOG_LEVEL_CRITICAL, | ||
"gdk_scroll_event_get_direction: assertion 'GDK_IS_EVENT (event)' failed", | ||
}, | ||
|
||
/* GTK4 */ | ||
{ | ||
"Gtk", | ||
G_LOG_LEVEL_CRITICAL, | ||
"Unable to connect to the accessibility bus at 'unix:path=/run/flatpak/at-spi-bus': Could not connect: No such file or directory", | ||
}, | ||
|
||
/* Adwaita */ | ||
{ | ||
"Adwaita", | ||
G_LOG_LEVEL_WARNING, | ||
"Using GtkSettings:gtk-application-prefer-dark-theme with libadwaita is unsupported. Please use AdwStyleManager:color-scheme instead.", | ||
}, | ||
|
||
/* GVFS */ | ||
{ | ||
"GVFS", | ||
G_LOG_LEVEL_WARNING, | ||
"The peer-to-peer connection failed: Error when getting information for file “/run/user/1000/gvfsd”: No such file or directory. Falling back to the session bus. Your application is probably missing --filesystem=xdg-run/gvfsd privileges.", | ||
}, | ||
}; | ||
|
||
static inline gboolean | ||
workbench_log_ignore (const char *log_domain, | ||
GLogLevelFlags log_level, | ||
const char *message) | ||
{ | ||
if G_UNLIKELY (log_domain == NULL || message == NULL) | ||
return FALSE; | ||
|
||
for (unsigned int i = 0; i < G_N_ELEMENTS (ignored_messages); i++) | ||
{ | ||
if (ignored_messages[i].log_level == log_level && | ||
g_str_equal (ignored_messages[i].log_domain, log_domain) && | ||
g_str_equal (ignored_messages[i].message, message)) | ||
return TRUE; | ||
} | ||
|
||
return FALSE; | ||
} | ||
|
||
static GLogWriterOutput | ||
workbench_log_writer (GLogLevelFlags log_level, | ||
const GLogField *fields, | ||
gsize n_fields, | ||
gpointer user_data) | ||
{ | ||
const char *log_domain = NULL; | ||
const char *message = NULL; | ||
|
||
/* Respect default handling of log levels and domains */ | ||
if (g_log_writer_default_would_drop (log_level, log_domain)) | ||
return G_LOG_WRITER_HANDLED; | ||
|
||
/* Silence specific messages */ | ||
for (gsize i = 0; i < n_fields; i++) | ||
{ | ||
GLogField field = fields[i]; | ||
|
||
if (g_str_equal (field.key, "GLIB_DOMAIN")) | ||
log_domain = field.value; | ||
else if (g_str_equal (field.key, "MESSAGE")) | ||
message = field.value; | ||
|
||
if (log_domain != NULL && message != NULL) | ||
break; | ||
} | ||
|
||
if (workbench_log_ignore (log_domain, log_level, message)) | ||
return G_LOG_WRITER_HANDLED; | ||
|
||
return g_log_writer_standard_streams (log_level, fields, n_fields, user_data); | ||
} | ||
|
||
|
||
/** | ||
* workbench_init: | ||
* | ||
* Initialize the internal library for Workbench. | ||
*/ | ||
void | ||
workbench_init (void) | ||
{ | ||
gsize initialized = 0; | ||
|
||
if (g_once_init_enter (&initialized)) | ||
{ | ||
g_log_set_writer_func (workbench_log_writer, NULL, NULL); | ||
g_once_init_leave (&initialized, TRUE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
// SPDX-FileCopyrightText: Workbench Contributors | ||
// SPDX-FileContributor: Andy Holmes <[email protected]> | ||
|
||
#pragma once | ||
|
||
#if !defined (WORKBENCH_INSIDE) && !defined (WORKBENCH_COMPILATION) | ||
# error "Only <workbench.h> can be included directly." | ||
#endif | ||
|
||
#include <glib.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
WORKBENCH_EXPORT | ||
void workbench_init (void); | ||
|
||
G_END_DECLS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import "./init.js"; | ||
import "./log_handler.js"; | ||
import application from "./application.js"; | ||
|
||
pkg.initGettext(); | ||
|