3c85fa61b6
Signed-off-by: Peter Siegmund <developer@mars3142.org>
78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
const ACTION_CACHES = {};
|
|
|
|
$UD.connect('dev.mars3142.ulanzideck.collection');
|
|
$UD.onConnected(() => {
|
|
console.log('app.js onConnected');
|
|
Utils.readJson(`${Utils.getPluginPath()}/${$UD.language}.json`)
|
|
.then(json => { $UD.localization = json['Localization'] || null; })
|
|
.catch(() => {});
|
|
});
|
|
|
|
$UD.onAdd(jsn => {
|
|
const context = jsn.context;
|
|
console.log('app.js onAdd:', JSON.stringify(jsn));
|
|
|
|
if (!ACTION_CACHES[context]) {
|
|
const name = jsn.uuid.split('.').pop().toLowerCase();
|
|
if (name === 'petrol') {
|
|
ACTION_CACHES[context] = new PetrolAction($UD, context);
|
|
} else if (name === 'copilot') {
|
|
ACTION_CACHES[context] = new CopilotAction($UD, context);
|
|
} else if (name === 'gitea') {
|
|
ACTION_CACHES[context] = new GiteaAction($UD, context);
|
|
} else if (name === 'giteapr') {
|
|
ACTION_CACHES[context] = new GiteaPRAction($UD, context);
|
|
} else if (name === 'railway') {
|
|
ACTION_CACHES[context] = new RailwayAction($UD, context);
|
|
} else if (name === 'stream') {
|
|
ACTION_CACHES[context] = new StreamAction($UD, context);
|
|
} else if (name === 'timemaster') {
|
|
ACTION_CACHES[context] = new TimemasterAction($UD, context);
|
|
}
|
|
}
|
|
|
|
if (ACTION_CACHES[context]) ACTION_CACHES[context].setParams(jsn);
|
|
});
|
|
|
|
$UD.onSetActive(jsn => {
|
|
const instance = ACTION_CACHES[jsn.context];
|
|
if (instance) instance.setActive(jsn.active);
|
|
});
|
|
|
|
$UD.onRun(jsn => {
|
|
const context = jsn.context;
|
|
if (!ACTION_CACHES[context]) {
|
|
$UD.emit('add', jsn);
|
|
} else {
|
|
ACTION_CACHES[context].onRun();
|
|
}
|
|
});
|
|
|
|
$UD.onClear(jsn => {
|
|
if (jsn.param) {
|
|
for (let i = 0; i < jsn.param.length; i++) {
|
|
const context = jsn.param[i].context;
|
|
if (ACTION_CACHES[context]) {
|
|
ACTION_CACHES[context].onClear();
|
|
delete ACTION_CACHES[context];
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
$UD.onParamFromApp(jsn => {
|
|
console.log('app.js onParamFromApp:', JSON.stringify(jsn.param));
|
|
onSetSettings(jsn);
|
|
});
|
|
|
|
$UD.onParamFromPlugin(jsn => {
|
|
console.log('app.js onParamFromPlugin:', JSON.stringify(jsn.param));
|
|
onSetSettings(jsn);
|
|
});
|
|
|
|
function onSetSettings(jsn) {
|
|
const action = ACTION_CACHES[jsn.context];
|
|
if (!action) return;
|
|
action.setParams(jsn);
|
|
}
|