Blame SOURCES/0002-extensionSystem-Get-rid-of-_enabled-boolean-optimiza.patch

a3db19
From b70cf463e08bff43b242b851fc7c79244f54e76b Mon Sep 17 00:00:00 2001
a3db19
From: Ray Strode <rstrode@redhat.com>
a3db19
Date: Tue, 10 Aug 2021 13:25:57 -0400
a3db19
Subject: [PATCH 2/4] extensionSystem: Get rid of _enabled boolean optimization
a3db19
a3db19
At the moment a session mode either allows extensions or it doesn't.
a3db19
If it allows extensions, then the entire available list of
a3db19
configured extensions get enabled as soon as the session mode is
a3db19
entered.
a3db19
a3db19
Since enabling or disabling extensions is an all or nothing situation,
a3db19
the code tracks whether extensions are already enabled when entering
a3db19
the session mode, and if so, avoids iterating through the extension list
a3db19
needlessly. It does this using a boolean named _enabled.
a3db19
a3db19
In the future, the extensions themselves will be given some say on
a3db19
whether or not they should be enabled in a given session mode. This
a3db19
means, the configured extension list may contain extensions that
a3db19
shouldn't be enabled for a given session mode, and the _enabled boolean
a3db19
will no longer be appropriated.
a3db19
a3db19
This commit drops the _enabled boolean optimization.
a3db19
---
a3db19
 js/ui/extensionSystem.js | 13 -------------
a3db19
 1 file changed, 13 deletions(-)
a3db19
a3db19
diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js
a3db19
index 77929f2a6..05630ed54 100644
a3db19
--- a/js/ui/extensionSystem.js
a3db19
+++ b/js/ui/extensionSystem.js
a3db19
@@ -1,53 +1,52 @@
a3db19
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
a3db19
 
a3db19
 const { GLib, Gio, GObject, St } = imports.gi;
a3db19
 const Signals = imports.signals;
a3db19
 
a3db19
 const ExtensionDownloader = imports.ui.extensionDownloader;
a3db19
 const ExtensionUtils = imports.misc.extensionUtils;
a3db19
 const FileUtils = imports.misc.fileUtils;
a3db19
 const Main = imports.ui.main;
a3db19
 const MessageTray = imports.ui.messageTray;
a3db19
 
a3db19
 const { ExtensionState, ExtensionType } = ExtensionUtils;
a3db19
 
a3db19
 const ENABLED_EXTENSIONS_KEY = 'enabled-extensions';
a3db19
 const DISABLE_USER_EXTENSIONS_KEY = 'disable-user-extensions';
a3db19
 const EXTENSION_DISABLE_VERSION_CHECK_KEY = 'disable-extension-version-validation';
a3db19
 
a3db19
 const UPDATE_CHECK_TIMEOUT = 24 * 60 * 60; // 1 day in seconds
a3db19
 
a3db19
 var ExtensionManager = class {
a3db19
     constructor() {
a3db19
         this._initted = false;
a3db19
-        this._enabled = false;
a3db19
         this._updateNotified = false;
a3db19
 
a3db19
         this._extensions = new Map();
a3db19
         this._enabledExtensions = [];
a3db19
         this._extensionOrder = [];
a3db19
 
a3db19
         Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
a3db19
     }
a3db19
 
a3db19
     init() {
a3db19
         this._installExtensionUpdates();
a3db19
         this._sessionUpdated();
a3db19
 
a3db19
         GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, UPDATE_CHECK_TIMEOUT, () => {
a3db19
             ExtensionDownloader.checkForUpdates();
a3db19
             return GLib.SOURCE_CONTINUE;
a3db19
         });
a3db19
         ExtensionDownloader.checkForUpdates();
a3db19
     }
a3db19
 
a3db19
     lookup(uuid) {
a3db19
         return this._extensions.get(uuid);
a3db19
     }
a3db19
 
a3db19
     getUuids() {
a3db19
         return [...this._extensions.keys()];
a3db19
     }
a3db19
 
a3db19
     _callExtensionDisable(uuid) {
a3db19
         let extension = this.lookup(uuid);
a3db19
@@ -375,63 +374,60 @@ var ExtensionManager = class {
a3db19
         let hasError =
a3db19
             extension.state == ExtensionState.ERROR ||
a3db19
             extension.state == ExtensionState.OUT_OF_DATE;
a3db19
 
a3db19
         let isMode = this._getModeExtensions().includes(extension.uuid);
a3db19
         let modeOnly = global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY);
a3db19
 
a3db19
         extension.canChange =
a3db19
             !hasError &&
a3db19
             global.settings.is_writable(ENABLED_EXTENSIONS_KEY) &&
a3db19
             (isMode || !modeOnly);
a3db19
     }
a3db19
 
a3db19
     _getEnabledExtensions() {
a3db19
         let extensions = this._getModeExtensions();
a3db19
 
a3db19
         if (global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY))
a3db19
             return extensions;
a3db19
 
a3db19
         return extensions.concat(global.settings.get_strv(ENABLED_EXTENSIONS_KEY));
a3db19
     }
a3db19
 
a3db19
     _onUserExtensionsEnabledChanged() {
a3db19
         this._onEnabledExtensionsChanged();
a3db19
         this._onSettingsWritableChanged();
a3db19
     }
