components: Change component loading to be asynchronous
Some components use build time optional dependencies such as GNOME Bluetooth, so we need to import the components conditionally. Also rename to get rid of __init__.js file Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1499>
This commit is contained in:
parent
b81beece36
commit
d9198317ae
@ -127,7 +127,7 @@
|
|||||||
<file>ui/workspacesView.js</file>
|
<file>ui/workspacesView.js</file>
|
||||||
<file>ui/xdndHandler.js</file>
|
<file>ui/xdndHandler.js</file>
|
||||||
|
|
||||||
<file>ui/components/__init__.js</file>
|
<file>ui/components.js</file>
|
||||||
<file>ui/components/autorunManager.js</file>
|
<file>ui/components/autorunManager.js</file>
|
||||||
<file>ui/components/automountManager.js</file>
|
<file>ui/components/automountManager.js</file>
|
||||||
<file>ui/components/networkAgent.js</file>
|
<file>ui/components/networkAgent.js</file>
|
||||||
|
@ -6,16 +6,19 @@ var ComponentManager = class {
|
|||||||
this._allComponents = {};
|
this._allComponents = {};
|
||||||
this._enabledComponents = [];
|
this._enabledComponents = [];
|
||||||
|
|
||||||
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
Main.sessionMode.connect('updated', () => {
|
||||||
this._sessionUpdated();
|
this._sessionModeUpdated().catch(logError);
|
||||||
|
});
|
||||||
|
|
||||||
|
this._sessionModeUpdated().catch(logError);
|
||||||
}
|
}
|
||||||
|
|
||||||
_sessionUpdated() {
|
async _sessionModeUpdated() {
|
||||||
let newEnabledComponents = Main.sessionMode.components;
|
let newEnabledComponents = Main.sessionMode.components;
|
||||||
|
|
||||||
newEnabledComponents
|
await Promise.allSettled([...newEnabledComponents
|
||||||
.filter(name => !this._enabledComponents.includes(name))
|
.filter(name => !this._enabledComponents.includes(name))
|
||||||
.forEach(name => this._enableComponent(name));
|
.map(name => this._enableComponent(name))]);
|
||||||
|
|
||||||
this._enabledComponents
|
this._enabledComponents
|
||||||
.filter(name => !newEnabledComponents.includes(name))
|
.filter(name => !newEnabledComponents.includes(name))
|
||||||
@ -24,12 +27,13 @@ var ComponentManager = class {
|
|||||||
this._enabledComponents = newEnabledComponents;
|
this._enabledComponents = newEnabledComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
_importComponent(name) {
|
async _importComponent(name) {
|
||||||
let module = imports.ui.components[name];
|
// TODO: Import as module
|
||||||
|
let module = await imports.ui.components[name];
|
||||||
return module.Component;
|
return module.Component;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ensureComponent(name) {
|
async _ensureComponent(name) {
|
||||||
let component = this._allComponents[name];
|
let component = this._allComponents[name];
|
||||||
if (component)
|
if (component)
|
||||||
return component;
|
return component;
|
||||||
@ -37,14 +41,14 @@ var ComponentManager = class {
|
|||||||
if (Main.sessionMode.isLocked)
|
if (Main.sessionMode.isLocked)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
let constructor = this._importComponent(name);
|
let constructor = await this._importComponent(name);
|
||||||
component = new constructor();
|
component = new constructor();
|
||||||
this._allComponents[name] = component;
|
this._allComponents[name] = component;
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
_enableComponent(name) {
|
async _enableComponent(name) {
|
||||||
let component = this._ensureComponent(name);
|
let component = await this._ensureComponent(name);
|
||||||
if (component)
|
if (component)
|
||||||
component.enable();
|
component.enable();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user