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