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

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