fbf40f75b2
- petrol watch - copilot usage Signed-off-by: Peter Siegmund <developer@mars3142.org>
65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
const ACTION_CACHES = {};
|
|
|
|
$UD.connect('dev.mars3142.ulanzideck.collection');
|
|
$UD.onConnected(() => {
|
|
console.log('app.js onConnected');
|
|
});
|
|
|
|
$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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|