[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: Indexable<Plugin>;
fetchPlugin: (id: string) => void;
installPlugin: (id: string, enabled?: boolean) => void;
evalPlugin: (plugin: Plugin) => void;
fetchPlugin: (id: string) => Promise<void>;
installPlugin: (id: string, enabled?: boolean) => Promise<void>;
startPlugin: (id: string) => Promise<void>;
stopPlugin: (id: string, disable?: boolean) => void;
removePlugin: (id: string) => void;
getSettings: (id: string) => JSX.Element;
};
themes: {
themes: Indexable<Theme>;
fetchTheme: (id: string, selected?: boolean) => void;
installTheme: (id: string) => void;
selectTheme: (id: string) => void;
fetchTheme: (id: string, selected?: boolean) => Promise<void>;
installTheme: (id: string) => Promise<void>;
selectTheme: (id: string) => Promise<void>;
removeTheme: (id: string) => Promise<boolean>;
getCurrentTheme: () => Theme | null;
updateThemes: () => void;
updateThemes: () => Promise<void>;
};
commands: {
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
console.log("Hello from Vendetta!");
(async () => (await import(".")).default().catch(e => {
import(".").then((m) => m.default()).catch((e) => {
console.log(e?.stack ?? e.toString());
alert([
"Failed to load Vendetta!\n",
@ -12,4 +12,4 @@ console.log("Hello from Vendetta!");
`Vendetta: ${__vendettaVersion}`,
e?.stack || e.toString(),
].join("\n"));
}))();
});

View file

@ -8,7 +8,6 @@ export const createMMKVBackend = (store: 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({
default: (f) => 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");
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 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 };
keys.forEach((k) => delete cloned[k]);
return cloned;
@ -36,7 +36,7 @@ export default async (unloads: any[]): Promise<VendettaObject> => ({
assets,
...color,
},
plugins: without(plugins, "initPlugins"),
plugins: without(plugins, "initPlugins", "evalPlugin"),
themes: without(themes, "initThemes"),
commands: without(commands, "patchCommands"),
storage,