Skip to content

Commit

Permalink
🐛 Rebind shortcuts after logout / login
Browse files Browse the repository at this point in the history
  • Loading branch information
Schneegans committed May 13, 2024
1 parent 568a1c9 commit fe3dcd7
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ const DBUS_INTERFACE = `

export default class KandoIntegration extends Extension {

constructor(metadata) {
super(metadata);

// This set contains all currently bound shortcuts. We will use it to re-bind all
// shortcuts when the extension is re-enabled.
this._currentShortcuts = new Set();
}

// Exports the DBus interface.
enable() {
this._dbus = Gio.DBusExportedObject.wrapJSObject(DBUS_INTERFACE, this);
Expand All @@ -62,6 +70,10 @@ export default class KandoIntegration extends Extension {
this._shortcuts.connect('activated', (s, shortcut) => {
this._dbus.emit_signal('ShortcutPressed', new GLib.Variant('(s)', [shortcut]));
});

this._currentShortcuts.forEach((shortcut) => {
this.BindShortcut(shortcut);
});
}

// Unbinds all shortcuts and unexports the DBus interface.
Expand Down Expand Up @@ -110,12 +122,24 @@ export default class KandoIntegration extends Extension {
// Binds the given shortcut. When it's pressed, the "ShortcutPressed" signal will be
// emitted.
BindShortcut(shortcut) {
return this._shortcuts.bind(shortcut);
const success = this._shortcuts.bind(shortcut);

if (success) {
this._currentShortcuts.add(shortcut);
}

return success;
}

// Unbinds a previously bound shortcut.
UnbindShortcut(shortcut) {
return this._shortcuts.unbind(shortcut);
const success = this._shortcuts.unbind(shortcut);

if (success) {
this._currentShortcuts.delete(shortcut);
}

return success;
}

// Unbinds all previously bound shortcuts.
Expand Down

0 comments on commit fe3dcd7

Please sign in to comment.