2017-11-24 20:37:40 +02:00
|
|
|
class SyncTargetRegistry {
|
|
|
|
static classById(syncTargetId) {
|
2017-11-24 20:59:16 +02:00
|
|
|
const info = SyncTargetRegistry.reg_[syncTargetId];
|
2019-09-19 23:51:18 +02:00
|
|
|
if (!info) throw new Error(`Invalid id: ${syncTargetId}`);
|
2017-11-24 20:59:16 +02:00
|
|
|
return info.classRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
static addClass(SyncTargetClass) {
|
|
|
|
this.reg_[SyncTargetClass.id()] = {
|
|
|
|
id: SyncTargetClass.id(),
|
2017-11-24 21:21:30 +02:00
|
|
|
name: SyncTargetClass.targetName(),
|
2017-11-24 20:59:16 +02:00
|
|
|
label: SyncTargetClass.label(),
|
|
|
|
classRef: SyncTargetClass,
|
2018-02-06 20:59:36 +02:00
|
|
|
supportsConfigCheck: SyncTargetClass.supportsConfigCheck(),
|
2017-11-24 20:59:16 +02:00
|
|
|
};
|
2017-11-24 20:37:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-24 21:21:30 +02:00
|
|
|
static nameToId(name) {
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const n in this.reg_) {
|
2017-11-24 21:21:30 +02:00
|
|
|
if (!this.reg_.hasOwnProperty(n)) continue;
|
|
|
|
if (this.reg_[n].name === name) return this.reg_[n].id;
|
|
|
|
}
|
2019-09-19 23:51:18 +02:00
|
|
|
throw new Error(`Name not found: ${name}`);
|
2017-11-24 21:21:30 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 21:01:14 +02:00
|
|
|
static idToMetadata(id) {
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const n in this.reg_) {
|
2018-01-25 21:01:14 +02:00
|
|
|
if (!this.reg_.hasOwnProperty(n)) continue;
|
|
|
|
if (this.reg_[n].id === id) return this.reg_[n];
|
|
|
|
}
|
2019-09-19 23:51:18 +02:00
|
|
|
throw new Error(`ID not found: ${id}`);
|
2018-01-25 21:01:14 +02:00
|
|
|
}
|
|
|
|
|
2018-01-25 23:15:58 +02:00
|
|
|
static idToName(id) {
|
|
|
|
return this.idToMetadata(id).name;
|
|
|
|
}
|
|
|
|
|
2020-02-08 13:59:19 +02:00
|
|
|
static idAndLabelPlainObject(os) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const output = {};
|
|
|
|
for (const n in this.reg_) {
|
2017-11-24 21:21:30 +02:00
|
|
|
if (!this.reg_.hasOwnProperty(n)) continue;
|
2020-02-08 13:59:19 +02:00
|
|
|
const info = this.reg_[n];
|
|
|
|
if (info.classRef.unsupportedPlatforms().indexOf(os) >= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
output[n] = info.label;
|
2017-11-24 21:21:30 +02:00
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2017-11-24 20:37:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-24 20:59:16 +02:00
|
|
|
SyncTargetRegistry.reg_ = {};
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = SyncTargetRegistry;
|