Skip to content

Commit

Permalink
Merge pull request #150 from p-e-w/WIP-gnome-45
Browse files Browse the repository at this point in the history
GNOME 45 support
  • Loading branch information
mwilck authored Apr 3, 2024
2 parents e2d68ea + ce230ed commit 0449229
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 356 deletions.
72 changes: 37 additions & 35 deletions [email protected]/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@
* (https://gnu.org/licenses/gpl.html)
*/

const Lang = imports.lang;
const GObject = imports.gi.GObject;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Mainloop = imports.mainloop;

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

var ArgosButton = GObject.registerClass({
import GObject from 'gi://GObject';
import GLib from 'gi://GLib';
import Gio from 'gi://Gio';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';

import ArgosLineView from './lineview.js';
import ArgosMenuItem from './menuitem.js';
import * as Utilities from './utilities.js';

const cArgosButton = GObject.registerClass({
GTypeName: "ArgosButton",
},

Expand All @@ -36,41 +33,41 @@ class ArgosButton extends PanelMenu.Button {

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

this._isDestroyed = false;

this._updateTimeout = null;
this._cycleTimeout = null;

this.connect("destroy", Lang.bind(this, this._onDestroy));
this.connect("destroy", this._onDestroy.bind(this));

this._updateRunning = false;

this._update();

if (settings.updateOnOpen) {
this.menu.connect("open-state-changed", Lang.bind(this, function(menu, open) {
if (open)
this.update();
}));
this.menu.connect("open-state-changed", (open) => {
if (open)
this.update();
});
}
}

_onDestroy() {
this._isDestroyed = true;

if (this._updateTimeout !== null)
Mainloop.source_remove(this._updateTimeout);
GLib.source_remove(this._updateTimeout);
if (this._cycleTimeout !== null)
Mainloop.source_remove(this._cycleTimeout);
GLib.source_remove(this._cycleTimeout);

this.menu.removeAll();
}

update() {
if (this._updateTimeout !== null) {
Mainloop.source_remove(this._updateTimeout);
GLib.source_remove(this._updateTimeout);
this._updateTimeout = null;
}

Expand All @@ -89,7 +86,7 @@ class ArgosButton extends PanelMenu.Button {

try {
Utilities.spawnWithCallback(null, [this._file.get_path()], envp, 0, null,
Lang.bind(this, function(standardOutput) {
(standardOutput) => {
this._updateRunning = false;

if (this._isDestroyed)
Expand All @@ -98,13 +95,16 @@ class ArgosButton extends PanelMenu.Button {
this._processOutput(standardOutput.split("\n"));

if (this._updateInterval !== null) {
this._updateTimeout = Mainloop.timeout_add_seconds(this._updateInterval, Lang.bind(this, function() {
this._updateTimeout = null;
this._update();
return false;
}));
this._updateTimeout =
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT,
this._updateInterval,
() => {
this._updateTimeout = null;
this._update();
return false;
});
}
}));
});
} catch (error) {
log("Unable to execute file '" + this._file.get_basename() + "': " + error);
this._updateRunning = false;
Expand Down Expand Up @@ -135,7 +135,7 @@ class ArgosButton extends PanelMenu.Button {
this.menu.removeAll();

if (this._cycleTimeout !== null) {
Mainloop.source_remove(this._cycleTimeout);
GLib.source_remove(this._cycleTimeout);
this._cycleTimeout = null;
}

Expand All @@ -151,11 +151,11 @@ class ArgosButton extends PanelMenu.Button {
} else {
this._lineView.setLine(buttonLines[0]);
let i = 0;
this._cycleTimeout = Mainloop.timeout_add_seconds(3, Lang.bind(this, function() {
this._cycleTimeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 3, () => {
i++;
this._lineView.setLine(buttonLines[i % buttonLines.length]);
return true;
}));
});

for (let j = 0; j < buttonLines.length; j++) {
if (buttonLines[j].dropdown !== "false")
Expand Down Expand Up @@ -214,9 +214,11 @@ class ArgosButton extends PanelMenu.Button {
let menuItem = new PopupMenu.PopupMenuItem(this._file.get_basename(), {
style_class: "argos-menu-item-edit"
});
menuItem.connect("activate", Lang.bind(this, function() {
menuItem.connect("activate", () => {
Gio.AppInfo.launch_default_for_uri("file://" + this._file.get_path(), null);
}));
});
this.menu.addMenuItem(menuItem);
}
});

export default cArgosButton;
2 changes: 2 additions & 0 deletions [email protected]/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,3 +1286,5 @@ var EMOJI = {
"zm": "🇿🇲",
"zw": "🇿🇼"
};

export default EMOJI;
83 changes: 38 additions & 45 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@
* (https://gnu.org/licenses/gpl.html)
*/

const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;

const Extension = imports.misc.extensionUtils.getCurrentExtension();
const ArgosButton = Extension.imports.button.ArgosButton;
const Utilities = Extension.imports.utilities;

let directory;
let directoryMonitor;
let directoryChangedId;
let debounceTimeout = null;
let buttons = [];

function init() {
import GLib from 'gi://GLib';
import Gio from 'gi://Gio';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';

import ArgosButton from './button.js'
import * as Utilities from './utilities.js'

export default class ArgosExtension {

constructor() {
let directoryPath = GLib.build_filenamev([GLib.get_user_config_dir(), "argos"]);

directory = Gio.File.new_for_path(directoryPath);
this.directory = Gio.File.new_for_path(directoryPath);
this.buttons = [];
this.debounceTimeout = null;

if (!directory.query_exists(null)) {
directory.make_directory(null);
if (!this.directory.query_exists(null)) {
this.directory.make_directory(null);

// Create "welcome" script on first run to indicate
// that the extension is installed and working
Expand All @@ -45,50 +41,46 @@ function init() {
'echo "$URL | iconName=help-faq-symbolic href=\'https://$URL\'"\n' +
'echo "$DIR | iconName=folder-symbolic href=\'file://$DIR\'"\n\n';

GLib.file_set_contents(scriptPath, scriptContents);

// Running an external program just to make a file executable is ugly,
// but Gjs appears to be missing bindings for the "chmod" syscall
GLib.spawn_sync(null, ["chmod", "+x", scriptPath], null, GLib.SpawnFlags.SEARCH_PATH, null);
GLib.file_set_contents_full(scriptPath, scriptContents, GLib.FileSetContentsFlags.CONSISTENT, 0o700);
}

// WATCH_MOVES requires GLib 2.46 or later
let monitorFlags = Gio.FileMonitorFlags.hasOwnProperty("WATCH_MOVES") ?
Gio.FileMonitorFlags.WATCH_MOVES : Gio.FileMonitorFlags.SEND_MOVED;
directoryMonitor = directory.monitor_directory(monitorFlags, null);
this.directoryMonitor = this.directory.monitor_directory(monitorFlags, null);
}

function enable() {
addButtons();
enable() {
this.addButtons();

directoryChangedId = directoryMonitor.connect("changed", function(monitor, file, otherFile, eventType) {
removeButtons();
this.directoryChangedId = this.directoryMonitor.connect("changed", (monitor, file, otherFile, eventType) => {
this.removeButtons();

// Some high-level file operations trigger multiple "changed" events in rapid succession.
// Debouncing groups them together to avoid unnecessary updates.
if (debounceTimeout === null) {
debounceTimeout = Mainloop.timeout_add(100, function() {
debounceTimeout = null;
addButtons();
if (this.debounceTimeout === null) {
this.debounceTimeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
this.debounceTimeout = null;
this.addButtons();
return false;
});
}
});
}

function disable() {
directoryMonitor.disconnect(directoryChangedId);
disable() {
this.directoryMonitor.disconnect(this.directoryChangedId);

if (debounceTimeout !== null)
Mainloop.source_remove(debounceTimeout);
if (this.debounceTimeout !== null)
GLib.source_remove(this.debounceTimeout);

removeButtons();
this.removeButtons();
}

function addButtons() {
addButtons() {
let files = [];

let enumerator = directory.enumerate_children(Gio.FILE_ATTRIBUTE_STANDARD_NAME, Gio.FileQueryInfoFlags.NONE, null);
let enumerator = this.directory.enumerate_children(Gio.FILE_ATTRIBUTE_STANDARD_NAME, Gio.FileQueryInfoFlags.NONE, null);

let fileInfo = null;
while ((fileInfo = enumerator.next_file(null)) !== null) {
Expand All @@ -109,14 +101,15 @@ function addButtons() {
for (let i = files.length - 1; i >= 0; i--) {
let settings = Utilities.parseFilename(files[i].get_basename());
let button = new ArgosButton(files[i], settings);
buttons.push(button);
this.buttons.push(button);
Main.panel.addToStatusArea("argos-button-" + i, button, settings.position, settings.box);
}
}

function removeButtons() {
for (let i = 0; i < buttons.length; i++) {
buttons[i].destroy();
removeButtons() {
for (let i = 0; i < this.buttons.length; i++) {
this.buttons[i].destroy();
}
buttons = [];
this.buttons = [];
}
}
18 changes: 10 additions & 8 deletions [email protected]/lineview.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
* (https://gnu.org/licenses/gpl.html)
*/

const GObject = imports.gi.GObject;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const GdkPixbuf = imports.gi.GdkPixbuf;
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;

var ArgosLineView = GObject.registerClass({
import GObject from 'gi://GObject';
import GLib from 'gi://GLib';
import Gio from 'gi://Gio';
import GdkPixbuf from 'gi://GdkPixbuf';
import St from 'gi://St';
import Clutter from 'gi://Clutter';

const cArgosLineView = GObject.registerClass({
GTypeName: "ArgosLineView",
},

Expand Down Expand Up @@ -115,3 +115,5 @@ class ArgosLineView extends St.BoxLayout {
});
}
});

export default cArgosLineView;
Loading

0 comments on commit 0449229

Please sign in to comment.