From 34ba8a58cd7737c343d70c03fde3d3dccebd0e6e Mon Sep 17 00:00:00 2001 From: Julian Schacher Date: Sun, 22 Jan 2023 15:48:35 +0100 Subject: [PATCH] Refactor: Add settings to `globalThis` Do this so that we don't have to get them in each class individually. --- src/prefs.js | 2 ++ src/prefsModules/PrefsBoxOrderListBox.js | 4 +--- src/prefsModules/PrefsBoxOrderListEmptyPlaceholder.js | 2 -- src/prefsModules/PrefsPage.js | 8 +++----- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/prefs.js b/src/prefs.js index 13b326a..da89541 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -11,4 +11,6 @@ function buildPrefsWidget() { } function init() { + // Load the settings. + globalThis.settings = ExtensionUtils.getSettings(); } diff --git a/src/prefsModules/PrefsBoxOrderListBox.js b/src/prefsModules/PrefsBoxOrderListBox.js index ede9020..16c0006 100644 --- a/src/prefsModules/PrefsBoxOrderListBox.js +++ b/src/prefsModules/PrefsBoxOrderListBox.js @@ -19,8 +19,6 @@ var PrefsBoxOrderListBox = GObject.registerClass({ constructor(params = {}, boxOrder) { super(params); - this._settings = ExtensionUtils.getSettings(); - this.boxOrder = boxOrder; } @@ -37,6 +35,6 @@ var PrefsBoxOrderListBox = GObject.registerClass({ const item = potentialPrefsBoxOrderItemRow.item; currentBoxOrder.push(item); } - this._settings.set_strv(this.boxOrder, currentBoxOrder); + settings.set_strv(this.boxOrder, currentBoxOrder); } }); diff --git a/src/prefsModules/PrefsBoxOrderListEmptyPlaceholder.js b/src/prefsModules/PrefsBoxOrderListEmptyPlaceholder.js index 6b160db..60f24be 100644 --- a/src/prefsModules/PrefsBoxOrderListEmptyPlaceholder.js +++ b/src/prefsModules/PrefsBoxOrderListEmptyPlaceholder.js @@ -34,8 +34,6 @@ var PrefsBoxOrderListEmptyPlaceholder = GObject.registerClass({ ownListBox.insert(value, 0); /// Finally save the box orders to settings. - const settings = ExtensionUtils.getSettings(); - settings.set_strv(ownListBox.boxOrder, [value.item]); let updatedBoxOrder = [ ]; diff --git a/src/prefsModules/PrefsPage.js b/src/prefsModules/PrefsPage.js index 31a7dd0..0b5304a 100644 --- a/src/prefsModules/PrefsPage.js +++ b/src/prefsModules/PrefsPage.js @@ -25,8 +25,6 @@ var PrefsPage = GObject.registerClass({ constructor(params = {}) { super(params); - this._settings = ExtensionUtils.getSettings(); - // Scroll up or down, when a Drag-and-Drop operation is in progress and // the user has their cursor either in the upper or lower 10% of this // widget respectively. @@ -73,8 +71,8 @@ var PrefsPage = GObject.registerClass({ gtkListBox.set_placeholder(new PrefsBoxOrderListEmptyPlaceholder.PrefsBoxOrderListEmptyPlaceholder()); }; - initializeGtkListBox(this._settings.get_strv("left-box-order"), this._left_box_order); - initializeGtkListBox(this._settings.get_strv("center-box-order"), this._center_box_order); - initializeGtkListBox(this._settings.get_strv("right-box-order"), this._right_box_order); + initializeGtkListBox(settings.get_strv("left-box-order"), this._left_box_order); + initializeGtkListBox(settings.get_strv("center-box-order"), this._center_box_order); + initializeGtkListBox(settings.get_strv("right-box-order"), this._right_box_order); } });