Skip to content

Commit

Permalink
Merge pull request #127 from mwilck/master
Browse files Browse the repository at this point in the history
Support for GNOME 3.26 - 3.38, and GNOME 40
  • Loading branch information
p-e-w authored Dec 10, 2021
2 parents fcb4751 + 2eb03a7 commit 2f43228
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 73 deletions.
10 changes: 6 additions & 4 deletions [email protected]/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var ArgosButton = new Lang.Class({

this._lineView = new ArgosLineView();
this._lineView.setMarkup("<small><i>" + GLib.markup_escape_text(file.get_basename(), -1) + " ...</i></small>");
this.add_actor(this._lineView);
Utilities.getActor(this).add_actor(this._lineView);

this._isDestroyed = false;

Expand Down Expand Up @@ -136,9 +136,9 @@ var ArgosButton = new Lang.Class({
this._cycleTimeout = null;
}

this.visible = buttonLines.length > 0 || !dropdownMode;
Utilities.getActor(this).visible = buttonLines.length > 0 || !dropdownMode;

if (!this.visible)
if (!Utilities.getActor(this).visible)
return;

if (buttonLines.length === 0) {
Expand Down Expand Up @@ -191,7 +191,9 @@ var ArgosButton = new Lang.Class({
menuItem.actor.insert_child_below(lineView, menuItem.label);
menuItem.label.visible = false;
menus[dropdownLines[i + 1].menuLevel] = menuItem.menu;
} else if ((i + 1) < dropdownLines.length && dropdownLines[i + 1].menuLevel === dropdownLines[i].menuLevel &&
} else if ((i + 1) < dropdownLines.length &&
dropdownLines[i + 1].menuLevel === dropdownLines[i].menuLevel &&
dropdownLines[i + 1].hasOwnProperty("alternate") &&
dropdownLines[i + 1].alternate === "true") {
menuItem = new ArgosMenuItem(this, dropdownLines[i], dropdownLines[i + 1]);
// Skip alternate line
Expand Down
137 changes: 77 additions & 60 deletions [email protected]/menuitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,86 @@ const Lang = imports.lang;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const PopupMenu = imports.ui.popupMenu;
const AltSwitcher = imports.ui.status.system.AltSwitcher;

const Extension = imports.misc.extensionUtils.getCurrentExtension();
const ArgosLineView = Extension.imports.lineview.ArgosLineView;
const Utilities = Extension.imports.utilities;
const AltSwitcher = Utilities.AltSwitcher;

var ArgosMenuItem = class extends PopupMenu.PopupBaseMenuItem {
constructor(button, line, alternateLine) {
let hasAction = line.hasAction || (typeof alternateLine !== "undefined" && alternateLine.hasAction);

super({
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 (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();
// "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);

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"
);
13 changes: 11 additions & 2 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
"name": "Argos",
"description": "Create GNOME Shell extensions in seconds",
"url": "https://github.com/p-e-w/argos",
"version": 3,
"shell-version": ["3.32"]
"shell-version": [
"3.26",
"3.28",
"3.30",
"3.32",
"3.34",
"3.36",
"3.38",
"40",
"41"
]
}
Loading

0 comments on commit 2f43228

Please sign in to comment.