add webview threaded api

This commit is contained in:
Johannes Kirschbauer
2024-05-15 14:27:18 +02:00
committed by hsjobeki
parent fef16a84a9
commit 7980f13bed
27 changed files with 359 additions and 80 deletions

View File

@@ -0,0 +1,22 @@
const deserialize = (fn: Function) => (str: string) => {
try {
fn(JSON.parse(str));
} catch (e) {
alert(`Error parsing JSON: ${e}`);
}
};
export const PYAPI = {
list_machines: {
dispatch: (data: null) =>
// @ts-ignore
window.webkit.messageHandlers.gtk.postMessage({
method: "list_machines",
data,
}),
receive: (fn: (response: string[]) => void) => {
// @ts-ignore
window.clan.list_machines = deserialize(fn);
},
},
};