mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 23:57:25 +00:00
Userland+LibCore: Update FileWatcher + its users for InodeWatcher 2.0
With the new InodeWatcher API, the old style of creating a watcher per inode will no longer work. Therefore the FileWatcher API has been updated to support multiple watches, and its users have also been refactored to the new style. At the moment, all operations done on a (Blocking)FileWatcher return Result objects, however, this may be changed in the future if it becomes too obnoxious. :^) Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@@ -8,6 +9,7 @@
|
||||
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <Kernel/API/InodeWatcherEvent.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibGUI/Icon.h>
|
||||
#include <LibGUI/Variant.h>
|
||||
@@ -21,12 +23,21 @@ ProjectTemplatesModel::ProjectTemplatesModel()
|
||||
: m_templates()
|
||||
, m_mapping()
|
||||
{
|
||||
auto watcher_or_error = Core::FileWatcher::watch(ProjectTemplate::templates_path());
|
||||
auto watcher_or_error = Core::FileWatcher::create();
|
||||
if (!watcher_or_error.is_error()) {
|
||||
m_file_watcher = watcher_or_error.release_value();
|
||||
m_file_watcher->on_change = [&](auto) {
|
||||
update();
|
||||
};
|
||||
|
||||
auto watch_result = m_file_watcher->add_watch(
|
||||
ProjectTemplate::templates_path(),
|
||||
Core::FileWatcherEvent::Type::ChildCreated
|
||||
| Core::FileWatcherEvent::Type::ChildDeleted);
|
||||
|
||||
if (watch_result.is_error()) {
|
||||
warnln("Unable to watch templates directory, templates will not automatically refresh. Error: {}", watch_result.error());
|
||||
}
|
||||
} else {
|
||||
warnln("Unable to watch templates directory, templates will not automatically refresh. Error: {}", watcher_or_error.error());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user