* Add main-menu Rotation for webview-only page turns. Cycle 0/90/180/270 from the History menu without rotating system or chrome; swap document width/height so pages reflow like a landscape layout, then map onto the portrait nest (Chromium ignores View scale, and nest LayoutParams blank tabs). Co-authored-by: Cursor <cursoragent@cursor.com> * Make webview Rotation reliable on physical devices. Drive CSS from the active tab WebView with Java-side CSS pixel sizes, retries, and a post-apply verify — visualViewport-only sizing and a nest search were enough on the emulator but could silently no-op on real WebView/density setups. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
83 lines
3.6 KiB
Bash
Executable file
83 lines
3.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
SRC="${ROOT_DIR}/sources/java/com/mycompany/app/web/WebViewRotationHelper.java"
|
|
OUT_SMALI="${ROOT_DIR}/app/smali_classes4/com/mycompany/app/web"
|
|
TOOLS="${ROOT_DIR}/tools"
|
|
ANDROID_HOME="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-${HOME}/android-sdk}}"
|
|
ANDROID_JAR="$(ls -1 "${ANDROID_HOME}/platforms"/android-*/android.jar 2>/dev/null | sort -V | tail -1)"
|
|
D8="$(find "${ANDROID_HOME}/build-tools" -name d8 -type f 2>/dev/null | sort -V | tail -1)"
|
|
DEX_TOOLS_ZIP="${TOOLS}/dex-tools-v2.4.zip"
|
|
DEX_TOOLS_DIR="${TOOLS}/dex-tools-v2.4"
|
|
|
|
mkdir -p "${TOOLS}" "${OUT_SMALI}"
|
|
|
|
if [[ ! -f "${ANDROID_JAR}" ]]; then
|
|
echo "error: android.jar not found" >&2
|
|
exit 1
|
|
fi
|
|
if [[ -z "${D8}" ]]; then
|
|
echo "error: d8 not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "${DEX_TOOLS_DIR}/d2j-dex2jar.sh" ]]; then
|
|
if [[ ! -f "${DEX_TOOLS_ZIP}" ]]; then
|
|
echo "Downloading dex-tools v2.4..."
|
|
curl -fsSL -o "${DEX_TOOLS_ZIP}" \
|
|
"https://github.com/pxb1988/dex2jar/releases/download/v2.4/dex-tools-v2.4.zip"
|
|
fi
|
|
unzip -qo "${DEX_TOOLS_ZIP}" -d "${TOOLS}"
|
|
fi
|
|
chmod +x "${DEX_TOOLS_DIR}/"*.sh "${DEX_TOOLS_DIR}/d2j_invoke.sh" 2>/dev/null || true
|
|
|
|
STAGE="$(mktemp -d)"
|
|
cleanup() { rm -rf "${STAGE}"; }
|
|
trap cleanup EXIT
|
|
|
|
echo "Compiling WebViewRotationHelper..."
|
|
javac --release 11 -classpath "${ANDROID_JAR}" -d "${STAGE}/classes" "${SRC}"
|
|
mkdir -p "${STAGE}/dex"
|
|
mapfile -t CLASS_FILES < <(find "${STAGE}/classes" -name '*.class' -type f)
|
|
"${D8}" --min-api 23 --lib "${ANDROID_JAR}" --output "${STAGE}/dex" "${CLASS_FILES[@]}"
|
|
bash "${DEX_TOOLS_DIR}/d2j-baksmali.sh" -f -o "${STAGE}/out" "${STAGE}/dex/classes.dex"
|
|
find "${STAGE}/out" -name '*.smali' -print0 | xargs -0 sed -i \
|
|
-e 's/\\u002d\$\$Nest\$/\-$$Nest$/g' \
|
|
-e 's/const\/high16 \([vp][0-9]*\), 16384/const\/high16 \1, 0x40000000 # 2.0f/g' \
|
|
-e 's/const\/high16 \([vp][0-9]*\), 17076/const\/high16 \1, 0x42b40000 # 90.0f/g' \
|
|
-e 's/const\/high16 \([vp][0-9]*\), 16256/const\/high16 \1, 0x3f800000 # 1.0f/g' \
|
|
-e 's/\.field private final static TAG:/.field private static final TAG:/g'
|
|
|
|
# Prefer classic access$000 over javac nest mates for apktool compatibility.
|
|
if rg -q -- '-\\$\\$Nest\\$smapplyNow' "${STAGE}/out/com/mycompany/app/web" 2>/dev/null \
|
|
|| rg -q 'Nest\$smapplyNow' "${STAGE}/out/com/mycompany/app/web"; then
|
|
python3 - <<'PY' "${STAGE}/out/com/mycompany/app/web"
|
|
import pathlib, re, sys
|
|
root = pathlib.Path(sys.argv[1])
|
|
for path in root.glob("WebViewRotationHelper*.smali"):
|
|
text = path.read_text()
|
|
text = text.replace(
|
|
"Lcom/mycompany/app/web/WebViewRotationHelper;->-$$Nest$smapplyNow(Landroid/view/View;I)V",
|
|
"Lcom/mycompany/app/web/WebViewRotationHelper;->access$000(Landroid/view/View;I)V",
|
|
)
|
|
text = re.sub(
|
|
r"\.method static bridge synthetic -\$\$Nest\$smapplyNow\(Landroid/view/View;I\)V\n"
|
|
r"(?: \.registers 2\n)?"
|
|
r"(?: )?invoke-static \{ p0, p1 \}, Lcom/mycompany/app/web/WebViewRotationHelper;->applyNow\(Landroid/view/View;I\)V\n"
|
|
r"(?: )?return-void\n"
|
|
r"\.end method\n",
|
|
".method static synthetic access$000(Landroid/view/View;I)V\n"
|
|
" .locals 0\n\n"
|
|
" invoke-static {p0, p1}, Lcom/mycompany/app/web/WebViewRotationHelper;->applyNow(Landroid/view/View;I)V\n\n"
|
|
" return-void\n"
|
|
".end method\n",
|
|
text,
|
|
)
|
|
path.write_text(text)
|
|
PY
|
|
fi
|
|
|
|
rm -f "${OUT_SMALI}"/WebViewRotationHelper*.smali
|
|
cp -a "${STAGE}/out/com/mycompany/app/web/WebViewRotationHelper"* "${OUT_SMALI}/"
|
|
echo "Wrote ${OUT_SMALI}/WebViewRotationHelper*.smali"
|