places-menu: Add nautilus-specific items

Both the "Starred" and "Network" locations are internal to nautilus
and not exposed to gvfs.

We can still support them by opening them explicitly in nautilus,
so add corresponding places if nautilus is installed and set up
as default file manager.

After this change, the list of places should be consistent with
the sidebar in the file manager again.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/issues/522
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/340>
This commit is contained in:
Florian Müllner
2024-10-16 14:38:09 +00:00
committed by Marge Bot
parent 8a62e491a8
commit a81f4f4885
+34
View File
@@ -123,6 +123,20 @@ class PlaceInfo extends EventEmitter {
}
}
class NautilusSpecialInfo extends PlaceInfo {
constructor(file, name, icon) {
super('special', file, name, icon);
const appSystem = Shell.AppSystem.get_default();
this._app = appSystem.lookup_app('org.gnome.Nautilus.desktop');
}
launch(timestamp) {
const launchContext = global.create_app_launch_context(timestamp, -1);
this._app.appInfo.launch([this.file], launchContext);
}
}
class PlaceDeviceInfo extends PlaceInfo {
_init(kind, mount) {
this._mount = mount;
@@ -288,6 +302,12 @@ export class PlacesManager extends EventEmitter {
this._places.special.forEach(p => p.destroy());
this._places.special = [];
const appSystem = Shell.AppSystem.get_default();
const nautilusApp = appSystem.lookup_app('org.gnome.Nautilus.desktop');
const defaultFm = Gio.AppInfo.get_default_for_type('inode/directory', true);
const showNautilusSpecials =
nautilusApp && defaultFm && nautilusApp.appInfo.equal(defaultFm);
const homeFile = Gio.File.new_for_path(GLib.get_home_dir());
this._places.special.push(new PlaceInfo(
@@ -302,6 +322,13 @@ export class PlacesManager extends EventEmitter {
_('Recent')));
}
if (showNautilusSpecials) {
this._places.special.push(new NautilusSpecialInfo(
Gio.File.new_for_uri('starred:///'),
_('Starred'),
'starred-symbolic'));
}
if (this._settings.get_boolean('show-desktop-icons')) {
const desktopPath = GLib.get_user_special_dir(
GLib.UserDirectory.DIRECTORY_DESKTOP);
@@ -315,6 +342,13 @@ export class PlacesManager extends EventEmitter {
}
}
if (showNautilusSpecials) {
this._places.special.push(new NautilusSpecialInfo(
Gio.File.new_for_uri('x-network-view:///'),
_('Network'),
'network-workgroup-symbolic'));
}
this._places.special.push(new PlaceInfo(
'special',
Gio.File.new_for_uri('trash:///'),