-
Notifications
You must be signed in to change notification settings - Fork 31
core/desktopentry: add file system watcher for desktop entry directories #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
I'm generally conflicted on this one because I prefer state change notifications to manually triggered scanning, which often leads to polling.
Looks like its just a simple directory watch, but it likely has to be recursive on every potential desktop entry dir, otherwise it's unlikely to handle nix generation switches and such. This is the general direction I'd like to take it in. No pressure on you to implement it if you don't want to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you've marked it as WIP. Partial review
src/core/desktopentrymonitor.cpp
Outdated
void DesktopEntryMonitor::addDirectoryHierarchy(const QString& dirPath) { | ||
this->scanAndWatch(dirPath); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
src/core/desktopentrymonitor.cpp
Outdated
this->watcher = new QFileSystemWatcher(this); | ||
this->debounceTimer = new QTimer(this); | ||
this->debounceTimer->setSingleShot(true); | ||
this->debounceTimer->setInterval(500); // 500ms debounce |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
500ms is unreasonably long for a debounce
src/core/desktopentrymonitor.cpp
Outdated
connect( | ||
this->watcher, | ||
&QFileSystemWatcher::directoryChanged, | ||
this, | ||
&DesktopEntryMonitor::onDirectoryChanged | ||
); | ||
connect( | ||
this->watcher, | ||
&QFileSystemWatcher::fileChanged, | ||
this, | ||
&DesktopEntryMonitor::onFileChanged | ||
); | ||
connect(this->debounceTimer, &QTimer::timeout, this, &DesktopEntryMonitor::processChanges); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QObject::connect
src/core/desktopentrymonitor.cpp
Outdated
} | ||
|
||
void DesktopEntryMonitor::scanAndWatch(const QString& dirPath) { | ||
QDir dir(dirPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disallowed style, use auto
this->scanAndWatch(dirPath); | ||
} | ||
|
||
void DesktopEntryMonitor::scanAndWatch(const QString& dirPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scanAndWatch + all the various change handlers share a lot of the code. consider initialization to be a diff from an empty set of entries and share the code.
src/core/desktopentrymonitor.cpp
Outdated
if (watchedFile.startsWith(path + "/") || watchedFile == path) { | ||
this->watcher->removePath(watchedFile); | ||
this->fileTimestamps.remove(watchedFile); | ||
this->queueChange(ChangeEvent::Removed, watchedFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The debounce is not used in a logical way. If you are going to debounce, it should guard re-scanning directories, not model updates.
src/core/desktopentrymonitor.cpp
Outdated
for (auto it = this->watchedFiles.begin(); it != this->watchedFiles.end();) { | ||
const QString& watchedFile = *it; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we tracking watched files, the fs watcher already does that
src/core/desktopentrymonitor.cpp
Outdated
return; | ||
} | ||
|
||
QList<QString> currentFiles = dir.entryList({"*.desktop"}, QDir::Files); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto
@outfoxxed I addressed the comments, I had it initially watching .desktop files and then decided against it, to just watch the directories and rescan when there's a change instead. Sorry for the confusion, not wip anymore - ready for review |
De-dupe code paths to scanAndWatch function, Optimize lookups by using a QSet, remove paths from watcher if deleted
- Create less fs watchers - Just re-scan when a directory containing .desktop files changes
DesktopEntries only scans one time~~, and doesnt expose scanning functions to QML. This adds a
rescan
function, a signal for applications changed. It just allows a nicer launcher that doesn't get stale.~~This adds:
DesktopUtils
which had a common function for locating.desktop
filesDesktopEntryMonitor
which implements QFileSystemWatcherDesktopEntryManager
and add a new signalapplicationsChanged