work on sandbox
This commit is contained in:
parent
722ddf1638
commit
083999212e
@ -96,25 +96,25 @@ async function apiNoteView(noteId) {
|
|||||||
return utilBackend().anki.guiBrowse(`nid:${noteId}`);
|
return utilBackend().anki.guiBrowse(`nid:${noteId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function apiTemplateRender(template, data) {
|
async function apiTemplateRender(template, data, dynamic) {
|
||||||
return handlebarsRender(template, data);
|
if (dynamic) {
|
||||||
}
|
return new Promise((resolve, reject) => {
|
||||||
|
const sequence = utilBackend().sequenceNew();
|
||||||
|
const handler = event => {
|
||||||
|
if (event.data.sequence === sequence) {
|
||||||
|
resolve(event.data.result);
|
||||||
|
window.removeEventListener('message', handler);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async function apiTemplateRenderDynamic(template, data) {
|
window.addEventListener('message', handler);
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const sequence = utilBackend().sequenceNew();
|
|
||||||
const handler = event => {
|
|
||||||
if (event.data.sequence === sequence) {
|
|
||||||
resolve(event.data.result);
|
|
||||||
window.removeEventListener('message', handler);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('message', handler);
|
const sandbox = utilBackend().sandbox();
|
||||||
|
sandbox.postMessage({template, data, sequence, command: 'render'}, '*');
|
||||||
const sandbox = utilBackend().sandbox();
|
});
|
||||||
sandbox.postMessage({template, data, sequence, command: 'render'}, '*');
|
} else {
|
||||||
});
|
return handlebarsRender(template, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function apiCommandExec(command) {
|
async function apiCommandExec(command) {
|
||||||
|
@ -113,8 +113,8 @@ class Backend {
|
|||||||
forward(apiNoteView(noteId), callback);
|
forward(apiNoteView(noteId), callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
templateRender: ({template, data, callback}) => {
|
templateRender: ({template, data, dynamic, callback}) => {
|
||||||
forward(apiTemplateRender(template, data), callback);
|
forward(apiTemplateRender(template, data, dynamic), callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
commandExec: ({command, callback}) => {
|
commandExec: ({command, callback}) => {
|
||||||
|
@ -45,8 +45,8 @@ function apiNoteView(noteId) {
|
|||||||
return utilInvoke('noteView', {noteId});
|
return utilInvoke('noteView', {noteId});
|
||||||
}
|
}
|
||||||
|
|
||||||
function apiTemplateRender(template, data) {
|
function apiTemplateRender(template, data, dynamic) {
|
||||||
return utilInvoke('templateRender', {data, template});
|
return utilInvoke('templateRender', {data, template, dynamic});
|
||||||
}
|
}
|
||||||
|
|
||||||
function apiCommandExec(command) {
|
function apiCommandExec(command) {
|
||||||
|
Loading…
Reference in New Issue
Block a user