[TS] Completely remove Indexable from Vendetta

This commit is contained in:
Beef 2023-04-15 03:04:48 +01:00
parent 32b3a0295c
commit b271240f76
5 changed files with 18 additions and 21 deletions

20
src/def.d.ts vendored
View file

@ -124,8 +124,8 @@ interface ThemeData {
description?: string;
authors?: Author[];
spec: number;
semanticColors?: Indexable<string[]>;
rawColors?: Indexable<string>;
semanticColors?: Record<string, string[]>;
rawColors?: Record<string, string>;
}
interface Theme {
@ -292,8 +292,6 @@ interface FileManager {
DocumentsDirPath: string;
}
type Indexable<Type> = { [index: string]: Type }
type EmitterEvent = "SET" | "GET" | "DEL";
interface EmitterListenerData {
@ -306,7 +304,7 @@ type EmitterListener = (
data: EmitterListenerData | any
) => any;
type EmitterListeners = Indexable<Set<EmitterListener>>;
type EmitterListeners = Record<string, Set<EmitterListener>>
interface Emitter {
listeners: EmitterListeners;
@ -437,18 +435,18 @@ interface VendettaObject {
showInputAlert: (options: InputAlertProps) => void;
};
assets: {
all: Indexable<Asset>;
all: Record<string, Asset>;
find: (filter: (a: any) => void) => Asset | null | undefined;
getAssetByName: (name: string) => Asset;
getAssetByID: (id: number) => Asset;
getAssetIDByName: (name: string) => number;
};
// TODO: Make a vain attempt to type these
semanticColors: Indexable<any>;
rawColors: Indexable<any>;
semanticColors: Record<string, any>;
rawColors: Record<string, any>;
};
plugins: {
plugins: Indexable<Plugin>;
plugins: Record<string, Plugin>;
fetchPlugin: (id: string) => Promise<void>;
installPlugin: (id: string, enabled?: boolean) => Promise<void>;
startPlugin: (id: string) => Promise<void>;
@ -457,7 +455,7 @@ interface VendettaObject {
getSettings: (id: string) => JSX.Element;
};
themes: {
themes: Indexable<Theme>;
themes: Record<string, Theme>;
fetchTheme: (id: string, selected?: boolean) => Promise<void>;
installTheme: (id: string) => Promise<void>;
selectTheme: (id: string) => Promise<void>;
@ -490,7 +488,7 @@ interface VendettaObject {
interface VendettaPluginObject {
id: string;
manifest: PluginManifest;
storage: Indexable<any>;
storage: Record<string, any>;
}
declare global {

View file

@ -1,4 +1,4 @@
import { Indexable, PluginManifest, Plugin } from "@types";
import { PluginManifest, Plugin } from "@types";
import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
import { MMKVManager } from "@lib/native";
import settings from "@lib/settings";
@ -11,8 +11,8 @@ type EvaledPlugin = {
settings: JSX.Element;
};
export const plugins = wrapSync(createStorage<Indexable<Plugin>>(createMMKVBackend("VENDETTA_PLUGINS")));
const loadedPlugins: Indexable<EvaledPlugin> = {};
export const plugins = wrapSync(createStorage<Record<string, Plugin>>(createMMKVBackend("VENDETTA_PLUGINS")));
const loadedPlugins: Record<string, EvaledPlugin> = {};
export async function fetchPlugin(id: string) {
if (!id.endsWith("/")) id += "/";
@ -60,7 +60,7 @@ export async function evalPlugin(plugin: Plugin) {
id: plugin.id,
manifest: plugin.manifest,
// Wrapping this with wrapSync is NOT an option.
storage: await createStorage<Indexable<any>>(createMMKVBackend(plugin.id)),
storage: await createStorage<Record<string, any>>(createMMKVBackend(plugin.id)),
},
logger: new logModule(`Vendetta » ${plugin.manifest.name}`),
};

View file

@ -1,4 +1,4 @@
import { Indexable, Theme, ThemeData } from "@types";
import { Theme, ThemeData } from "@types";
import { findByProps } from "@metro/filters";
import { ReactNative, chroma } from "@metro/common";
import { instead } from "@lib/patcher";
@ -9,7 +9,7 @@ import { safeFetch } from "@utils";
// Somehow, this is late enough, though?
export const color = findByProps("SemanticColor");
export const themes = wrapSync(createStorage<Indexable<Theme>>(createMMKVBackend("VENDETTA_THEMES")));
export const themes = wrapSync(createStorage<Record<string, Theme>>(createMMKVBackend("VENDETTA_THEMES")));
async function writeTheme(theme: Theme | {}) {
if (typeof theme !== "object") throw new Error("Theme must be an object");

View file

@ -1,8 +1,8 @@
import { Asset, Indexable } from "@types";
import { Asset } from "@types";
import { assets } from "@metro/common";
import { after } from "@lib/patcher";
export const all: Indexable<Asset> = {};
export const all: Record<string, Asset> = {};
export function patchAssets() {
const unpatch = after("registerAsset", assets, (args: Asset[], id: number) => {

View file

@ -1,4 +1,3 @@
import { Indexable } from "@types";
import { ReactNative as RN } from "@metro/common";
import { useProxy } from "@lib/storage";
import { HelpMessage, ErrorBoundary, Search } from "@ui/components";
@ -6,7 +5,7 @@ import { CardWrapper } from "@ui/settings/components/Card";
import settings from "@lib/settings";
interface AddonPageProps<T> {
items: Indexable<T & { id: string }>;
items: Record<string, T & { id: string }>;
safeModeMessage: string;
safeModeExtras?: JSX.Element | JSX.Element[];
card: React.ComponentType<CardWrapper<T>>;