[UI > QuickInstall] Fix simple action sheet patch on 195.x (#150)
This commit is contained in:
parent
b90cddd3d8
commit
f40af91ed9
1 changed files with 44 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { findByProps } from "@metro/filters";
|
import { findByProps, find } from "@metro/filters";
|
||||||
import { ReactNative as RN, channels, url } from "@metro/common";
|
import { ReactNative as RN, channels, url } from "@metro/common";
|
||||||
import { PROXY_PREFIX, THEMES_CHANNEL_ID } from "@lib/constants";
|
import { PROXY_PREFIX, THEMES_CHANNEL_ID } from "@lib/constants";
|
||||||
import { after, instead } from "@lib/patcher";
|
import { after, instead } from "@lib/patcher";
|
||||||
|
@ -8,7 +8,7 @@ import { showConfirmationAlert } from "@ui/alerts";
|
||||||
import { getAssetIDByName } from "@ui/assets";
|
import { getAssetIDByName } from "@ui/assets";
|
||||||
import { showToast } from "@ui/toasts";
|
import { showToast } from "@ui/toasts";
|
||||||
|
|
||||||
const showSimpleActionSheet = findByProps("showSimpleActionSheet");
|
const showSimpleActionSheet = find((m) => m?.showSimpleActionSheet && !Object.getOwnPropertyDescriptor(m, "showSimpleActionSheet")?.get);
|
||||||
const handleClick = findByProps("handleClick");
|
const handleClick = findByProps("handleClick");
|
||||||
const { openURL } = url;
|
const { openURL } = url;
|
||||||
const { getChannelId } = channels;
|
const { getChannelId } = channels;
|
||||||
|
@ -25,49 +25,57 @@ function typeFromUrl(url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function installWithToast(type: "Plugin" | "Theme", url: string) {
|
function installWithToast(type: "Plugin" | "Theme", url: string) {
|
||||||
(type === "Plugin" ? installPlugin : installTheme)(url).then(() => {
|
(type === "Plugin" ? installPlugin : installTheme)(url)
|
||||||
showToast("Successfully installed", getAssetIDByName("Check"));
|
.then(() => {
|
||||||
}).catch((e: Error) => {
|
showToast("Successfully installed", getAssetIDByName("Check"));
|
||||||
showToast(e.message, getAssetIDByName("Small"));
|
})
|
||||||
});
|
.catch((e: Error) => {
|
||||||
|
showToast(e.message, getAssetIDByName("Small"));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const patches = new Array<Function>;
|
const patches = new Array<Function>();
|
||||||
|
|
||||||
patches.push(after("showSimpleActionSheet", showSimpleActionSheet, (args) => {
|
patches.push(
|
||||||
if (args[0].key !== "LongPressUrl") return;
|
after("showSimpleActionSheet", showSimpleActionSheet, (args) => {
|
||||||
const { header: { title: url }, options } = args[0];
|
if (args[0].key !== "LongPressUrl") return;
|
||||||
|
const {
|
||||||
|
header: { title: url },
|
||||||
|
options,
|
||||||
|
} = args[0];
|
||||||
|
|
||||||
const urlType = typeFromUrl(url);
|
const urlType = typeFromUrl(url);
|
||||||
if (!urlType) return;
|
if (!urlType) return;
|
||||||
|
|
||||||
options.push({
|
options.push({
|
||||||
label: `Install ${urlType}`,
|
label: `Install ${urlType}`,
|
||||||
onPress: () => installWithToast(urlType, url),
|
onPress: () => installWithToast(urlType, url),
|
||||||
});
|
});
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
patches.push(instead("handleClick", handleClick, async function (this: any, args, orig) {
|
patches.push(
|
||||||
const { href: url } = args[0];
|
instead("handleClick", handleClick, async function (this: any, args, orig) {
|
||||||
|
const { href: url } = args[0];
|
||||||
|
|
||||||
const urlType = typeFromUrl(url);
|
const urlType = typeFromUrl(url);
|
||||||
if (!urlType) return orig.apply(this, args);
|
if (!urlType) return orig.apply(this, args);
|
||||||
|
|
||||||
// Make clicking on theme links only work in #themes, should there be a theme proxy in the future, this can be removed.
|
// Make clicking on theme links only work in #themes, should there be a theme proxy in the future, this can be removed.
|
||||||
if (urlType === "Theme" && getChannel(getChannelId())?.parent_id !== THEMES_CHANNEL_ID)
|
if (urlType === "Theme" && getChannel(getChannelId())?.parent_id !== THEMES_CHANNEL_ID) return orig.apply(this, args);
|
||||||
return orig.apply(this, args);
|
|
||||||
|
|
||||||
showConfirmationAlert({
|
showConfirmationAlert({
|
||||||
title: "Hold Up",
|
title: "Hold Up",
|
||||||
content: ["This link is a ", <RN.Text style={TextStyleSheet["text-md/semibold"]}>{urlType}</RN.Text>, ", would you like to install it?"],
|
content: ["This link is a ", <RN.Text style={TextStyleSheet["text-md/semibold"]}>{urlType}</RN.Text>, ", would you like to install it?"],
|
||||||
onConfirm: () => installWithToast(urlType, url),
|
onConfirm: () => installWithToast(urlType, url),
|
||||||
confirmText: "Install",
|
confirmText: "Install",
|
||||||
cancelText: "Cancel",
|
cancelText: "Cancel",
|
||||||
secondaryConfirmText: "Open in Browser",
|
secondaryConfirmText: "Open in Browser",
|
||||||
onConfirmSecondary: () => openURL(url),
|
onConfirmSecondary: () => openURL(url),
|
||||||
});
|
});
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return () => patches.forEach((p) => p());
|
return () => patches.forEach((p) => p());
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue