Skip to content

Commit dc80763

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 dc80763

2 files changed

Lines changed: 86 additions & 9 deletions

File tree

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const Cinnamon = imports.gi.Cinnamon;
22
const CMenu = imports.gi.CMenu;
3+
const Gio = imports.gi.Gio;
4+
const GLib = imports.gi.GLib;
35

46
let appsys = Cinnamon.AppSystem.get_default();
57

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

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)