mobile: fix share extension not able to clip webpage

This commit is contained in:
Ammar Ahmed
2025-10-31 10:01:59 +05:00
parent dbecd6a466
commit 5921c61e98
5 changed files with 174 additions and 197 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,6 @@ import RNFetchBlob from "react-native-blob-util";
import WebView from "react-native-webview"; import WebView from "react-native-webview";
import { Config } from "./store"; import { Config } from "./store";
import { db } from "../app/common/database"; import { db } from "../app/common/database";
import { SUBSCRIPTION_STATUS } from "../app/utils/constants";
export const fetchHandle = createRef(); export const fetchHandle = createRef();
export const HtmlLoadingWebViewAgent = React.memo( export const HtmlLoadingWebViewAgent = React.memo(
@@ -40,6 +39,7 @@ export const HtmlLoadingWebViewAgent = React.memo(
const webview = useRef(); const webview = useRef();
const premium = useRef(false); const premium = useRef(false);
const corsProxy = Config.corsProxy; const corsProxy = Config.corsProxy;
const [isLoggedIn, setIsLoggedIn] = useState();
useImperativeHandle( useImperativeHandle(
fetchHandle, fetchHandle,
@@ -72,11 +72,8 @@ export const HtmlLoadingWebViewAgent = React.memo(
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const user = await db.user.getUser(); const user = await db.user.getUser();
const subscriptionStatus = setIsLoggedIn(!!user);
user?.subscription?.type || SUBSCRIPTION_STATUS.BASIC; console.log("USER", !!user);
premium.current =
user && subscriptionStatus !== SUBSCRIPTION_STATUS.BASIC;
const clipperPath = const clipperPath =
Platform.OS === "ios" Platform.OS === "ios"
? RNFetchBlob.fs.dirs.MainBundleDir + ? RNFetchBlob.fs.dirs.MainBundleDir +
@@ -91,6 +88,7 @@ export const HtmlLoadingWebViewAgent = React.memo(
.catch((e) => console.log(e)); .catch((e) => console.log(e));
})(); })();
}, []); }, []);
console.log(isLoggedIn);
return !source || !clipper ? null : ( return !source || !clipper ? null : (
<WebView <WebView
@@ -103,7 +101,8 @@ export const HtmlLoadingWebViewAgent = React.memo(
height: 100, height: 100,
position: "absolute", position: "absolute",
opacity: 0, opacity: 0,
zIndex: -1 zIndex: -1,
pointerEvents: "none"
}} }}
useSharedProcessPool={false} useSharedProcessPool={false}
pointerEvents="none" pointerEvents="none"
@@ -123,7 +122,11 @@ export const HtmlLoadingWebViewAgent = React.memo(
console.log("Error handling webview message", e); console.log("Error handling webview message", e);
} }
}} }}
injectedJavaScriptBeforeContentLoaded={script(clipper, premium.current)} injectedJavaScriptBeforeContentLoaded={script(
clipper,
corsProxy,
isLoggedIn
)}
onError={() => { onError={() => {
console.log("Error loading page"); console.log("Error loading page");
loadHandler.current?.(); loadHandler.current?.();
@@ -137,9 +140,11 @@ export const HtmlLoadingWebViewAgent = React.memo(
() => true () => true
); );
const script = (clipper, pro) => ` const script = (clipper, corsProxy, loggedIn) => `
globalThis.module = {};
${clipper} ${clipper}
function postMessage(type, value) { function postMessage(type, value) {
if (window.ReactNativeWebView) { if (window.ReactNativeWebView) {
window.ReactNativeWebView.postMessage( window.ReactNativeWebView.postMessage(
@@ -158,10 +163,10 @@ function postMessage(type, value) {
postMessage("error", globalThis.Clipper.clipPage); postMessage("error", globalThis.Clipper.clipPage);
} else { } else {
globalThis.Clipper.clipPage(document,false, { globalThis.Clipper.clipPage(document,false, {
images: ${pro}, images: ${loggedIn ? "true" : "false"},
inlineImages: false, inlineImages: false,
styles: false, styles: false,
corsProxy: undefined corsProxy: ${corsProxy ? `"${corsProxy}"` : "undefined"}
}).then(result => { }).then(result => {
postMessage("html", result); postMessage("html", result);
}).catch(e => { }).catch(e => {

View File

@@ -267,7 +267,6 @@ const ShareView = () => {
); );
const onLoad = useCallback(() => { const onLoad = useCallback(() => {
console.log(noteContent.current, "current...");
eSendEvent(eOnLoadNote + "shareEditor", { eSendEvent(eOnLoadNote + "shareEditor", {
id: null, id: null,
content: { content: {
@@ -747,7 +746,7 @@ const ShareView = () => {
</Paragraph> </Paragraph>
{rawData.value && isURL(rawData.value) ? ( {rawData.value && isURL(rawData.value) ? (
<Button <Button
type={mode === 2 ? "inverted" : "transparent"} type={mode === 2 ? "inverted" : "plain"}
icon={mode === 2 ? "radiobox-marked" : "radiobox-blank"} icon={mode === 2 ? "radiobox-marked" : "radiobox-blank"}
onPress={() => changeMode(2)} onPress={() => changeMode(2)}
title={modes[2].title} title={modes[2].title}
@@ -758,9 +757,9 @@ const ShareView = () => {
/> />
) : null} ) : null}
<Button <Button
type={mode === 1 ? "inverted" : "transparent"} type={mode === 1 ? "inverted" : "plain"}
icon={mode === 1 ? "radiobox-marked" : "radiobox-blank"} icon={mode === 1 ? "radiobox-marked" : "radiobox-blank"}
onPress={() => changeMode(2)} onPress={() => changeMode(1)}
title={modes[1].title} title={modes[1].title}
height={30} height={30}
style={{ style={{

View File

@@ -26,7 +26,7 @@ declare global {
}; };
} }
global.Clipper = { globalThis.Clipper = {
clipArticle, clipArticle,
clipPage clipPage
}; };