Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GNOME 42 - possible fix for dropdowns for some users #7

Open
wants to merge 2 commits into
base: GNOME-42
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 64 additions & 73 deletions [email protected]/menuitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
var 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"
);