2019-01-31 09:07:06 -05:00
|
|
|
/* exported ComponentManager */
|
2012-09-02 21:23:50 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var ComponentManager = class {
|
|
|
|
constructor() {
|
2012-09-02 21:23:50 -04:00
|
|
|
this._allComponents = {};
|
|
|
|
this._enabledComponents = [];
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2012-09-02 21:23:50 -04:00
|
|
|
this._sessionUpdated();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-02 21:23:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sessionUpdated() {
|
2012-09-02 21:23:50 -04:00
|
|
|
let newEnabledComponents = Main.sessionMode.components;
|
|
|
|
|
2020-04-03 19:52:29 -04:00
|
|
|
newEnabledComponents
|
|
|
|
.filter(name => !this._enabledComponents.includes(name))
|
|
|
|
.forEach(name => this._enableComponent(name));
|
|
|
|
|
|
|
|
this._enabledComponents
|
|
|
|
.filter(name => !newEnabledComponents.includes(name))
|
|
|
|
.forEach(name => this._disableComponent(name));
|
2012-09-02 21:23:50 -04:00
|
|
|
|
|
|
|
this._enabledComponents = newEnabledComponents;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-02 21:23:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_importComponent(name) {
|
2012-09-02 21:23:50 -04:00
|
|
|
let module = imports.ui.components[name];
|
|
|
|
return module.Component;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-02 21:23:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ensureComponent(name) {
|
2012-09-02 21:23:50 -04:00
|
|
|
let component = this._allComponents[name];
|
|
|
|
if (component)
|
|
|
|
return component;
|
|
|
|
|
2019-01-29 15:18:46 -05:00
|
|
|
if (Main.sessionMode.isLocked)
|
|
|
|
return null;
|
2012-09-05 06:48:14 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
let constructor = this._importComponent(name);
|
|
|
|
component = new constructor();
|
|
|
|
this._allComponents[name] = component;
|
|
|
|
return component;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-02 21:23:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_enableComponent(name) {
|
2012-09-02 21:23:50 -04:00
|
|
|
let component = this._ensureComponent(name);
|
2019-01-29 15:18:46 -05:00
|
|
|
if (component)
|
2012-09-05 06:48:14 -04:00
|
|
|
component.enable();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-09-02 21:23:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_disableComponent(name) {
|
2012-09-02 21:23:50 -04:00
|
|
|
let component = this._allComponents[name];
|
|
|
|
if (component == null)
|
|
|
|
return;
|
|
|
|
component.disable();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|