Skip to content

Commit 724be54

Browse files
Add support for triggering notifications on WPE
Implement registerNotifyCallback via filesystem watch Original from 2.28 pull request: #1039
1 parent c0422ff commit 724be54

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Source/WebCore/PAL/pal/Logging.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
#if PLATFORM(COCOA)
3232
#include <notify.h>
3333
#include <wtf/BlockPtr.h>
34+
#elif PLATFORM(WPE)
35+
#include <glib.h>
36+
#include <gio/gio.h>
37+
#include <wtf/FileSystem.h>
38+
#include <wtf/glib/GRefPtr.h>
3439
#endif
3540

3641
namespace PAL {
@@ -42,6 +47,25 @@ void registerNotifyCallback(ASCIILiteral notifyID, Function<void()>&& callback)
4247
notify_register_dispatch(notifyID.characters(), &token, dispatch_get_main_queue(), makeBlockPtr([callback = WTFMove(callback)](int) {
4348
callback();
4449
}).get());
50+
#elif PLATFORM(WPE)
51+
using namespace FileSystem;
52+
53+
// Triggers callback with "touch <user config dir>/notify/<notifyID>".
54+
CString notifyFilePath = fileSystemRepresentation(pathByAppendingComponents(StringView::fromLatin1(g_get_user_config_dir()), {"notify"_s, notifyID}));
55+
GRefPtr<GFile> notifyFile = adoptGRef(g_file_new_for_path(notifyFilePath.data()));
56+
GFileMonitor* monitor = g_file_monitor_file(notifyFile.get(), G_FILE_MONITOR_NONE, nullptr, nullptr);
57+
58+
g_signal_connect(monitor, "changed", G_CALLBACK(+[](GFileMonitor*, GFile* file, GFile*, GFileMonitorEvent event, WTF::Function<void()> *callback) {
59+
const char *path = g_file_get_path(file);
60+
if ((nullptr == path) || !g_file_test(path, G_FILE_TEST_EXISTS)) {
61+
return;
62+
}
63+
if ((G_FILE_MONITOR_EVENT_CREATED == event) || (G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED == event)) {
64+
(*callback)();
65+
}
66+
// We are not releasing the allocated memory for the Function object, as this code will get called each time the signal is raised
67+
// No "unregisterNotifyCallback" available to do proper cleanup (signal disconnection and memory release)
68+
}), new WTF::Function<void()>(WTFMove(callback)));
4569
#else
4670
UNUSED_PARAM(notifyID);
4771
UNUSED_PARAM(callback);

0 commit comments

Comments
 (0)