[UI > Plugins] Add unproxied plugin warning prompt (#101)

* [UI > Plugins] Add unproxied plugin warning prompt

* [UI > Plugins] Show msg if developer not enabled

* [UI > Plugins] Prettier-be-gone!

---------

Co-authored-by: Beef <beefers@riseup.net>
This commit is contained in:
Gabe616 2023-07-09 02:33:54 +02:00 committed by GitHub
parent 30fb554759
commit 5c37b911a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 20 deletions

View file

@ -1,5 +1,5 @@
import { ReactNative as RN, stylesheet, clipboard } from "@metro/common"; import { ReactNative as RN, stylesheet, clipboard } from "@metro/common";
import { HTTP_REGEX } from "@lib/constants"; import { HTTP_REGEX_MULTI } from "@lib/constants";
import { showInputAlert } from "@ui/alerts"; import { showInputAlert } from "@ui/alerts";
import { getAssetIDByName } from "@ui/assets"; import { getAssetIDByName } from "@ui/assets";
import { semanticColors } from "@ui/color"; import { semanticColors } from "@ui/color";
@ -8,7 +8,7 @@ const styles = stylesheet.createThemedStyleSheet({
icon: { icon: {
marginRight: 10, marginRight: 10,
tintColor: semanticColors.HEADER_PRIMARY, tintColor: semanticColors.HEADER_PRIMARY,
} },
}); });
interface InstallButtonProps { interface InstallButtonProps {
@ -22,11 +22,11 @@ export default function InstallButton({ alertTitle, installFunction: fetchFuncti
clipboard.getString().then((content) => clipboard.getString().then((content) =>
showInputAlert({ showInputAlert({
title: alertTitle, title: alertTitle,
initialValue: HTTP_REGEX.test(content) ? content : "", initialValue: content.match(HTTP_REGEX_MULTI)?.[0] ?? "",
placeholder: "https://example.com/", placeholder: "https://example.com/",
onConfirm: (input: string) => fetchFunction(input), onConfirm: (input: string) => fetchFunction(input),
confirmText: "Install", confirmText: "Install",
cancelText: "Cancel" cancelText: "Cancel",
}) })
) )
}> }>

View file

@ -11,10 +11,13 @@ import General from "@ui/settings/pages/General";
import Plugins from "@ui/settings/pages/Plugins"; import Plugins from "@ui/settings/pages/Plugins";
import Themes from "@ui/settings/pages/Themes"; import Themes from "@ui/settings/pages/Themes";
import Developer from "@ui/settings/pages/Developer"; import Developer from "@ui/settings/pages/Developer";
import { PROXY_PREFIX } from "@/lib/constants";
import { showConfirmationAlert } from "../alerts";
import { showToast } from "../toasts";
interface Screen { interface Screen {
[index: string]: any; [index: string]: any;
key: string, key: string;
title: string; title: string;
icon?: string; icon?: string;
shouldRender?: () => boolean; shouldRender?: () => boolean;
@ -41,7 +44,25 @@ export const getScreens = (youKeys = false): Screen[] => [
title: "Plugins", title: "Plugins",
icon: "debug", icon: "debug",
options: { options: {
headerRight: () => <InstallButton alertTitle="Install Plugin" installFunction={installPlugin} />, headerRight: () => (
<InstallButton
alertTitle="Install Plugin"
installFunction={async (input) => {
if (!input.startsWith(PROXY_PREFIX) && !settings.developerSettings)
showConfirmationAlert({
title: "Unproxied Plugin",
content: "The plugin you are trying to install has not been proxied/verified by Vendetta staff. Are you sure you want to continue?",
confirmText: "Install",
onConfirm: () =>
installPlugin(input)
.then(() => showToast("Installed plugin", getAssetIDByName("Check")))
.catch((x) => showToast(x.toString(), getAssetIDByName("Small"))),
cancelText: "Cancel",
});
else return await installPlugin(input);
}}
/>
),
}, },
render: Plugins, render: Plugins,
}, },
@ -67,22 +88,22 @@ export const getScreens = (youKeys = false): Screen[] => [
key: formatKey("VendettaCustomPage", youKeys), key: formatKey("VendettaCustomPage", youKeys),
title: "Vendetta Page", title: "Vendetta Page",
shouldRender: () => false, shouldRender: () => false,
render: ({ render: PageView, noErrorBoundary, ...options }: { render: React.ComponentType, noErrorBoundary: boolean } & Record<string, object>) => { render: ({ render: PageView, noErrorBoundary, ...options }: { render: React.ComponentType; noErrorBoundary: boolean } & Record<string, object>) => {
const navigation = NavigationNative.useNavigation(); const navigation = NavigationNative.useNavigation();
navigation.addListener("focus", () => navigation.setOptions(without(options, "render", "noErrorBoundary"))); navigation.addListener("focus", () => navigation.setOptions(without(options, "render", "noErrorBoundary")));
return noErrorBoundary ? <PageView /> : <ErrorBoundary><PageView /></ErrorBoundary>; return noErrorBoundary ? <PageView /> : <ErrorBoundary><PageView /></ErrorBoundary>
} },
} },
] ];
export const getRenderableScreens = (youKeys = false) => getScreens(youKeys).filter(s => s.shouldRender?.() ?? true); export const getRenderableScreens = (youKeys = false) => getScreens(youKeys).filter(s => s.shouldRender?.() ?? true);
export const getPanelsScreens = () => keyMap(getScreens(), (s => ({ export const getPanelsScreens = () => keyMap(getScreens(), (s) => ({
title: s.title, title: s.title,
render: s.render, render: s.render,
...s.options, ...s.options,
}))); }));
export const getYouData = () => { export const getYouData = () => {
const screens = getScreens(true); const screens = getScreens(true);
@ -102,9 +123,9 @@ export const getYouData = () => {
getComponent: () => ({ navigation, route }: any) => { getComponent: () => ({ navigation, route }: any) => {
navigation.addListener("focus", () => navigation.setOptions(s.options)); navigation.addListener("focus", () => navigation.setOptions(s.options));
// TODO: Some ungodly issue causes the keyboard to automatically close in TextInputs on Android. Why?! // TODO: Some ungodly issue causes the keyboard to automatically close in TextInputs on Android. Why?!
return <RN.View style={styles.container}><s.render {...route.params} /></RN.View>; return <RN.View style={styles.container}><s.render {...route.params} /></RN.View>
} },
} },
})) })),
} };
} };