[Plugins] Give plugins their own logger

This commit is contained in:
Jack Matthews 2023-02-17 01:21:56 -05:00 committed by Beef
parent c9aeefe419
commit a13b6e210c
2 changed files with 5 additions and 0 deletions

1
src/def.d.ts vendored
View file

@ -375,6 +375,7 @@ interface VendettaObject {
interface VendettaPluginObject { interface VendettaPluginObject {
manifest: PluginManifest; manifest: PluginManifest;
storage: Indexable<any>; storage: Indexable<any>;
logger: Logger;
} }
declare global { declare global {

View file

@ -1,8 +1,11 @@
import { Indexable, PluginManifest, Plugin } from "@types"; import { Indexable, PluginManifest, Plugin } from "@types";
import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage"; import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
import { findByProps } from "@metro/filters";
import safeFetch from "@utils/safeFetch"; import safeFetch from "@utils/safeFetch";
import logger from "@lib/logger"; import logger from "@lib/logger";
const logModule = findByProps("setLogFn").default;
type EvaledPlugin = { type EvaledPlugin = {
onLoad?(): void; onLoad?(): void;
onUnload(): void; onUnload(): void;
@ -60,6 +63,7 @@ export async function evalPlugin(plugin: Plugin) {
manifest: plugin.manifest, manifest: plugin.manifest,
// Wrapping this with wrapSync is NOT an option. // Wrapping this with wrapSync is NOT an option.
storage: await createStorage<Indexable<any>>(createMMKVBackend(plugin.id)), storage: await createStorage<Indexable<any>>(createMMKVBackend(plugin.id)),
logger: new logModule(plugin.manifest.name),
} }
}; };
const pluginString = `vendetta=>{return ${plugin.js}}\n//# sourceURL=${plugin.id}`; const pluginString = `vendetta=>{return ${plugin.js}}\n//# sourceURL=${plugin.id}`;