fix(android): enable camera permission for WebView getUserMedia
Declare CAMERA in AndroidManifest so RustWebChromeClient can show the system permission dialog. Inject Permissions-Policy meta for camera access in the Tauri shell.
This commit is contained in:
23
.github/scripts/inject-tauri-shell.mjs
vendored
23
.github/scripts/inject-tauri-shell.mjs
vendored
@@ -5,6 +5,8 @@ import { fileURLToPath } from "node:url";
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const root = path.resolve(__dirname, "../..");
|
||||
const MARKER = "data-web2app-tauri-shell";
|
||||
const PERMISSIONS_POLICY_MARKER = "data-web2app-permissions-policy";
|
||||
const PERMISSIONS_POLICY_TAG = `<meta ${PERMISSIONS_POLICY_MARKER} http-equiv="Permissions-Policy" content="camera=*, microphone=*" />`;
|
||||
const scriptPath = path.join(root, "template", "scripts", "tauri-shell.js");
|
||||
|
||||
export function injectTauriShell(distDir) {
|
||||
@@ -12,19 +14,26 @@ export function injectTauriShell(distDir) {
|
||||
if (!fs.existsSync(indexPath)) return;
|
||||
|
||||
let html = fs.readFileSync(indexPath, "utf8");
|
||||
if (html.includes(MARKER)) return;
|
||||
const needsPolicy = !html.includes(PERMISSIONS_POLICY_MARKER);
|
||||
const needsScript = !html.includes(MARKER);
|
||||
if (!needsPolicy && !needsScript) return;
|
||||
|
||||
const script = fs.readFileSync(scriptPath, "utf8").trim();
|
||||
const tag = `<script ${MARKER}>${script}</script>`;
|
||||
const injections = [];
|
||||
if (needsPolicy) injections.push(PERMISSIONS_POLICY_TAG);
|
||||
if (needsScript) {
|
||||
const script = fs.readFileSync(scriptPath, "utf8").trim();
|
||||
injections.push(`<script ${MARKER}>${script}</script>`);
|
||||
}
|
||||
const block = `${injections.join("\n")}\n`;
|
||||
|
||||
if (html.includes("<head>")) {
|
||||
html = html.replace("<head>", `<head>\n${tag}`);
|
||||
html = html.replace("<head>", `<head>\n${block}`);
|
||||
} else if (html.includes("</head>")) {
|
||||
html = html.replace("</head>", `${tag}\n</head>`);
|
||||
html = html.replace("</head>", `${block}</head>`);
|
||||
} else if (html.includes("</body>")) {
|
||||
html = html.replace("</body>", `${tag}\n</body>`);
|
||||
html = html.replace("</body>", `${block}</body>`);
|
||||
} else {
|
||||
html += `\n${tag}\n`;
|
||||
html += `\n${block}`;
|
||||
}
|
||||
|
||||
fs.writeFileSync(indexPath, html);
|
||||
|
||||
Reference in New Issue
Block a user