Skip to content

Commit

Permalink
🔧 Keep a reference to the Settings object
Browse files Browse the repository at this point in the history
  • Loading branch information
Schneegans committed Jun 7, 2024
1 parent 8b9ef9e commit 9fb3d16
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export default class KandoIntegration extends Extension {
});

// Re-bind all shortcuts that were bound before the extension was disabled.
const shortcuts = this.getSettings().get_strv('shortcuts');
this._settings = this.getSettings();
this._settings.get_strv('shortcuts');
shortcuts.forEach((shortcut) => {
this._shortcuts.bind(shortcut);
});
Expand All @@ -83,6 +84,8 @@ export default class KandoIntegration extends Extension {
this._shortcuts.destroy();
this._shortcuts = null;

this._settings = null;

this._inputManipulator = null;
}

Expand Down Expand Up @@ -124,9 +127,9 @@ export default class KandoIntegration extends Extension {
const success = this._shortcuts.bind(shortcut);

if (success) {
const shortcuts = this.getSettings().get_strv('shortcuts');
const shortcuts = this._settings.get_strv('shortcuts');
shortcuts.push(shortcut);
this.getSettings().set_strv('shortcuts', shortcuts);
this._settings.set_strv('shortcuts', shortcuts);
}

return success;
Expand All @@ -137,8 +140,8 @@ export default class KandoIntegration extends Extension {
const success = this._shortcuts.unbind(shortcut);

if (success) {
const shortcuts = this.getSettings().get_strv('shortcuts');
this.getSettings().set_strv('shortcuts', shortcuts.filter((s) => s !== shortcut));
const shortcuts = this._settings.get_strv('shortcuts');
this._settings.set_strv('shortcuts', shortcuts.filter((s) => s !== shortcut));
}

return success;
Expand All @@ -147,6 +150,6 @@ export default class KandoIntegration extends Extension {
// Unbinds all previously bound shortcuts.
UnbindAllShortcuts() {
this._shortcuts.unbindAll();
this.getSettings().set_strv('shortcuts', []);
this._settings.set_strv('shortcuts', []);
}
}

0 comments on commit 9fb3d16

Please sign in to comment.