diff --git a/src/core/ui/components/AddonPage.tsx b/src/core/ui/components/AddonPage.tsx index 0b9c2ae..4879369 100644 --- a/src/core/ui/components/AddonPage.tsx +++ b/src/core/ui/components/AddonPage.tsx @@ -4,12 +4,12 @@ import { findAssetId } from "@lib/api/assets"; import { settings } from "@lib/api/settings"; import { useProxy } from "@lib/api/storage"; import { HTTP_REGEX_MULTI } from "@lib/utils/constants"; -import { clipboard, NavigationNative } from "@metro/common"; +import { clipboard } from "@metro/common"; import { FlashList, FloatingActionButton, HelpMessage } from "@metro/common/components"; import { showInputAlert } from "@ui/alerts"; import { ErrorBoundary, Search } from "@ui/components"; import fuzzysort from "fuzzysort"; -import { ComponentType, ReactNode, useCallback, useMemo } from "react"; +import { ComponentType, ReactNode, useMemo } from "react"; import { View } from "react-native"; type SearchKeywords = Array string)>; @@ -30,14 +30,6 @@ interface AddonPageProps { export default function AddonPage({ card: CardComponent, ...props }: AddonPageProps) { useProxy(settings); - const [, forceUpdate] = React.useReducer(s => ~s, 0); - NavigationNative.useFocusEffect( - useCallback(() => { - console.log("giler", items); - forceUpdate(); - }, []) - ); - const [search, setSearch] = React.useState(""); const items = useMemo(() => { @@ -51,33 +43,26 @@ export default function AddonPage({ card: CardComponent, ...pr return fuzzysort.go(search, items, { keys: props.searchKeywords }).map(r => r.obj); }, [items, search]); - const headerElement = useMemo(() => ( - + const headerElement = ( + {settings.safeMode?.enabled && {props.safeModeMessage} {props.safeModeExtras} } - setSearch(v)} - /> + setSearch(v)} /> - ), []); + ); return ( - {/* - I've spent countless hours on these, but FlashList and FlatList refuse to rerender (unless if you reopen the page) - *even* if the data totally changed. Solutions online suggest putting extraData prop, - but that doesn't work either. I wonder what could have caused this - */} i?.id} estimatedItemSize={136} ListHeaderComponent={headerElement} - contentContainerStyle={{ paddingBottom: 90, paddingHorizontal: 5 }} + contentContainerStyle={{ padding: 8, paddingHorizontal: 12 }} + ItemSeparatorComponent={() => } ListFooterComponent={props.ListFooterComponent} renderItem={({ item }: any) => ( diff --git a/src/core/ui/settings/pages/Plugins/index.tsx b/src/core/ui/settings/pages/Plugins/index.tsx index d3e77fe..1790e65 100644 --- a/src/core/ui/settings/pages/Plugins/index.tsx +++ b/src/core/ui/settings/pages/Plugins/index.tsx @@ -104,16 +104,12 @@ export default function Plugins() { ] }); - return - - - ; + return ( + + + + + + + ); } diff --git a/src/lib/api/storage/new.ts b/src/lib/api/storage/new.ts index 962dbcb..08c3abb 100644 --- a/src/lib/api/storage/new.ts +++ b/src/lib/api/storage/new.ts @@ -14,7 +14,7 @@ const storagePromiseSymbol = Symbol.for("bunny.storage.promise"); const _loadedPath = {} as Record; -function createFileBackend(filePath: string): StorageBackend { +function createFileBackend(filePath: string): StorageBackend { return { get: async () => { try { @@ -187,13 +187,19 @@ export const createStorage = (path: string, dflt = {} as T): T & { [key: symb }; export async function preloadStorageIfExists(path: string) { - if (_loadedPath[path]) return; - if (!await fileExists(path)) return; + if (_loadedPath[path]) return _loadedPath[path]; - const data = await createFileBackend(path).get(); - _loadedPath[path] = data; + const backend = createFileBackend(path); + if (await backend.exists()) { + return _loadedPath[path] = await backend.get(); + } + + console.log("no " + path); } +export function getPreloadedStorage(path: string): T { + return _loadedPath[path]; +} export function awaitStorage(...proxies: any[]) { return Promise.all(proxies.map(proxy => proxy[storagePromiseSymbol])); } diff --git a/src/lib/plugins/index.ts b/src/lib/plugins/index.ts index 4e21996..70072eb 100644 --- a/src/lib/plugins/index.ts +++ b/src/lib/plugins/index.ts @@ -1,6 +1,6 @@ import { getCorePlugins } from "@core/plugins"; import { readFile, removeFile, writeFile } from "@lib/api/native/fs"; -import { awaitStorage, createStorage, preloadStorageIfExists, updateStorageAsync } from "@lib/api/storage/new"; +import { awaitStorage, createStorage, getPreloadedStorage, preloadStorageIfExists, updateStorageAsync } from "@lib/api/storage/new"; import { safeFetch } from "@lib/utils"; import { semver } from "@metro/common"; @@ -155,19 +155,24 @@ export async function updateRepository(repoUrl: string) { } } - await Promise.all(Object.keys(repo).map(async plugin => { - if (!storedRepo || !storedRepo[plugin] || repo[plugin].alwaysFetch || newerThan(repo[plugin].version, storedRepo[plugin].version)) { + await Promise.all(Object.keys(repo).map(async pluginId => { + if (!storedRepo || !storedRepo[pluginId] || repo[pluginId].alwaysFetch || newerThan(repo[pluginId].version, storedRepo[pluginId].version)) { updated = true; - pluginRepositories[repoUrl][plugin] = repo[plugin]; - await updateAndWritePlugin(repoUrl, plugin, Boolean(storedRepo && pluginSettings[plugin])); + pluginRepositories[repoUrl][pluginId] = repo[pluginId]; + await updateAndWritePlugin(repoUrl, pluginId, Boolean(storedRepo && pluginSettings[pluginId])); } else { - await preloadStorageIfExists(`plugins/manifests/${plugin}.json`); + const manifest = await preloadStorageIfExists(`plugins/manifests/${pluginId}.json`); + if (manifest === undefined) { // File does not exist, so do refetch and stuff + await updateAndWritePlugin(repoUrl, pluginId, Boolean(storedRepo && pluginSettings[pluginId])); + } } })); // Register plugins in this repository for (const id in repo) { - const manifest = createStorage(`plugins/manifests/${id}.json`); + const manifest = getPreloadedStorage(`plugins/manifests/${id}.json`); + if (manifest === undefined) continue; // shouldn't happen, but just incase if it does + const existing = registeredPlugins.get(id); // Skip if this version isn't any higher diff --git a/src/lib/ui/components/Search.tsx b/src/lib/ui/components/Search.tsx index 85047f9..dbf9919 100644 --- a/src/lib/ui/components/Search.tsx +++ b/src/lib/ui/components/Search.tsx @@ -2,12 +2,12 @@ import { Strings } from "@core/i18n"; import { findAssetId } from "@lib/api/assets"; import { TextInput } from "@metro/common/components"; import ErrorBoundary from "@ui/components/ErrorBoundary"; -import { Image, View } from "react-native"; +import { Image, View, ViewStyle } from "react-native"; export interface SearchProps { onChangeText?: (v: string) => void; placeholder?: string; - style?: import("react-native").TextStyle; + style?: ViewStyle; } function SearchIcon() { diff --git a/src/metro/common/types/components.ts b/src/metro/common/types/components.ts index 824349e..24b2a95 100644 --- a/src/metro/common/types/components.ts +++ b/src/metro/common/types/components.ts @@ -60,6 +60,7 @@ export interface SegmentedControlState { interface SegmentedControlProps { state: SegmentedControlState; + variant?: string; } export type SegmentedControl = React.FC;