[Storage] Rework everything (#10)

* [storage] rework everything

* [storage] expose createProxy

* [storage] add useProxy hook

* [storage] fix settings.ts

* [Storage] Implement wrapSync, fix UI

* [storage] fix storage

* [plugins] re-add plugin loading

* [storage] fix fix storage

* [storage] make wrapSync more magical

* [storage] save deletes

* [ui] hack around plugin removal... again

* [plugins] make plugin storage work

* [storage] expose api

---------

Co-authored-by: Beef <beefers@riseup.net>
This commit is contained in:
redstonekasi 2023-01-29 22:05:47 +01:00 committed by GitHub
parent 7282d45d39
commit 4c9fe8fcaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 201 additions and 87 deletions

View file

@ -2,8 +2,8 @@ import { ReactNative as RN, stylesheet } from "@metro/common";
import { Forms, General } from "@ui/components";
import { Plugin } from "@types";
import { getAssetIDByName } from "@ui/assets";
import { removePlugin, startPlugin, stopPlugin, showSettings, getSettings } from "@lib/plugins";
import { showToast } from "@ui/toasts";
import { removePlugin, startPlugin, stopPlugin, showSettings, getSettings } from "@lib/plugins";
import copyText from "@lib/utils/copyText";
const { FormRow, FormSwitch } = Forms;
@ -39,13 +39,9 @@ interface PluginCardProps {
}
export default function PluginCard({ plugin }: PluginCardProps) {
const [enabled, setEnabled] = React.useState(plugin.enabled);
const [update, setUpdate] = React.useState(plugin.update);
const [removed, setRemoved] = React.useState(false);
// This is bad, but I don't think I have much choice - Beef
// Once the user re-renders the page, this is not taken into account anyway.
if (removed) return <></>;
// This is needed because of React™
if (removed) return null;
return (
<RN.View style={styles.card}>
@ -58,7 +54,6 @@ export default function PluginCard({ plugin }: PluginCardProps) {
value={plugin.enabled}
onValueChange={(v: boolean) => {
if (v) startPlugin(plugin.id); else stopPlugin(plugin.id);
setEnabled(v);
}}
/>
}
@ -87,7 +82,6 @@ export default function PluginCard({ plugin }: PluginCardProps) {
onPress={() => {
plugin.update = !plugin.update;
showToast(`${plugin.update ? "Enabled" : "Disabled"} updates for ${plugin.manifest.name}.`, getAssetIDByName("toast_image_saved"));
setUpdate(plugin.update);
}}
>
<Image style={styles.icon} source={getAssetIDByName(plugin.update ? "Check" : "Small")} />
@ -100,4 +94,4 @@ export default function PluginCard({ plugin }: PluginCardProps) {
/>
</RN.View>
)
}
}

View file

@ -1,6 +1,7 @@
import { Forms } from "@ui/components";
import { getAssetIDByName } from "@ui/assets";
import settings from "@/lib/settings";
import { useProxy } from "@lib/storage";
import settings from "@lib/settings";
const { FormRow, FormSection, FormDivider } = Forms;
@ -9,6 +10,8 @@ interface SettingsSectionProps {
}
export default function SettingsSection({ navigation }: SettingsSectionProps) {
useProxy(settings);
return (
<FormSection key="Vendetta" title="Vendetta">
<FormRow

View file

@ -1,8 +1,9 @@
import { ReactNative as RN, navigation } from "@metro/common";
import { Forms } from "@ui/components";
import { getAssetIDByName } from "@ui/assets";
import { showToast } from "@/ui/toasts";
import { showToast } from "@ui/toasts";
import { connectToDebugger } from "@lib/debug";
import { useProxy } from "@lib/storage";
import settings from "@lib/settings";
import logger from "@lib/logger";
import Subpage from "@ui/settings/components/Subpage";
@ -11,33 +12,32 @@ import AssetBrowser from "@ui/settings/pages/AssetBrowser";
const { FormSection, FormRow, FormInput, FormDivider } = Forms;
export default function Developer() {
const [debuggerUrl, setDebuggerUrl] = React.useState(settings.debuggerUrl || "");
useProxy(settings);
return (
<RN.View style={{ flex: 1 }}>
<FormSection title="Debug">
<FormInput
value={debuggerUrl}
value={settings.debuggerUrl}
onChange={(v: string) => {
settings.debuggerUrl = v;
setDebuggerUrl(v);
}}
title="DEBUGGER URL"
/>
<FormDivider />
<FormRow
label="Connect to debug websocket"
leading={() => <FormRow.Icon source={getAssetIDByName("copy")} />}
onPress={() => connectToDebugger(debuggerUrl)}
leading={<FormRow.Icon source={getAssetIDByName("copy")} />}
onPress={() => connectToDebugger(settings.debuggerUrl)}
/>
<FormDivider />
{window.__vendetta_rdc && <FormRow
label="Connect to React DevTools"
leading={() => <FormRow.Icon source={getAssetIDByName("ic_badge_staff")} />}
leading={<FormRow.Icon source={getAssetIDByName("ic_badge_staff")} />}
onPress={() => {
try {
window.__vendetta_rdc?.connectToDevTools({
host: debuggerUrl.split(":")[0],
host: settings.debuggerUrl.split(":")?.[0],
resolveRNStyle: RN.StyleSheet.flatten,
});
} catch(e) {
@ -50,7 +50,7 @@ export default function Developer() {
<FormSection title="Other">
<FormRow
label="Asset Browser"
leading={() => <FormRow.Icon source={getAssetIDByName("ic_media_upload")} />}
leading={<FormRow.Icon source={getAssetIDByName("ic_media_upload")} />}
trailing={FormRow.Arrow}
onPress={() => navigation.push(Subpage, {
name: "Asset Browser",

View file

@ -3,14 +3,15 @@ import { DISCORD_SERVER, GITHUB } from "@lib/constants";
import { getAssetIDByName } from "@ui/assets";
import { Forms } from "@ui/components";
import { getDebugInfo } from "@lib/debug";
import Version from "@ui/settings/components/Version";
import { useProxy } from "@lib/storage";
import settings from "@lib/settings";
import Version from "@ui/settings/components/Version";
const { FormRow, FormSwitchRow, FormSection, FormDivider } = Forms;
const debugInfo = getDebugInfo();
export default function General() {
const [devSettings, setDevSettings] = React.useState(settings.developerSettings || false);
useProxy(settings);
const versions = [
{
@ -116,10 +117,9 @@ export default function General() {
<FormSwitchRow
label="Developer Settings"
leading={<FormRow.Icon source={getAssetIDByName("ic_progress_wrench_24px")} />}
value={devSettings}
value={settings.developerSettings}
onValueChange={(v: boolean) => {
settings.developerSettings = v;
setDevSettings(v);
}}
/>
</FormSection>

View file

@ -2,14 +2,15 @@ import { ReactNative as RN } from "@metro/common";
import { Forms } from "@ui/components";
import { showToast } from "@ui/toasts";
import { getAssetIDByName } from "@ui/assets";
import { fetchPlugin, plugins } from "@lib/plugins";
import { useProxy } from "@lib/storage";
import { plugins, fetchPlugin } from "@lib/plugins";
import PluginCard from "@ui/settings/components/PluginCard";
const { FormInput, FormRow } = Forms;
export default function Plugins() {
useProxy(plugins);
const [pluginUrl, setPluginUrl] = React.useState("");
const [pluginList, setPluginList] = React.useState(plugins);
return (
<RN.View style={{ flex: 1 }}>
@ -24,7 +25,6 @@ export default function Plugins() {
onPress={() => {
fetchPlugin(pluginUrl).then(() => {
setPluginUrl("");
setPluginList(plugins);
}).catch((e: Error) => {
showToast(e.message, getAssetIDByName("Small"));
});
@ -33,7 +33,7 @@ export default function Plugins() {
/>
<RN.FlatList
style={{ marginTop: 10 }}
data={Object.values(pluginList)}
data={Object.values(plugins)}
renderItem={({ item }) => <PluginCard plugin={item} />}
keyExtractor={item => item.id}
/>