From 7611acbc631e70af5ca11d85a2903c9ec9f89965 Mon Sep 17 00:00:00 2001 From: Ram Mehta Date: Sun, 8 Mar 2020 15:09:12 -0400 Subject: [PATCH 1/2] Use registerClass to make plugin compatible with gnome 3.36. --- argos@pew.worldwidemann.com/menuitem.js | 137 +++++++++++------------- 1 file changed, 64 insertions(+), 73 deletions(-) diff --git a/argos@pew.worldwidemann.com/menuitem.js b/argos@pew.worldwidemann.com/menuitem.js index 5fa9671..2455a2a 100644 --- a/argos@pew.worldwidemann.com/menuitem.js +++ b/argos@pew.worldwidemann.com/menuitem.js @@ -10,6 +10,7 @@ */ const Lang = imports.lang; +const GObject = imports.gi.GObject; const GLib = imports.gi.GLib; const Gio = imports.gi.Gio; const PopupMenu = imports.ui.popupMenu; @@ -19,80 +20,70 @@ const ArgosLineView = Extension.imports.lineview.ArgosLineView; const Utilities = Extension.imports.utilities; const AltSwitcher = Utilities.AltSwitcher; -// "constructor" aka "init function" for ArgosMenuItem. -// Defined as ordinary function, referencing "this"; these references will -// be resolved by later bind() calls. -// Utilities.MakeSimpleClass() is used below to actually define the class. -const _ArgosMenuItem_init = function(button, line, alternateLine) { - let hasAction = line.hasAction || (typeof alternateLine !== "undefined" && alternateLine.hasAction); - - let altSwitcher = null; - - let lineView = new ArgosLineView(line); - - if (typeof alternateLine === "undefined") { - Utilities.getActor(this).add_child(lineView); - } else { - let alternateLineView = new ArgosLineView(alternateLine); - altSwitcher = new AltSwitcher(lineView, alternateLineView); - lineView.visible = true; - alternateLineView.visible = true; - Utilities.getActor(this).add_child(altSwitcher.actor); - } - - if (hasAction) { - this.connect("activate", Lang.bind(this, function() { - let activeLine = (altSwitcher === null) ? line : altSwitcher.actor.get_child().line; - - if (activeLine.hasOwnProperty("href")) - Gio.AppInfo.launch_default_for_uri(activeLine.href, null); - - if (activeLine.hasOwnProperty("eval")) - eval(activeLine.eval); - - if (activeLine.hasOwnProperty("bash")) { - let argv = []; - - if (activeLine.terminal === "false") { - argv = ["bash", "-c", activeLine.bash]; - } else { - // Run shell immediately after executing the command to keep the terminal window open - // (see http://stackoverflow.com/q/3512055) - argv = ["gnome-terminal", "--", "bash", "-c", activeLine.bash + "; exec ${SHELL:=bash}"]; - } - - let [success, pid] = GLib.spawn_async( - null, argv, null, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, null); +// Menu entry representing a docker container +const ArgosMenuItem = GObject.registerClass( + { + GTypeName: 'ArgosMenuItem' + }, + class extends PopupMenu.PopupBaseMenuItem { + _init(button, line, alternateLine) { + let hasAction = line.hasAction || (typeof alternateLine !== "undefined" && alternateLine.hasAction); + + super._init({ + activate: hasAction, + hover: hasAction, + can_focus: hasAction + }); + + let altSwitcher = null; + + let lineView = new ArgosLineView(line); + + if (typeof alternateLine === "undefined") { + this.actor.add_child(lineView); + } else { + let alternateLineView = new ArgosLineView(alternateLine); + altSwitcher = new AltSwitcher(lineView, alternateLineView); + lineView.visible = true; + alternateLineView.visible = true; + this.actor.add_child(altSwitcher.actor); + } - if (success) { - GLib.child_watch_add(GLib.PRIORITY_DEFAULT_IDLE, pid, function() { - if (activeLine.refresh === "true") - button.update(); - }); - } - } else if (activeLine.refresh === "true") { - button.update(); + if (hasAction) { + this.connect("activate", Lang.bind(this, function() { + let activeLine = (altSwitcher === null) ? line : altSwitcher.actor.get_child().line; + + if (activeLine.hasOwnProperty("href")) + Gio.AppInfo.launch_default_for_uri(activeLine.href, null); + + if (activeLine.hasOwnProperty("eval")) + eval(activeLine.eval); + + if (activeLine.hasOwnProperty("bash")) { + let argv = []; + + if (activeLine.terminal === "false") { + argv = ["bash", "-c", activeLine.bash]; + } else { + // Run shell immediately after executing the command to keep the terminal window open + // (see http://stackoverflow.com/q/3512055) + argv = ["gnome-terminal", "--", "bash", "-c", activeLine.bash + "; exec ${SHELL:=bash}"]; + } + + let [success, pid] = GLib.spawn_async( + null, argv, null, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, null); + + if (success) { + GLib.child_watch_add(GLib.PRIORITY_DEFAULT_IDLE, pid, function() { + if (activeLine.refresh === "true") + button.update(); + }); + } + } else if (activeLine.refresh === "true") { + button.update(); + } + })); } - })); + } } -} - -// Helper for the init function. This function is passed the same arguments -// as the constuctor and returns an object to be passed to the superclass -// constructor / init function. -const _ArgosMenuItem_superArg = function(button, line, alternateLine) { - let hasAction = line.hasAction || (typeof alternateLine !== "undefined" && alternateLine.hasAction); - - return { - activate: hasAction, - hover: hasAction, - can_focus: hasAction - }; -} - -var ArgosMenuItem = Utilities.makeSimpleClass( - PopupMenu.PopupBaseMenuItem, - _ArgosMenuItem_superArg, - _ArgosMenuItem_init, - "ArgosMenuItem" ); From 1a6d716bcb3eba0aa9f36e754ae9b14d70108564 Mon Sep 17 00:00:00 2001 From: Daniel Britten Date: Wed, 13 Apr 2022 12:26:15 +1200 Subject: [PATCH 2/2] Fix menu not opening, related to error: `Any symbols to be exported from a module must be defined with 'var'`. The full error is: ``` Some code accessed the property 'ArgosMenuItem' on the module 'menuitem'. That property was defined with 'let' or 'const' inside the module. This was previously supported, but is not correct according to the ES6 standard. Any symbols to be exported from a module must be defined with 'var'. The property access will work as previously for the time being, but please fix your code anyway. ``` The menu doesn't seem to open without this change. --- argos@pew.worldwidemann.com/menuitem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/argos@pew.worldwidemann.com/menuitem.js b/argos@pew.worldwidemann.com/menuitem.js index 2455a2a..64dd335 100644 --- a/argos@pew.worldwidemann.com/menuitem.js +++ b/argos@pew.worldwidemann.com/menuitem.js @@ -21,7 +21,7 @@ const Utilities = Extension.imports.utilities; const AltSwitcher = Utilities.AltSwitcher; // Menu entry representing a docker container -const ArgosMenuItem = GObject.registerClass( +var ArgosMenuItem = GObject.registerClass( { GTypeName: 'ArgosMenuItem' },