From ef3f5b7da5a09927d156c5e899343a2332f086c6 Mon Sep 17 00:00:00 2001 From: Tom Perez <60866122+tper0700@users.noreply.github.com> Date: Tue, 7 Apr 2020 11:06:07 -0700 Subject: [PATCH 1/8] AppsIcon menu only shows existing apps --- appIcons.js | 89 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/appIcons.js b/appIcons.js index dc737e5..ed131d2 100644 --- a/appIcons.js +++ b/appIcons.js @@ -1741,59 +1741,84 @@ var MyShowAppsIconMenu = Utils.defineClass({ _dtpRedisplay: function() { this.removeAll(); - if (this.sourceActor != Main.layoutManager.dummyCursor) { - let powerSettingsMenuItem = this._appendMenuItem(_('Power options')); - powerSettingsMenuItem.connect('activate', function () { - Util.spawn(['gnome-control-center', 'power']); + function _checkExists(app) { + let cmd = "which '" + app + "'"; + let out = GLib.spawn_command_line_sync(cmd); + + // out contains 1: stdout, 2: stderr, 3: exit code + return out[3] == 0; + } + + function _appendItem(obj, info) { + if (_checkExists(info.cmd[0])) { + let item = obj._appendMenuItem(_(info.title)); + + item.connect('activate', function() { + Util.spawn(info.cmd); + }); + + log(" FOUND: " + info.cmd[0]); + return item; + } else { + log("NOT FOUND: " + info.cmd[0]); + } + + return null; + } + + if (this.sourceActor != Main.layoutManager.dummyCursor) { + let powerSettingsMenuItem = _appendItem(this, { + title: 'Power options', + cmd: ['gnome-control-center', 'power'] }); - let logsMenuItem = this._appendMenuItem(_('Event logs')); - logsMenuItem.connect('activate', function () { - Util.spawn(['gnome-logs']); + let logsMenuItem = _appendItem(this, { + title: 'Event logs', + cmd: ['gnome-logs'] }); - let systemSettingsMenuItem = this._appendMenuItem(_('System')); - systemSettingsMenuItem.connect('activate', function () { - Util.spawn(['gnome-control-center', 'info-overview']); + let systemSettingsMenuItem = _appendItem(this, { + title: 'System', + cmd: ['gnome-control-center', 'info-overview'] }); - let devicesSettingsMenuItem = this._appendMenuItem(_('Device Management')); - devicesSettingsMenuItem.connect('activate', function () { - Util.spawn(['gnome-control-center', 'display']); + let devicesSettingsMenuItem = _appendItem(this, { + title: 'Device Management', + cmd: ['gnome-control-center', 'display'] }); - let disksMenuItem = this._appendMenuItem(_('Disk Management')); - disksMenuItem.connect('activate', function () { - Util.spawn(['gnome-disks']); + let disksMenuItem = _appendItem(this, { + title: 'Disk Management', + cmd: ['gnome-disks'] }); this._appendSeparator(); } - let terminalMenuItem = this._appendMenuItem(_('Terminal')); - terminalMenuItem.connect('activate', function () { - Util.spawn(['gnome-terminal']); + let terminalMenuItem = _appendItem(this, { + title: 'Terminal', + cmd: ['gnome-terminal'] }); - let systemMonitorMenuItem = this._appendMenuItem(_('System monitor')); - systemMonitorMenuItem.connect('activate', function () { - Util.spawn(['gnome-system-monitor']); + let systemMonitorMenuItem = _appendItem(this, { + title: 'System monitor', + cmd: ['gnome-system-monitor'] }); - let filesMenuItem = this._appendMenuItem(_('Files')); - filesMenuItem.connect('activate', function () { - Util.spawn(['nautilus']); + let filesMenuItem = _appendItem(this, { + title: 'Files', + cmd: ['nautilus'] }); - let extPrefsMenuItem = this._appendMenuItem(_('Extensions')); - extPrefsMenuItem.connect('activate', function () { - Util.spawn(["gnome-shell-extension-prefs"]); + let extPrefsMenuItem = _appendItem(this, { + title: 'Extensions', + cmd: ['gnome-shell-extension-prefs'] }); - let gsSettingsMenuItem = this._appendMenuItem(_('Settings')); - gsSettingsMenuItem.connect('activate', function () { - Util.spawn(['gnome-control-center', 'wifi']); - }); + let gsSettingsMenuItem = _appendItem(this, { + title: 'Settings', + cmd: ['gnome-control-center', 'wifi'] + }); this._appendSeparator(); From 537cb2b7ae8057916b01b69776fe6b041e7ae74f Mon Sep 17 00:00:00 2001 From: Tom Perez <60866122+tper0700@users.noreply.github.com> Date: Tue, 7 Apr 2020 11:11:15 -0700 Subject: [PATCH 2/8] Cleanup logging and comment on last fix. --- appIcons.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/appIcons.js b/appIcons.js index ed131d2..941319b 100644 --- a/appIcons.js +++ b/appIcons.js @@ -1741,6 +1741,7 @@ var MyShowAppsIconMenu = Utils.defineClass({ _dtpRedisplay: function() { this.removeAll(); + // true if `which` can find the app function _checkExists(app) { let cmd = "which '" + app + "'"; let out = GLib.spawn_command_line_sync(cmd); @@ -1749,6 +1750,7 @@ var MyShowAppsIconMenu = Utils.defineClass({ return out[3] == 0; } + // Only add menu entries for commands that exist in path function _appendItem(obj, info) { if (_checkExists(info.cmd[0])) { let item = obj._appendMenuItem(_(info.title)); @@ -1756,11 +1758,7 @@ var MyShowAppsIconMenu = Utils.defineClass({ item.connect('activate', function() { Util.spawn(info.cmd); }); - - log(" FOUND: " + info.cmd[0]); return item; - } else { - log("NOT FOUND: " + info.cmd[0]); } return null; From 536e9942573b0924060c591bbf715462590c396d Mon Sep 17 00:00:00 2001 From: Tom Perez <60866122+tper0700@users.noreply.github.com> Date: Mon, 13 Apr 2020 11:43:37 -0700 Subject: [PATCH 3/8] Moving check to utils and removing unused variables --- appIcons.js | 33 ++++++++++++--------------------- utils.js | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/appIcons.js b/appIcons.js index 941319b..1f9e5fc 100644 --- a/appIcons.js +++ b/appIcons.js @@ -1740,19 +1740,10 @@ var MyShowAppsIconMenu = Utils.defineClass({ _dtpRedisplay: function() { this.removeAll(); - - // true if `which` can find the app - function _checkExists(app) { - let cmd = "which '" + app + "'"; - let out = GLib.spawn_command_line_sync(cmd); - - // out contains 1: stdout, 2: stderr, 3: exit code - return out[3] == 0; - } - + // Only add menu entries for commands that exist in path function _appendItem(obj, info) { - if (_checkExists(info.cmd[0])) { + if (Utils.checkExists(info.cmd[0])) { let item = obj._appendMenuItem(_(info.title)); item.connect('activate', function() { @@ -1765,27 +1756,27 @@ var MyShowAppsIconMenu = Utils.defineClass({ } if (this.sourceActor != Main.layoutManager.dummyCursor) { - let powerSettingsMenuItem = _appendItem(this, { + _appendItem(this, { title: 'Power options', cmd: ['gnome-control-center', 'power'] }); - let logsMenuItem = _appendItem(this, { + _appendItem(this, { title: 'Event logs', cmd: ['gnome-logs'] }); - let systemSettingsMenuItem = _appendItem(this, { + _appendItem(this, { title: 'System', cmd: ['gnome-control-center', 'info-overview'] }); - let devicesSettingsMenuItem = _appendItem(this, { + _appendItem(this, { title: 'Device Management', cmd: ['gnome-control-center', 'display'] }); - let disksMenuItem = _appendItem(this, { + _appendItem(this, { title: 'Disk Management', cmd: ['gnome-disks'] }); @@ -1793,27 +1784,27 @@ var MyShowAppsIconMenu = Utils.defineClass({ this._appendSeparator(); } - let terminalMenuItem = _appendItem(this, { + _appendItem(this, { title: 'Terminal', cmd: ['gnome-terminal'] }); - let systemMonitorMenuItem = _appendItem(this, { + _appendItem(this, { title: 'System monitor', cmd: ['gnome-system-monitor'] }); - let filesMenuItem = _appendItem(this, { + _appendItem(this, { title: 'Files', cmd: ['nautilus'] }); - let extPrefsMenuItem = _appendItem(this, { + _appendItem(this, { title: 'Extensions', cmd: ['gnome-shell-extension-prefs'] }); - let gsSettingsMenuItem = _appendItem(this, { + _appendItem(this, { title: 'Settings', cmd: ['gnome-control-center', 'wifi'] }); diff --git a/utils.js b/utils.js index 6757f77..6415933 100644 --- a/utils.js +++ b/utils.js @@ -26,6 +26,7 @@ const Config = imports.misc.config; const GdkPixbuf = imports.gi.GdkPixbuf const Gi = imports._gi; const Gio = imports.gi.Gio; +const GLib = imports.gi.GLib; const GObject = imports.gi.GObject; const Gtk = imports.gi.Gtk; const Meta = imports.gi.Meta; @@ -875,4 +876,16 @@ var drawRoundedLine = function(cr, x, y, width, height, isRoundLeft, isRoundRigh if (stroke != null) cr.setSource(stroke); cr.stroke(); -} \ No newline at end of file +} + +/** + * Check if an app exists in the system. + * Depends on "which" to find app in $PATH + */ +function checkExists(app) { + let cmd = "which '" + app + "'"; + let out = GLib.spawn_command_line_sync(cmd); + + // out contains 1: stdout, 2: stderr, 3: exit code + return out[3] == 0; +} From 059a56259cb825b996f001a743ce5b7f1970095f Mon Sep 17 00:00:00 2001 From: Tom Perez <60866122+tper0700@users.noreply.github.com> Date: Fri, 17 Apr 2020 01:15:35 -0700 Subject: [PATCH 4/8] Switch to POSIX "command" for more availability --- appIcons.js | 4 ++-- utils.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appIcons.js b/appIcons.js index 1f9e5fc..856bbb3 100644 --- a/appIcons.js +++ b/appIcons.js @@ -1743,7 +1743,7 @@ var MyShowAppsIconMenu = Utils.defineClass({ // Only add menu entries for commands that exist in path function _appendItem(obj, info) { - if (Utils.checkExists(info.cmd[0])) { + if (Utils.checkIfCommandExists(info.cmd[0])) { let item = obj._appendMenuItem(_(info.title)); item.connect('activate', function() { @@ -1838,4 +1838,4 @@ adjustMenuRedisplay(MyShowAppsIconMenu.prototype); function adjustMenuRedisplay(menuProto) { menuProto[menuRedisplayFunc] = function() { this._dtpRedisplay(menuRedisplayFunc) }; -} \ No newline at end of file +} diff --git a/utils.js b/utils.js index 6415933..c8f80f0 100644 --- a/utils.js +++ b/utils.js @@ -882,8 +882,8 @@ var drawRoundedLine = function(cr, x, y, width, height, isRoundLeft, isRoundRigh * Check if an app exists in the system. * Depends on "which" to find app in $PATH */ -function checkExists(app) { - let cmd = "which '" + app + "'"; +function checkIfCommandExists(app) { + let cmd = "bash -c 'command -v " + app + "'"; let out = GLib.spawn_command_line_sync(cmd); // out contains 1: stdout, 2: stderr, 3: exit code From 39d07f1c0e8123c39f306378d85290f6874b2589 Mon Sep 17 00:00:00 2001 From: Tom Perez <60866122+tper0700@users.noreply.github.com> Date: Fri, 17 Apr 2020 14:51:07 -0700 Subject: [PATCH 5/8] Building AppIconMenu from settings schema --- appIcons.js | 78 ++++++------------- ...shell.extensions.dash-to-panel.gschema.xml | 38 ++++++++- 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/appIcons.js b/appIcons.js index 856bbb3..0f1be45 100644 --- a/appIcons.js +++ b/appIcons.js @@ -1754,62 +1754,34 @@ var MyShowAppsIconMenu = Utils.defineClass({ return null; } + + function _appendList(obj, cmd_list, title_list) { + if (cmd_list.length != title_list.length) { + return; + } + + for (var entry = 0; entry < cmd_list.length; entry++) { + _appendItem(obj, { + title: title_list[entry], + cmd: cmd_list[entry].split(' ') + }); + } - if (this.sourceActor != Main.layoutManager.dummyCursor) { - _appendItem(this, { - title: 'Power options', - cmd: ['gnome-control-center', 'power'] - }); - - _appendItem(this, { - title: 'Event logs', - cmd: ['gnome-logs'] - }); - - _appendItem(this, { - title: 'System', - cmd: ['gnome-control-center', 'info-overview'] - }); - - _appendItem(this, { - title: 'Device Management', - cmd: ['gnome-control-center', 'display'] - }); - - _appendItem(this, { - title: 'Disk Management', - cmd: ['gnome-disks'] - }); - - this._appendSeparator(); + obj._appendSeparator(); } - _appendItem(this, { - title: 'Terminal', - cmd: ['gnome-terminal'] - }); - - _appendItem(this, { - title: 'System monitor', - cmd: ['gnome-system-monitor'] - }); - - _appendItem(this, { - title: 'Files', - cmd: ['nautilus'] - }); - - _appendItem(this, { - title: 'Extensions', - cmd: ['gnome-shell-extension-prefs'] - }); - - _appendItem(this, { - title: 'Settings', - cmd: ['gnome-control-center', 'wifi'] - }); - - this._appendSeparator(); + if (this.sourceActor != Main.layoutManager.dummyCursor) { + _appendList( + this, + Me.settings.get_strv('show-apps-button-context-menu-commands'), + Me.settings.get_strv('show-apps-button-context-menu-titles') + ) + } + _appendList( + this, + Me.settings.get_strv('panel-context-menu-commands'), + Me.settings.get_strv('panel-context-menu-titles') + ) let lockTaskbarMenuItem = this._appendMenuItem(Me.settings.get_boolean('taskbar-locked') ? _('Unlock taskbar') : _('Lock taskbar')); lockTaskbarMenuItem.connect('activate', () => { diff --git a/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml b/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml index acbd651..cc5a50d 100644 --- a/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml +++ b/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml @@ -372,6 +372,42 @@ Animate Show Applications from the desktop Animate Show Applications from the desktop + + ['gnome-control-center power', + 'gnome-logs', + 'gnome-control-center info-overview', + 'gnome-control-center display', + 'gnome-disks'] + Commands to run on Show Apps Menu + Commands to run in the Show Apps button context menu + + + ['Power options', + 'Event logs', + 'System', + 'Device Management', + 'Disk Management'] + Titles to show on Show Apps Menu + Titles to show in the Show Apps button context menu + + + ['gnome-terminal', + 'gnome-system-monitor', + 'nautilus', + 'gnome-shell-extension-prefs', + 'gnome-control-center wifi'] + Commands to run on panel context menu + Commands to run in the panel context menu + + + ['Terminal', + 'System monitor', + 'Files', + 'Extensions', + 'Settings'] + Titles to show on panel context menu + Titles to show in the panel context menu + false Show activities button @@ -1186,7 +1222,7 @@ Show progress bar on app icon Whether to show progress bar overlay on app icon, for supported applications. - + true Show badge count on app icon Whether to show badge count overlay on app icon, for supported applications. From ce32b433101d6bbc6fb465466f1c401ff5e11cdb Mon Sep 17 00:00:00 2001 From: Tom Perez <60866122+tper0700@users.noreply.github.com> Date: Fri, 17 Apr 2020 16:26:04 -0700 Subject: [PATCH 6/8] Caching results of checkIfCommandExists to speed up menu display. --- utils.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/utils.js b/utils.js index c8f80f0..c348631 100644 --- a/utils.js +++ b/utils.js @@ -882,10 +882,20 @@ var drawRoundedLine = function(cr, x, y, width, height, isRoundLeft, isRoundRigh * Check if an app exists in the system. * Depends on "which" to find app in $PATH */ -function checkIfCommandExists(app) { - let cmd = "bash -c 'command -v " + app + "'"; - let out = GLib.spawn_command_line_sync(cmd); +var checkedCommandsMap = new Map(); - // out contains 1: stdout, 2: stderr, 3: exit code - return out[3] == 0; +function checkIfCommandExists(app) { + let answer = checkedCommandsMap.get(app); + if (answer === undefined) { + // Command is a shell built in, use shell to call it. + // Quotes around app value are important. They let command operate + // on the whole value, instead of having shell interpret it. + let cmd = "sh -c 'command -v \"" + app + "\"'"; + let out = GLib.spawn_command_line_sync(cmd); + + // out contains 1: stdout, 2: stderr, 3: exit code + answer = out[3] == 0; + checkedCommandsMap.set(app, answer); + } + return answer; } From 8200a481ea1d65f560a03c82a670418b6b259386 Mon Sep 17 00:00:00 2001 From: Tom Perez <60866122+tper0700@users.noreply.github.com> Date: Fri, 17 Apr 2020 16:40:16 -0700 Subject: [PATCH 7/8] Handling the case where sh is not available and allowing an empty menu --- utils.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils.js b/utils.js index c348631..aa5e618 100644 --- a/utils.js +++ b/utils.js @@ -891,10 +891,14 @@ function checkIfCommandExists(app) { // Quotes around app value are important. They let command operate // on the whole value, instead of having shell interpret it. let cmd = "sh -c 'command -v \"" + app + "\"'"; - let out = GLib.spawn_command_line_sync(cmd); + try { + let out = GLib.spawn_command_line_sync(cmd); + // out contains 1: stdout, 2: stderr, 3: exit code + answer = out[3] == 0; + } catch { + answer = false; + } - // out contains 1: stdout, 2: stderr, 3: exit code - answer = out[3] == 0; checkedCommandsMap.set(app, answer); } return answer; From 20ebb623b8a435cd610dd1ef301764f0e5196e26 Mon Sep 17 00:00:00 2001 From: Tom Perez <60866122+tper0700@users.noreply.github.com> Date: Sun, 19 Apr 2020 21:14:04 -0700 Subject: [PATCH 8/8] Incorporating feedback to address gsettings localization issues. --- appIcons.js | 67 +++++++++++++++++-- ...shell.extensions.dash-to-panel.gschema.xml | 40 ++++------- utils.js | 1 - 3 files changed, 72 insertions(+), 36 deletions(-) diff --git a/appIcons.js b/appIcons.js index 0f1be45..804fe25 100644 --- a/appIcons.js +++ b/appIcons.js @@ -1755,34 +1755,87 @@ var MyShowAppsIconMenu = Utils.defineClass({ return null; } - function _appendList(obj, cmd_list, title_list) { - if (cmd_list.length != title_list.length) { + function _appendList(obj, commandList, titleList) { + if (commandList.length != titleList.length) { return; } - for (var entry = 0; entry < cmd_list.length; entry++) { + for (var entry = 0; entry < commandList.length; entry++) { _appendItem(obj, { - title: title_list[entry], - cmd: cmd_list[entry].split(' ') + title: titleList[entry], + cmd: commandList[entry].split(' ') }); } - - obj._appendSeparator(); } if (this.sourceActor != Main.layoutManager.dummyCursor) { + _appendItem(this, { + title: 'Power options', + cmd: ['gnome-control-center', 'power'] + }); + + _appendItem(this, { + title: 'Event logs', + cmd: ['gnome-logs'] + }); + + _appendItem(this, { + title: 'System', + cmd: ['gnome-control-center', 'info-overview'] + }); + + _appendItem(this, { + title: 'Device Management', + cmd: ['gnome-control-center', 'display'] + }); + + _appendItem(this, { + title: 'Disk Management', + cmd: ['gnome-disks'] + }); + _appendList( this, Me.settings.get_strv('show-apps-button-context-menu-commands'), Me.settings.get_strv('show-apps-button-context-menu-titles') ) + + this._appendSeparator(); } + + _appendItem(this, { + title: 'Terminal', + cmd: ['gnome-terminal'] + }); + + _appendItem(this, { + title: 'System monitor', + cmd: ['gnome-system-monitor'] + }); + + _appendItem(this, { + title: 'Files', + cmd: ['nautilus'] + }); + + _appendItem(this, { + title: 'Extensions', + cmd: ['gnome-shell-extension-prefs'] + }); + + _appendItem(this, { + title: 'Settings', + cmd: ['gnome-control-center', 'wifi'] + }); + _appendList( this, Me.settings.get_strv('panel-context-menu-commands'), Me.settings.get_strv('panel-context-menu-titles') ) + this._appendSeparator(); + let lockTaskbarMenuItem = this._appendMenuItem(Me.settings.get_boolean('taskbar-locked') ? _('Unlock taskbar') : _('Lock taskbar')); lockTaskbarMenuItem.connect('activate', () => { Me.settings.set_boolean('taskbar-locked', !Me.settings.get_boolean('taskbar-locked')); diff --git a/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml b/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml index cc5a50d..d40ca56 100644 --- a/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml +++ b/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml @@ -373,40 +373,24 @@ Animate Show Applications from the desktop - ['gnome-control-center power', - 'gnome-logs', - 'gnome-control-center info-overview', - 'gnome-control-center display', - 'gnome-disks'] - Commands to run on Show Apps Menu - Commands to run in the Show Apps button context menu + [] + Show Apps button context menu commands + Commands to add to the Show Apps button right click menu - ['Power options', - 'Event logs', - 'System', - 'Device Management', - 'Disk Management'] - Titles to show on Show Apps Menu - Titles to show in the Show Apps button context menu + [] + Show Apps button context menu titles + Titles for commands added to Show Apps button right click menu - ['gnome-terminal', - 'gnome-system-monitor', - 'nautilus', - 'gnome-shell-extension-prefs', - 'gnome-control-center wifi'] - Commands to run on panel context menu - Commands to run in the panel context menu + [] + Panel context menu commands + Commands to add to the panel right click menu - ['Terminal', - 'System monitor', - 'Files', - 'Extensions', - 'Settings'] - Titles to show on panel context menu - Titles to show in the panel context menu + [] + Panel context menu titles + Titles for commands added to panel right click menu false diff --git a/utils.js b/utils.js index aa5e618..038379d 100644 --- a/utils.js +++ b/utils.js @@ -880,7 +880,6 @@ var drawRoundedLine = function(cr, x, y, width, height, isRoundLeft, isRoundRigh /** * Check if an app exists in the system. - * Depends on "which" to find app in $PATH */ var checkedCommandsMap = new Map();