This doesn’t fix the issue mentioned above (but fixes another one that is irrelevant in this topic)
As you can see I had to replace %20 with space, which breaks files/folders that actually contain %20. My question is if there’s a better way of doing this.
Now, the other issue I finally got what’s causing it, but I don’t know how to proper fix it. The problem is the method get_background_items() (see original py file in the first post). This method is necessary to process clicks on the current folder, but it breaks when clicking on a subfolder. Any ideas?
Running nautilus like this is a really bad approach. And, we have a better solution already!
Just go to Other Locations, then Connect to Server with the admin:/// URL. After that, add a bookmark for that URL and rename it.
Once you do that, you can simply browse to the file system as administrator, only running a minimal amount of code as root. Making everything much safer! Every time you open a new file in an application, you’ll be re-prompted to authenticate, so it is still not possible for other applications to access things incorrectly.
Now, going back to the start. Don’t run pkexec-script to launch nautilus. Instead, just open nautilus with the admin:// scheme rather than file://.
(Right, I didn’t realise you were explicitly avoiding using admin://. I can only stress that it is a bad idea to do that.)
I’m not sure what the issue is? get_background_items is for when the “background” - i.e. the folder itself - is clicked rather than any items in the folder.
The issue is when trying to open a subfolder as root so this get_background_items() is also triggered and it messes with get_file_items() in such way that the result is having the current folder being opened as root, and not the subfolder. I know that because I debugged the script and also because if I remove get_background_items() method then subfolders open as root normally.