This repository was archived by the owner on Dec 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.js
More file actions
84 lines (72 loc) · 3.34 KB
/
extension.js
File metadata and controls
84 lines (72 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { Extension, gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as AppDisplay from 'resource:///org/gnome/shell/ui/appDisplay.js';
import Gio from 'gi://Gio';
export default class OpenDesktopLocationExtension extends Extension {
constructor(metadata) {
super(metadata);
this._originalPopupMenu = null;
this._customMenuItemFolder = null;
this._customMenuItemFile = null;
}
enable() {
// Save the original popupMenu function to the prototype
if (!this._originalPopupMenu) {
this._originalPopupMenu = AppDisplay.AppIcon.prototype.popupMenu;
}
const originalPopupMenu = this._originalPopupMenu;
// Since there is not proper API to add context menu functions to the AppIcons, we'll have to patch the popupMenu function instead
AppDisplay.AppIcon.prototype.popupMenu = function (side = imports.gi.St.Side.LEFT) {
originalPopupMenu.call(this, side);
if (!this._menu) {
console.log('No context menu found for the app icon.');
return false;
}
const desktopInfo = this.app.get_app_info();
const desktopFilePath = desktopInfo?.get_filename();
if (!desktopFilePath) {
console.log('No .desktop file found for the selected app.');
return;
}
// Open folder action
if (!this._customMenuItemFolder) {
this._customMenuItemFolder = new PopupMenu.PopupMenuItem(_('Open .desktop location'));
this._customMenuItemFolder.connect('activate', () => {
if (Main.overview.visible) {
Main.overview.hide();
}
const file = Gio.File.new_for_path(desktopFilePath);
const fileManager = Gio.AppInfo.get_default_for_type('inode/directory', false);
if (file && fileManager) {
console.log(`Opening file location: ${file.get_uri()}`);
fileManager.launch([file], null);
}
});
this._menu.addMenuItem(this._customMenuItemFolder);
}
// Open file action
if(!this._customMenuItemFile) {
this._customMenuItemFile = new PopupMenu.PopupMenuItem(_('Open .desktop file'));
this._customMenuItemFile.connect('activate', () => {
if (Main.overview.visible) {
Main.overview.hide();
}
const file = Gio.File.new_for_path(desktopFilePath);
if (file) {
console.log(`Opening file: ${file.get_uri()}`);
Gio.AppInfo.launch_default_for_uri(file.get_uri(), null);
}
});
this._menu.addMenuItem(this._customMenuItemFile);
}
};
}
disable() {
// Restore the original popupMenu method
if (this._originalPopupMenu) {
AppDisplay.AppIcon.prototype.popupMenu = this._originalPopupMenu;
this._originalPopupMenu = null;
}
}
}