Closed probonopd closed 3 years ago
@antony-jr do you know how to do this?
Let me take a look at it.
Okay, QFileSystemWatcher only tells when a file is added into a directory or removed from a directory. Now to implement the auto integration. We must maintain a record on the Application we have already integrated into the menu and possibly store that info into some config file or local DB(sql?) and watch for changes in the directory and simply change the local DB and update the menu whenever a file is added or removed from the directories that we are watching.
If I implement this now without the DB part then everything will be in memory and the whole process is done on the startup of the Menu bar. For now if you have like 20 Apps or so it won't seem like a big thing because of our modern hardware. But if we are going to keep 100+ Apps, You will definitely see the degrade in performance. And even heavy usage of memory.
So I need to know how are you aiming to keep record of your application? I think KDE and Gnome uses a combination of config and local dbs? I have no idea.
Currently, no database is implemented yet. I originally thought one would be needed, but when I implemented https://github.com/helloSystem/launch (which scans well-known locations for applications) I added a timer to count how long it takes... in most cases around 10ms, which I think is accaptable.
So all I need is the System menu to get re-generated (like it is done when the menu is started) whenever something changes in one of the directories watched by the QFileSystemWatcher.
If things prove to be too slow, we can always introduce a database later on. (It should be shared with https://github.com/helloSystem/launch.) Having a database has its own downsides, e.g., we would need to make sure it is always in sync with what is going on in the filesystem.
Okay let me send you a PR.
@antony-jr do you think you might still be able to send that PR? Would really appreciate it. Thanks a ton.
@antony-jr do you think you might still be able to send that PR? Would really appreciate it. Thanks a ton.
My computer is currently out of order, Maybe in three days when I buy a new one and setup my distro? I really like to help though. :)
Could it be as easy as calling
when we get notified by QFileSystemWatcher?
Could it be as easy as calling
when we get notified by QFileSystemWatcher?
I don't think that's right, Working on this right now so please wait.
Please test https://github.com/helloSystem/Menu/pull/43
Hello @antony-jr I think I succeeded adding the QFileSystemWatcher
in the way I would like to, but now we need to find a way to make this function do something:
It basically should rebuild the whole System menu.
Do you know how to do that?
Hello @antony-jr I think I succeeded adding the
QFileSystemWatcher
in the way I would like to, but now we need to find a way to make this function do something:It basically should rebuild the whole System menu.
Do you know how to do that?
Yes I was thinking about rebuilding the menu itself on every update. But I used QFileSystemModel so I have to replace that to get which directories have added files and run a check on finding which was changed and rebuild the System Menu.
Is there an easier way without a QFileSystemModel?
Is there an easier way without a QFileSystemModel?
Yes it is QFileSystemWatcher, both are very similar and QFileSystemModel uses QFileSystemWatcher internally. Only difference is that QFileSystemModel exactly tells the file which was added in a directory(with the path of the new file). But with QFileSystemWatcher we only get the directory in which some file was added or deleted or modified, So we have to check our registered application and the filesystem to find which was newly added and then rebuild the menu. When a application is removed we have to do the same thing again.
My approach is much simpler: Rather than trying to figure out what has changed, just throw away the entire 'System' menu and rebuild it from scratch (in the same way like when the application is started initially). This happens so infrequently that optimizing for speed is not important here.
The only thing I need help with: How to rebuild the entire 'System' menu?
My approach is much simpler: Rather than trying to figure out what has changed, just throw away the entire 'System' menu and rebuild it from scratch (in the same way like when the application is started initially). This happens so infrequently that optimizing for speed is not important here.
The only thing I need help with: How to rebuild the entire 'System' menu?
That's not hard. Have to make it async so that it won't block the GUI thread, that's all.
Could you help me there please? That'd be great
The System menu now gets populated based on the filesystem structure on disk. E.g., you put an app into
/Applications
and it will show up in the menu.Currently one has to restart the menu for changes to take effect.
Hence we should find a way to automatically update the System menu using QFileSystemWatcher whenever something changes in the directories that are put in the System menu: