fix(metro/common): polyfill url

This commit is contained in:
PalmDevs 2025-05-19 17:16:20 +07:00
parent d703120268
commit 59ffa77a3a
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
3 changed files with 24 additions and 9 deletions

View file

@ -5,17 +5,17 @@ import { installTheme } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after, instead } from "@lib/api/patcher";
import { VD_PROXY_PREFIX,VD_THEMES_CHANNEL_ID } from "@lib/utils/constants";
import { VD_PROXY_PREFIX, VD_THEMES_CHANNEL_ID } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { channels, url } from "@metro/common";
import { channels } from "@metro/common";
import { byMutableProp } from "@metro/filters";
import { findExports } from "@metro/finders";
import { findByProps, findByPropsLazy } from "@metro/wrappers";
import { showToast } from "@ui/toasts";
import { Linking } from "react-native";
const showSimpleActionSheet = findExports(byMutableProp("showSimpleActionSheet"));
const handleClick = findByPropsLazy("handleClick");
const { openURL } = lazyDestructure(() => url);
const { getChannelId } = lazyDestructure(() => channels);
const { getChannel } = lazyDestructure(() => findByProps("getChannel"));
@ -75,7 +75,7 @@ export default () => {
confirmText: Strings.INSTALL,
cancelText: Strings.CANCEL,
secondaryConfirmText: Strings.OPEN_IN_BROWSER,
onConfirmSecondary: () => openURL(url),
onConfirmSecondary: () => Linking.openURL(url),
});
})
);

View file

@ -9,9 +9,9 @@ import { BundleUpdaterManager } from "@lib/api/native/modules";
import { settings } from "@lib/api/settings";
import { openAlert } from "@lib/ui/alerts";
import { DISCORD_SERVER, GITHUB } from "@lib/utils/constants";
import { NavigationNative, url } from "@metro/common";
import { NavigationNative } from "@metro/common";
import { AlertActionButton, AlertActions, AlertModal, Stack, TableRow, TableRowGroup, TableSwitchRow } from "@metro/common/components";
import { ScrollView } from "react-native";
import { Linking, ScrollView } from "react-native";
export default function General() {
useProxy(settings);
@ -48,13 +48,13 @@ export default function General() {
arrow={true}
label={Strings.DISCORD_SERVER}
icon={<TableRow.Icon source={findAssetId("Discord")!} />}
onPress={() => url.openDeeplink(DISCORD_SERVER)}
onPress={() => Linking.openURL(DISCORD_SERVER)}
/>
<TableRow
arrow={true}
label={Strings.GITHUB}
icon={<TableRow.Icon source={findAssetId("img_account_sync_github_white")!} />}
onPress={() => url.openURL(GITHUB)}
onPress={() => Linking.openURL(GITHUB)}
/>
</TableRowGroup>
<TableRowGroup title={Strings.ACTIONS}>

View file

@ -2,6 +2,7 @@ import { lazyDestructure } from "@lib/utils/lazy";
import { findByFilePathLazy, findByProps, findByPropsLazy } from "@metro/wrappers";
import type { Dispatcher } from "./types/flux";
import { Linking } from "react-native";
export * as components from "./components";
@ -9,7 +10,21 @@ export * as components from "./components";
export const constants = findByPropsLazy("Fonts", "Permissions");
export const channels = findByPropsLazy("getVoiceChannelId");
export const i18n = findByPropsLazy("Messages");
export const url = findByPropsLazy("openURL", "openDeeplink");
// Polyfill LinkingUtils
const openURL = (url: string) => Linking.openURL(url);
export const url = nativeModuleProxy.NativeLinkingModule || nativeModuleProxy.DCDLinkingManager ? {
openURL,
openDeeplink: openURL,
handleSupportedURL: openURL,
isDiscordConnectOauth2Deeplink: () => {
console.warn("url.isDiscordConnectOauth2Deeplink is not implemented and will always return false");
return false;
},
showLongPressUrlActionSheet: () => console.warn("url.showLongPressUrlActionSheet is not implemented"),
handleMessageLinking: findByFilePathLazy("modules/links/native/handleContentLinking.tsx", true),
} : findByPropsLazy("openURL", "openDeeplink");
export const clipboard = findByPropsLazy("setString", "getString", "hasString");
export const assets = findByPropsLazy("registerAsset");
export const invites = findByPropsLazy("acceptInviteAndTransitionToInviteChannel");