Skip to content

Commit c65d80a

Browse files
committed
menu@cinnamon.org: Replace "Uninstall" context menu item with "App Info"
"Uninstall" calls cinnamon-remove-application, a simple mint only script. Replace with "App Info" to open mintinstall or pamac-manager on the app details page so user can view an app's details and optionally uninstall using the OS's software manager.
1 parent 347c39c commit c65d80a

2 files changed

Lines changed: 87 additions & 9 deletions

File tree

files/usr/share/cinnamon/applets/menu@cinnamon.org/appUtils.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const Cinnamon = imports.gi.Cinnamon;
22
const CMenu = imports.gi.CMenu;
3+
const Gio = imports.gi.Gio;
4+
const GLib = imports.gi.GLib;
5+
const Util = imports.misc.util;
36

47
let appsys = Cinnamon.AppSystem.get_default();
58

@@ -115,3 +118,68 @@ function loadDirectory(dir, top_dir, apps) {
115118
}
116119
return has_entries;
117120
}
121+
122+
function _launchMintinstall(pkgName) {
123+
Util.spawn(["mintinstall", "show", pkgName]);
124+
}
125+
126+
// launch mintinstall on app page
127+
function launchMintinstallForApp(app) {
128+
if (app.get_is_flatpak()) {
129+
const pkgName = app.get_flatpak_app_id();
130+
_launchMintinstall(pkgName);
131+
} else {
132+
const filePath = app.desktop_file_path;
133+
if (!filePath) return;
134+
135+
const proc = Gio.Subprocess.new(
136+
['dpkg', '-S', filePath],
137+
Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE
138+
);
139+
proc.communicate_utf8_async(null, null, (obj, res) => {
140+
try {
141+
let [success, stdout, stderr] = obj.communicate_utf8_finish(res);
142+
if (success && stdout) {
143+
const foundPkg = stdout.split(':')[0].trim();
144+
_launchMintinstall(foundPkg);
145+
}
146+
} catch (e) {
147+
global.logError("dpkg check failed: " + e.message);
148+
}
149+
});
150+
}
151+
}
152+
153+
function _launchPamac(pkgName) {
154+
Util.spawn(["pamac-manager", `--details=${pkgName}`]);
155+
}
156+
157+
// launch pamac-manager on app page
158+
function launchPamacForApp(app) {
159+
if (app.get_is_flatpak()) {
160+
// pamac-manager doesn't open on page of flatpak apps even if flatpak
161+
// is enabled but let's launch it anyway so user can search for it.
162+
const pkgName = app.get_flatpak_app_id();
163+
_launchPamac(pkgName);
164+
} else {
165+
const filePath = app.desktop_file_path;
166+
if (!filePath) return;
167+
168+
const proc = Gio.Subprocess.new(
169+
['pacman', '-Qqo', filePath],
170+
Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE
171+
);
172+
proc.communicate_utf8_async(null, null, (obj, res) => {
173+
try {
174+
let [success, stdout, stderr] = obj.communicate_utf8_finish(res);
175+
if (success && stdout) {
176+
const foundPkg = stdout.trim();
177+
_launchPamac(foundPkg);
178+
}
179+
} catch (e) {
180+
global.logError("pacman check failed: " + e.message);
181+
}
182+
});
183+
}
184+
}
185+

files/usr/share/cinnamon/applets/menu@cinnamon.org/applet.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,17 @@ class ApplicationContextMenuItem extends PopupMenu.PopupBaseMenuItem {
423423
this._action = "add_to_favorites";
424424
closeMenu = false;
425425
break;
426+
case "app_info":
427+
if (this._appButton.applet._mintinstallAvailable) {
428+
AppUtils.launchMintinstallForApp(this._appButton.app);
429+
} else if (this._appButton.applet._pamacManagerAvailable) {
430+
AppUtils.launchPamacForApp(this._appButton.app);
431+
}
432+
closeMenu = true;
433+
break;
426434
case "app_properties":
427435
Util.spawnCommandLine("cinnamon-desktop-editor -mlauncher -o" + GLib.shell_quote(this._appButton.app.get_app_info().get_filename()));
428436
break;
429-
case "uninstall":
430-
Util.spawnCommandLine("/usr/bin/cinnamon-remove-application '" + this._appButton.app.get_app_info().get_filename() + "'");
431-
break;
432437
case "offload_launch":
433438
try {
434439
this._appButton.app.launch_offloaded(0, [], -1);
@@ -530,13 +535,17 @@ class GenericApplicationButton extends SimpleMenuItem {
530535

531536
const appinfo = this.app.get_app_info();
532537

533-
if (appinfo.get_filename() != null) {
534-
menuItem = new ApplicationContextMenuItem(this, _("Properties"), "app_properties", "xsi-document-properties-symbolic");
535-
menu.addMenuItem(menuItem);
538+
if (this.applet._pamacManagerAvailable || this.applet._mintinstallAvailable) {
539+
const filePath = this.app.desktop_file_path;
540+
// Software managers usually only know of system installed apps.
541+
if (!filePath.startsWith("/home/") && !filePath.includes("cinnamon-settings")) {
542+
menuItem = new ApplicationContextMenuItem(this, _("App Info"), "app_info", "xsi-dialog-information-symbolic");
543+
menu.addMenuItem(menuItem);
544+
}
536545
}
537546

538-
if (this.applet._canUninstallApps) {
539-
menuItem = new ApplicationContextMenuItem(this, _("Uninstall"), "uninstall", "xsi-edit-delete");
547+
if (appinfo.get_filename() != null) {
548+
menuItem = new ApplicationContextMenuItem(this, _("Properties"), "app_properties", "xsi-document-properties-symbolic");
540549
menu.addMenuItem(menuItem);
541550
}
542551

@@ -1229,7 +1238,8 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
12291238
this._activeActor = null;
12301239
this._knownApps = new Set(); // Used to keep track of apps that are already installed, so we can highlight newly installed ones
12311240
this._appsWereRefreshed = false;
1232-
this._canUninstallApps = GLib.file_test("/usr/bin/cinnamon-remove-application", GLib.FileTest.EXISTS);
1241+
this._pamacManagerAvailable = GLib.find_program_in_path("pamac-manager");
1242+
this._mintinstallAvailable = GLib.find_program_in_path("mintinstall");
12331243
this.RecentManager = DocInfo.getDocManager();
12341244
this.privacy_settings = new Gio.Settings( {schema_id: PRIVACY_SCHEMA} );
12351245
this.noRecentDocuments = true;

0 commit comments

Comments
 (0)