a3db19
 
a3db19
     _onEnabledExtensionsChanged() {
a3db19
         let newEnabledExtensions = this._getEnabledExtensions();
a3db19
 
a3db19
-        if (!this._enabled)
a3db19
-            return;
a3db19
-
a3db19
         // Find and enable all the newly enabled extensions: UUIDs found in the
a3db19
         // new setting, but not in the old one.
a3db19
         newEnabledExtensions.filter(
a3db19
             uuid => !this._enabledExtensions.includes(uuid)
a3db19
         ).forEach(uuid => {
a3db19
             this._callExtensionEnable(uuid);
a3db19
         });
a3db19
 
a3db19
         // Find and disable all the newly disabled extensions: UUIDs found in the
a3db19
         // old setting, but not in the new one.
a3db19
         this._enabledExtensions.filter(
a3db19
             item => !newEnabledExtensions.includes(item)
a3db19
         ).forEach(uuid => {
a3db19
             this._callExtensionDisable(uuid);
a3db19
         });
a3db19
 
a3db19
         this._enabledExtensions = newEnabledExtensions;
a3db19
     }
a3db19
 
a3db19
     _onSettingsWritableChanged() {
a3db19
         for (let extension of this._extensions.values()) {
a3db19
             this._updateCanChange(extension);
a3db19
             this.emit('extension-state-changed', extension);
a3db19
         }
a3db19
     }
a3db19
 
a3db19
     _onVersionValidationChanged() {
a3db19
         // we want to reload all extensions, but only enable
a3db19
         // extensions when allowed by the sessionMode, so
a3db19
         // temporarily disable them all
a3db19
@@ -482,85 +478,76 @@ var ExtensionManager = class {
a3db19
 
a3db19
         this._enabledExtensions = this._getEnabledExtensions();
a3db19
 
a3db19
         let perUserDir = Gio.File.new_for_path(global.userdatadir);
a3db19
         FileUtils.collectFromDatadirs('extensions', true, (dir, info) => {
a3db19
             let fileType = info.get_file_type();
a3db19
             if (fileType != Gio.FileType.DIRECTORY)
a3db19
                 return;
a3db19
             let uuid = info.get_name();
a3db19
             let existing = this.lookup(uuid);
a3db19
             if (existing) {
a3db19
                 log(`Extension ${uuid} already installed in ${existing.path}. ${dir.get_path()} will not be loaded`);
a3db19
                 return;
a3db19
             }
a3db19
 
a3db19
             let extension;
a3db19
             let type = dir.has_prefix(perUserDir)
a3db19
                 ? ExtensionType.PER_USER
a3db19
                 : ExtensionType.SYSTEM;
a3db19
             try {
a3db19
                 extension = this.createExtensionObject(uuid, dir, type);
a3db19
             } catch (e) {
a3db19
                 logError(e, `Could not load extension ${uuid}`);
a3db19
                 return;
a3db19
             }
a3db19
             this.loadExtension(extension);
a3db19
         });
a3db19
     }
a3db19
 
a3db19
     _enableAllExtensions() {
a3db19
-        if (this._enabled)
a3db19
-            return;
a3db19
-
a3db19
         if (!this._initted) {
a3db19
             this._loadExtensions();
a3db19
             this._initted = true;
a3db19
         } else {
a3db19
             this._enabledExtensions.forEach(uuid => {
a3db19
                 this._callExtensionEnable(uuid);
a3db19
             });
a3db19
         }
a3db19
-        this._enabled = true;
a3db19
     }
a3db19
 
a3db19
     _disableAllExtensions() {
a3db19
-        if (!this._enabled)
a3db19
-            return;
a3db19
-
a3db19
         if (this._initted) {
a3db19
             this._extensionOrder.slice().reverse().forEach(uuid => {
a3db19
                 this._callExtensionDisable(uuid);
a3db19
             });
a3db19
         }
a3db19
-
a3db19
-        this._enabled = false;
a3db19
     }
a3db19
 
a3db19
     _sessionUpdated() {
a3db19
         // For now sessionMode.allowExtensions controls extensions from both the
a3db19
         // 'enabled-extensions' preference and the sessionMode.enabledExtensions
a3db19
         // property; it might make sense to make enabledExtensions independent
a3db19
         // from allowExtensions in the future
a3db19
         if (Main.sessionMode.allowExtensions) {
a3db19
             // Take care of added or removed sessionMode extensions
a3db19
             this._onEnabledExtensionsChanged();
a3db19
             this._enableAllExtensions();
a3db19
         } else {
a3db19
             this._disableAllExtensions();
a3db19
         }
a3db19
     }
a3db19
 };
a3db19
 Signals.addSignalMethods(ExtensionManager.prototype);
a3db19
 
a3db19
 class ExtensionUpdateSource extends MessageTray.Source {
a3db19
     constructor() {
a3db19
         const appSys = Shell.AppSystem.get_default();
a3db19
         this._app = appSys.lookup_app('gnome-shell-extension-prefs.desktop');
a3db19
 
a3db19
         super(this._app.get_name());
a3db19
     }
a3db19
 
a3db19
     getIcon() {
a3db19
         return this._app.app_info.get_icon();
a3db19
     }
a3db19
 
a3db19
-- 
a3db19
2.27.0
a3db19