Skip to content

Commit e074360

Browse files
filipe-norte-redmagomez
authored andcommitted
Add support for triggering notifications
Implement registerNotifyCallback via filesystem watch Original from 2.28 pull request: #1039
1 parent 78d7d65 commit e074360

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Source/WebCore/PAL/pal/Logging.cpp

Lines changed: 25 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,26 @@ 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()), std::initializer_list<StringView>({ "notify"_s, notifyID })));
55+
56+
GRefPtr<GFile> notifyFile = adoptGRef(g_file_new_for_path(notifyFilePath.data()));
57+
GFileMonitor* monitor = g_file_monitor_file(notifyFile.get(), G_FILE_MONITOR_NONE, nullptr, nullptr);
58+
59+
g_signal_connect(monitor, "changed", G_CALLBACK(+[](GFileMonitor*, GFile* file, GFile*, GFileMonitorEvent event, WTF::Function<void()> *callback) {
60+
const char *path = g_file_get_path(file);
61+
if ((nullptr == path) || !g_file_test(path, G_FILE_TEST_EXISTS)) {
62+
return;
63+
}
64+
if ((G_FILE_MONITOR_EVENT_CREATED == event) || (G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED == event)) {
65+
(*callback)();
66+
}
67+
// We are not releasing the allocated memory for the Function object, as this code will get called each time the signal is raised
68+
// No "unregisterNotifyCallback" available to do proper cleanup (signal disconnection and memory release)
69+
}), new WTF::Function<void()>(WTFMove(callback)));
4570
#else
4671
UNUSED_PARAM(notifyID);
4772
UNUSED_PARAM(callback);

0 commit comments

Comments
 (0)