2024-03-09 14:52:33 +01:00
|
|
|
|
2024-03-21 21:06:41 +01:00
|
|
|
type plugin_t = {
|
2024-08-07 22:48:08 +02:00
|
|
|
on_ui?: any; // JSValue *
|
|
|
|
|
on_draw?: any; // JSValue *
|
|
|
|
|
on_update?: any; // JSValue *
|
|
|
|
|
on_delete?: any; // JSValue *
|
2024-03-21 21:06:41 +01:00
|
|
|
version?: string;
|
|
|
|
|
name?: string;
|
|
|
|
|
};
|
2024-03-09 14:52:33 +01:00
|
|
|
|
2024-03-21 21:06:41 +01:00
|
|
|
let plugin_map: map_t<string, plugin_t> = map_create();
|
2024-03-09 14:52:33 +01:00
|
|
|
let _plugin_name: string;
|
|
|
|
|
|
2024-03-21 21:06:41 +01:00
|
|
|
function plugin_create(): plugin_t {
|
|
|
|
|
let p: plugin_t = {};
|
2024-03-09 14:52:33 +01:00
|
|
|
p.name = _plugin_name;
|
2024-03-20 16:13:54 +01:00
|
|
|
map_set(plugin_map, p.name, p);
|
2024-03-09 14:52:33 +01:00
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function plugin_start(plugin: string) {
|
2024-03-21 21:06:41 +01:00
|
|
|
let blob: buffer_t = data_get_blob("plugins/" + plugin);
|
|
|
|
|
_plugin_name = plugin;
|
2024-09-26 21:55:27 +02:00
|
|
|
js_eval("(1, eval)(`" + sys_buffer_to_string(blob) + "`)");
|
2024-03-21 21:06:41 +01:00
|
|
|
data_delete_blob("plugins/" + plugin);
|
2024-03-09 14:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function plugin_stop(plugin: string) {
|
2024-03-21 21:06:41 +01:00
|
|
|
let p: plugin_t = map_get(plugin_map, plugin);
|
2024-08-07 22:48:08 +02:00
|
|
|
if (p.on_delete != null) {
|
|
|
|
|
js_call(p.on_delete);
|
2024-03-09 14:52:33 +01:00
|
|
|
}
|
2024-03-20 16:13:54 +01:00
|
|
|
map_delete(plugin_map, plugin);
|
2024-03-09 14:52:33 +01:00
|
|
|
}
|
2024-08-07 22:48:08 +02:00
|
|
|
|
|
|
|
|
function plugin_notify_on_ui(plugin: plugin_t, f: any): void {
|
|
|
|
|
plugin.on_ui = f;
|
|
|
|
|
}
|
2024-08-22 23:07:22 +02:00
|
|
|
|
2024-08-24 11:17:02 +02:00
|
|
|
function plugin_notify_on_update(plugin: plugin_t, f: any): void {
|
|
|
|
|
plugin.on_update = f;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 23:07:22 +02:00
|
|
|
function plugin_notify_on_delete(plugin: plugin_t, f: any): void {
|
|
|
|
|
plugin.on_delete = f;
|
|
|
|
|
}
|