227 lines
7.8 KiB
TypeScript
227 lines
7.8 KiB
TypeScript
// Metro module 10666 (f10667).
|
|
import { NativeModules } from "react-native";
|
|
import * as _PlatformUtils from "../../../utils/PlatformUtils";
|
|
import Module1271 from "../../../_bundle/Module1271";
|
|
import SentryUtils_native from "../../../utils/SentryUtils.native";
|
|
function $mk116043($env) {
|
|
return function generateWebviewHtml(a0) {
|
|
const { iFrameUri, iFrameSandboxAttributes, referrerPolicy } = a0;
|
|
let insets = a0.insets;
|
|
const messageForDisallowedNavigationError = a0.messageForDisallowedNavigationError;
|
|
const isAndroid = _PlatformUtils.isAndroid();
|
|
let r9 = "";
|
|
let r8 = "";
|
|
if (isAndroid) {
|
|
if (insets == null) {
|
|
insets = {
|
|
top: 0,
|
|
bottom: 0,
|
|
left: 0,
|
|
right: 0
|
|
};
|
|
}
|
|
r8 = `
|
|
<script type="text/javascript">
|
|
var iframe = document.getElementById("activityFrame");
|
|
var iframeWindow = iframe.contentWindow;
|
|
var isIframeLoaded = false;
|
|
${`
|
|
iframeWindow.addEventListener("load", () => {
|
|
var iframeDoc = iframeWindow.document;
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-left', '${insets.left}px');
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-right', '${insets.right}px');
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-top', '${insets.top}px');
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-bottom', '${insets.bottom}px');
|
|
isIframeLoaded = true;
|
|
});
|
|
`}
|
|
${`
|
|
function updateSafeAreaVars(insets) {
|
|
var iframeDoc = iframeWindow.document;
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-left', \`\${insets.left}px\`);
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-right', \`\${insets.right}px\`);
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-top', \`\${insets.top}px\`);
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-bottom', \`\${insets.bottom}px\`);
|
|
iframeWindow.dispatchEvent(new Event('resize'));
|
|
// Force redraw
|
|
iframeDoc.documentElement.offsetHeight;
|
|
}
|
|
iframeWindow.addEventListener('message', function (e) {
|
|
const messageData = e.data;
|
|
const {type, data} = messageData;
|
|
if (type === 'safeAreaUpdateEvent') {
|
|
const {insets} = data;
|
|
if (isIframeLoaded) {
|
|
updateSafeAreaVars(insets);
|
|
} else {
|
|
iframeWindow.addEventListener("load", () => {
|
|
updateSafeAreaVars(insets);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
`}
|
|
</script>
|
|
`;
|
|
}
|
|
if (messageForDisallowedNavigationError != null) {
|
|
r9 = `
|
|
<script type="text/javascript">
|
|
var iframe = document.getElementById("activityFrame");
|
|
var iframeWindow = iframe.contentWindow;
|
|
${`
|
|
iframeWindow.addEventListener('beforeunload', function (e) {
|
|
window.ReactNativeWebView.postMessage('${messageForDisallowedNavigationError}');
|
|
e.preventDefault();
|
|
});
|
|
`}
|
|
</script>
|
|
`;
|
|
}
|
|
return `
|
|
<html>
|
|
<head>
|
|
<style>
|
|
body {
|
|
padding: 0;
|
|
margin: 0;
|
|
width: 100vw;
|
|
min-height: 100vh; /* This keeps a small white gap at the bottom of the screen, the options below help prevent this. */
|
|
min-height: -moz-available; /* See: https://ilxanlar.medium.com/you-shouldnt-rely-on-css-100vh-and-here-s-why-1b4721e74487 for more info */
|
|
min-height: -webkit-fill-available;
|
|
min-height: fill-available;
|
|
}
|
|
</style>
|
|
<meta
|
|
name="viewport"
|
|
content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, viewport-fit=cover"
|
|
/>
|
|
</head>
|
|
<body>
|
|
<script type="text/javascript">
|
|
window.addEventListener('message', e => {
|
|
window.ReactNativeWebView.postMessage(JSON.stringify(e.data));
|
|
});
|
|
</script>
|
|
<iframe id="activityFrame" width="100%" height="100%" src="${iFrameUri}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen sandbox="${iFrameSandboxAttributes}" referrerPolicy="${referrerPolicy}">
|
|
</iframe>
|
|
${r8}
|
|
${r9}
|
|
</body>
|
|
</html>
|
|
`;
|
|
};
|
|
}
|
|
let env7163 = {};
|
|
export default async function createWebviewHtmlFile(c26786_0) {
|
|
let r97;
|
|
let c26786_1, c26786_2, c26786_3;
|
|
let c26786_4 = 0;
|
|
const r16 = env7163;
|
|
try {
|
|
let env30282;
|
|
c26786_2 = r16;
|
|
const r39 = env30282 = {
|
|
$parent: r16
|
|
};
|
|
c26786_1 = r39;
|
|
env30282[0] = void 0;
|
|
env30282[1] = void 0;
|
|
env30282[2] = void 0;
|
|
env30282[3] = void 0;
|
|
env30282[4] = void 0;
|
|
env30282[0] = c26786_0.iFrameUri;
|
|
env30282[1] = c26786_0.iFrameSandboxAttributes;
|
|
env30282[2] = c26786_0.referrerPolicy;
|
|
env30282[3] = c26786_0.insets;
|
|
env30282[4] = c26786_0.messageForDisallowedNavigationError;
|
|
env30282[5] = void 0;
|
|
env30282[6] = void 0;
|
|
await void 0;
|
|
env30282[5] = "discord_activity_data/activity.html";
|
|
const r66 = {
|
|
iFrameUri: env30282[0],
|
|
iFrameSandboxAttributes: env30282[1],
|
|
referrerPolicy: env30282[2],
|
|
insets: env30282[3],
|
|
messageForDisallowedNavigationError: env30282[4]
|
|
};
|
|
env30282[6] = $mk116043(env7163)(r66);
|
|
c26786_4 = 1;
|
|
r97 = _PlatformUtils.isAndroid() ? await (Module1271 == null ? void 0 : Module1271.writeFile("cache", env30282[5], env30282[6], "utf8")) : await NativeModules.DCDFileManager.writeFile("cache", env30282[5], env30282[6], "utf8");
|
|
c26786_4 = 0;
|
|
} catch ($e) {
|
|
const r37 = $e;
|
|
let r8 = r37;
|
|
c26786_3 = r37;
|
|
if (c26786_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r146 = c26786_3;
|
|
c26786_4 = 0;
|
|
env30282[7] = r146;
|
|
SentryUtils_native.captureException(env30282[7]);
|
|
} catch (r142) {
|
|
r8 = r142;
|
|
c26786_3 = r142;
|
|
if (c26786_4 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r97;
|
|
};
|
|
export function createInjectedJavascriptForIOS(a0) {
|
|
const r1 = a0 == null ? {
|
|
top: 0,
|
|
bottom: 0,
|
|
left: 0,
|
|
right: 0
|
|
} : a0;
|
|
return `
|
|
var iframeWindow = window;
|
|
var isIframeLoaded = false;
|
|
${`
|
|
iframeWindow.addEventListener("load", () => {
|
|
var iframeDoc = iframeWindow.document;
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-left', '${r1.left}px');
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-right', '${r1.right}px');
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-top', '${r1.top}px');
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-bottom', '${r1.bottom}px');
|
|
isIframeLoaded = true;
|
|
});
|
|
`}
|
|
${`
|
|
function updateSafeAreaVars(insets) {
|
|
var iframeDoc = iframeWindow.document;
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-left', \`\${insets.left}px\`);
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-right', \`\${insets.right}px\`);
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-top', \`\${insets.top}px\`);
|
|
iframeDoc.documentElement.style.setProperty('--discord-safe-area-inset-bottom', \`\${insets.bottom}px\`);
|
|
iframeWindow.dispatchEvent(new Event('resize'));
|
|
// Force redraw
|
|
iframeDoc.documentElement.offsetHeight;
|
|
}
|
|
iframeWindow.addEventListener('message', function (e) {
|
|
const messageData = e.data;
|
|
const {type, data} = messageData;
|
|
if (type === 'safeAreaUpdateEvent') {
|
|
const {insets} = data;
|
|
if (isIframeLoaded) {
|
|
updateSafeAreaVars(insets);
|
|
} else {
|
|
iframeWindow.addEventListener("load", () => {
|
|
updateSafeAreaVars(insets);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
`}
|
|
`;
|
|
}
|