[Global] Some changes and fixes

This commit is contained in:
redstonekasi 2023-04-05 22:18:22 +02:00 committed by Beef
parent 50755b2306
commit 5461065db8
4 changed files with 13 additions and 14 deletions

14
src/def.d.ts vendored
View file

@ -427,21 +427,21 @@ interface VendettaObject {
}; };
plugins: { plugins: {
plugins: Indexable<Plugin>; plugins: Indexable<Plugin>;
fetchPlugin: (id: string) => void; fetchPlugin: (id: string) => Promise<void>;
installPlugin: (id: string, enabled?: boolean) => void; installPlugin: (id: string, enabled?: boolean) => Promise<void>;
evalPlugin: (plugin: Plugin) => void; startPlugin: (id: string) => Promise<void>;
stopPlugin: (id: string, disable?: boolean) => void; stopPlugin: (id: string, disable?: boolean) => void;
removePlugin: (id: string) => void; removePlugin: (id: string) => void;
getSettings: (id: string) => JSX.Element; getSettings: (id: string) => JSX.Element;
}; };
themes: { themes: {
themes: Indexable<Theme>; themes: Indexable<Theme>;
fetchTheme: (id: string, selected?: boolean) => void; fetchTheme: (id: string, selected?: boolean) => Promise<void>;
installTheme: (id: string) => void; installTheme: (id: string) => Promise<void>;
selectTheme: (id: string) => void; selectTheme: (id: string) => Promise<void>;
removeTheme: (id: string) => Promise<boolean>; removeTheme: (id: string) => Promise<boolean>;
getCurrentTheme: () => Theme | null; getCurrentTheme: () => Theme | null;
updateThemes: () => void; updateThemes: () => Promise<void>;
}; };
commands: { commands: {
registerCommand: (command: ApplicationCommand) => () => void; registerCommand: (command: ApplicationCommand) => () => void;

View file

@ -3,7 +3,7 @@ import { ClientInfoManager } from "@lib/native";
// This logs in the native logging implementation, e.g. logcat // This logs in the native logging implementation, e.g. logcat
console.log("Hello from Vendetta!"); console.log("Hello from Vendetta!");
(async () => (await import(".")).default().catch(e => { import(".").then((m) => m.default()).catch((e) => {
console.log(e?.stack ?? e.toString()); console.log(e?.stack ?? e.toString());
alert([ alert([
"Failed to load Vendetta!\n", "Failed to load Vendetta!\n",
@ -12,4 +12,4 @@ console.log("Hello from Vendetta!");
`Vendetta: ${__vendettaVersion}`, `Vendetta: ${__vendettaVersion}`,
e?.stack || e.toString(), e?.stack || e.toString(),
].join("\n")); ].join("\n"));
}))(); });

View file

@ -8,7 +8,6 @@ export const createMMKVBackend = (store: string): StorageBackend => ({
}); });
export const createFileBackend = (file: string): StorageBackend => { export const createFileBackend = (file: string): StorageBackend => {
// TODO: Creating this function in every file backend probably isn't ideal.
const filePathFixer: (file: string) => string = RN.Platform.select({ const filePathFixer: (file: string) => string = RN.Platform.select({
default: (f) => f, default: (f) => f,
ios: (f) => `Documents/${f}`, ios: (f) => `Documents/${f}`,
@ -21,6 +20,6 @@ export const createFileBackend = (file: string): StorageBackend => {
if (!created && !(await FileManager.fileExists(path))) return (created = true), FileManager.writeFile("documents", filePathFixer(file), "{}", "utf8"); if (!created && !(await FileManager.fileExists(path))) return (created = true), FileManager.writeFile("documents", filePathFixer(file), "{}", "utf8");
return JSON.parse(await FileManager.readFile(path, "utf8")); return JSON.parse(await FileManager.readFile(path, "utf8"));
}, },
set: (data) => void FileManager.writeFile("documents", filePathFixer(file), JSON.stringify(data), "utf8"), set: async (data) => void await FileManager.writeFile("documents", filePathFixer(file), JSON.stringify(data), "utf8"),
}; };
}; };

View file

@ -17,7 +17,7 @@ import * as assets from "@ui/assets";
import * as color from "@ui/color"; import * as color from "@ui/color";
import * as utils from "@utils"; import * as utils from "@utils";
function without<T extends Record<string, any>>(object: T, ...keys: string[]) { function without<O extends object, K extends readonly (keyof O)[]>(object: O, ...keys: K): Omit<O, typeof keys[number]> {
const cloned = { ...object }; const cloned = { ...object };
keys.forEach((k) => delete cloned[k]); keys.forEach((k) => delete cloned[k]);
return cloned; return cloned;
@ -36,7 +36,7 @@ export default async (unloads: any[]): Promise<VendettaObject> => ({
assets, assets,
...color, ...color,
}, },
plugins: without(plugins, "initPlugins"), plugins: without(plugins, "initPlugins", "evalPlugin"),
themes: without(themes, "initThemes"), themes: without(themes, "initThemes"),
commands: without(commands, "patchCommands"), commands: without(commands, "patchCommands"),
storage, storage,