fix(android): cross-origin Bearer auth in Tauri shell
Inject a Tauri shell script during CI prep to disable service workers and attach Bearer tokens on cross-origin API requests. Enable Android third-party cookies in MainActivity and eval the same script from Rust on page load.
This commit is contained in:
32
.github/scripts/inject-tauri-shell.mjs
vendored
Normal file
32
.github/scripts/inject-tauri-shell.mjs
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
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 scriptPath = path.join(root, "template", "scripts", "tauri-shell.js");
|
||||
|
||||
export function injectTauriShell(distDir) {
|
||||
const indexPath = path.join(distDir, "index.html");
|
||||
if (!fs.existsSync(indexPath)) return;
|
||||
|
||||
let html = fs.readFileSync(indexPath, "utf8");
|
||||
if (html.includes(MARKER)) return;
|
||||
|
||||
const script = fs.readFileSync(scriptPath, "utf8").trim();
|
||||
const tag = `<script ${MARKER}>${script}</script>`;
|
||||
|
||||
if (html.includes("<head>")) {
|
||||
html = html.replace("<head>", `<head>\n${tag}`);
|
||||
} else if (html.includes("</head>")) {
|
||||
html = html.replace("</head>", `${tag}\n</head>`);
|
||||
} else if (html.includes("</body>")) {
|
||||
html = html.replace("</body>", `${tag}\n</body>`);
|
||||
} else {
|
||||
html += `\n${tag}\n`;
|
||||
}
|
||||
|
||||
fs.writeFileSync(indexPath, html);
|
||||
console.log("Injected Tauri shell script into index.html");
|
||||
}
|
||||
Reference in New Issue
Block a user