From 7b1c0303250e4bc080d3d030e9d8ffd09f55507a Mon Sep 17 00:00:00 2001 From: Julian Schacher Date: Thu, 26 Jan 2023 03:42:56 +0100 Subject: [PATCH] Fix: Don't use `globalThis`, since it won't get g.c. on window close Don't use `globalThis`, since it won't get garbage collected on window close. See here for the relevant review: https://extensions.gnome.org/review/38364 And for the relevant documentation: https://gjs.guide/extensions/review-guidelines/review-guidelines.html#only-use-init-for-initialization --- src/prefs.js | 2 -- src/prefsModules/PrefsBoxOrderListBox.js | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/prefs.js b/src/prefs.js index e74b4f4..309bbc6 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -11,6 +11,4 @@ function buildPrefsWidget() { } function init() { - // Load the settings. - globalThis.settings = ExtensionUtils.getSettings(); } diff --git a/src/prefsModules/PrefsBoxOrderListBox.js b/src/prefsModules/PrefsBoxOrderListBox.js index e3db84f..832c720 100644 --- a/src/prefsModules/PrefsBoxOrderListBox.js +++ b/src/prefsModules/PrefsBoxOrderListBox.js @@ -1,6 +1,5 @@ "use strict"; /* exported PrefsBoxOrderListBox */ -/* global settings */ const Gtk = imports.gi.Gtk; const GObject = imports.gi.GObject; @@ -30,6 +29,9 @@ var PrefsBoxOrderListBox = GObject.registerClass({ constructor(params = {}) { super(params); + // Load the settings. + this._settings = ExtensionUtils.getSettings(); + // Add a placeholder widget for the case, where no GtkListBoxRows are // present. this.set_placeholder(new PrefsBoxOrderListEmptyPlaceholder.PrefsBoxOrderListEmptyPlaceholder()); @@ -42,6 +44,9 @@ var PrefsBoxOrderListBox = GObject.registerClass({ set boxOrder(value) { this._boxOrder = value; + // Load the settings here as well, since a `CONSTRUCT_ONLY` property + // apparently can't access `this._settings`. + const settings = ExtensionUtils.getSettings(); // Get the actual box order for the given box order name from settings. const boxOrder = settings.get_strv(this._boxOrder); // Populate this GtkListBox with GtkListBoxRows for the items of the @@ -67,6 +72,6 @@ var PrefsBoxOrderListBox = GObject.registerClass({ const item = potentialPrefsBoxOrderItemRow.item; currentBoxOrder.push(item); } - settings.set_strv(this.boxOrder, currentBoxOrder); + this._settings.set_strv(this.boxOrder, currentBoxOrder); } });