mirror of
https://github.com/edu4rdshl/gnome-shell.git
synced 2026-07-17 23:24:51 +00:00
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>
62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
/* exported ComponentManager */
|
|
const Main = imports.ui.main;
|
|
|
|
var ComponentManager = class {
|
|
constructor() {
|
|
this._allComponents = {};
|
|
this._enabledComponents = [];
|
|
|
|
Main.sessionMode.connect('updated', () => {
|
|
this._sessionModeUpdated().catch(logError);
|
|
});
|
|
|
|
this._sessionModeUpdated().catch(logError);
|
|
}
|
|
|
|
async _sessionModeUpdated() {
|
|
let newEnabledComponents = Main.sessionMode.components;
|
|
|
|
await Promise.allSettled([...newEnabledComponents
|
|
.filter(name => !this._enabledComponents.includes(name))
|
|
.map(name => this._enableComponent(name))]);
|
|
|
|
this._enabledComponents
|
|
.filter(name => !newEnabledComponents.includes(name))
|
|
.forEach(name => this._disableComponent(name));
|
|
|
|
this._enabledComponents = newEnabledComponents;
|
|
}
|
|
|
|
async _importComponent(name) {
|
|
// TODO: Import as module
|
|
let module = await imports.ui.components[name];
|
|
return module.Component;
|
|
}
|
|
|
|
async _ensureComponent(name) {
|
|
let component = this._allComponents[name];
|
|
if (component)
|
|
return component;
|
|
|
|
if (Main.sessionMode.isLocked)
|
|
return null;
|
|
|
|
let constructor = await this._importComponent(name);
|
|
component = new constructor();
|
|
this._allComponents[name] = component;
|
|
return component;
|
|
}
|
|
|
|
async _enableComponent(name) {
|
|
let component = await this._ensureComponent(name);
|
|
if (component)
|
|
component.enable();
|
|
}
|
|
|
|
_disableComponent(name) {
|
|
let component = this._allComponents[name];
|
|
if (component == null)
|
|
return;
|
|
component.disable();
|
|
}
|
|
};
|