I’m developing a combo of extension + application, where the GNOME extension waits for a signal from the application to do something and then replies information back to the application. For now I’ve only written the code as a GNOME Extension, but I’m already developing it with the application in mind.
I’ve been trying to use dbus/GActions by following the guide on gjs, however it seems like my “client”-side doesn’t connect to changes in the value even though my “server”-side does. This is a minimum reproducible code:
import GObject from 'gi://GObject';
import St from 'gi://St';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
const Indicator = GObject.registerClass(
class Indicator extends PanelMenu.Button {
_init() {
// Creates a minimum indicator for testing purposes
super._init(0.0, _('My Shiny Indicator'));
this.add_child(new St.Icon({
icon_name: 'face-smile-symbolic',
style_class: 'system-status-icon',
}));
let item = new PopupMenu.PopupMenuItem(_('Show Notification'));
this.menu.addMenuItem(item);
// "Client"-side connects to the state
const remoteGroup = Gio.DBusActionGroup.get(
Gio.DBus.session,
'org.gnome.Shell',
'/guide/gjs/Test');
// The client waits for an update from the server-side
// NOT WORKING
remoteGroup.connect('action-state-changed', (action, value) => {
console.log("I'm not called");
});
// Acts as a button to communicate with the server
item.connect('activate', () => {
remoteGroup.activate_action('paramAction', new GLib.Variant('(s)', ['string']));
});
}
});
export default class IndicatorExampleExtension extends Extension {
enable() {
// Initialize our actions and create a GActionGroup
const stateAction = new Gio.SimpleAction({
name: 'stateAction',
state: GLib.Variant.new_string(''),
});
const paramAction = new Gio.SimpleAction({
name: 'paramAction',
parameter_type: new GLib.VariantType('(s)'),
});
const actionGroup = new Gio.SimpleActionGroup();
actionGroup.add_action(paramAction);
actionGroup.add_action(stateAction);
// "Server"-side is called whenever the value is changed
// WORKS
actionGroup.connect('action-state-changed', (action, value) => {
console.log("I'm called");
});
// Endpoint the "client" reaches to update the state
paramAction.connect('activate', (action, parameter) => {
// I also tried with stateAction.change_state
actionGroup.action_state_changed('stateAction',
new GLib.Variant('s',
"string")
);
});
// Exposes the serverside
this.connection = Gio.DBus.session;
this.groupId = this.connection.export_action_group('/guide/gjs/Test',
actionGroup);
// Builds our testing "client"
this._indicator = new Indicator();
Main.panel.addToStatusArea(this.uuid, this._indicator);
}
disable() {
this._indicator.destroy();
this._indicator = null;
this.connection.unexport_action_group(this.groupId);
}
}
No errors nor anything… Is this a bug? Is it not possible for remoteGroup
to see changes in a dbus value with Gio.DBusActionGroup.get
? Is there another way of doing what I’m trying to accomplish using GNOME libraries?
Thanks in advance <3