[Plugins] Give plugins their own logger
This commit is contained in:
parent
c9aeefe419
commit
a13b6e210c
2 changed files with 5 additions and 0 deletions
1
src/def.d.ts
vendored
1
src/def.d.ts
vendored
|
@ -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 {
|
||||||
|
|
|
@ -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}`;
|
||||||
|
|
Loading…
Reference in a new issue