diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-05-09 17:09:30 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-12 22:38:20 +0200 |
commit | 2159f90e00cdca66eedbbb0807b731c74695e5d8 (patch) | |
tree | e358620308619bc582308f42a0d1ff55df57a25e /Userland/DevTools/HackStudio/Dialogs/ProjectTemplatesModel.cpp | |
parent | fe5ca6ca276ad452a16215031fb395b4f5bef048 (diff) | |
download | serenity-2159f90e00cdca66eedbbb0807b731c74695e5d8.zip |
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>
Diffstat (limited to 'Userland/DevTools/HackStudio/Dialogs/ProjectTemplatesModel.cpp')
-rw-r--r-- | Userland/DevTools/HackStudio/Dialogs/ProjectTemplatesModel.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Userland/DevTools/HackStudio/Dialogs/ProjectTemplatesModel.cpp b/Userland/DevTools/HackStudio/Dialogs/ProjectTemplatesModel.cpp index ea51eef868..64d9367cf7 100644 --- a/Userland/DevTools/HackStudio/Dialogs/ProjectTemplatesModel.cpp +++ b/Userland/DevTools/HackStudio/Dialogs/ProjectTemplatesModel.cpp @@ -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()); } |