|
| 1 | +#!/bin/bash |
| 2 | +# Re-apply the custom URL scheme intent filters to the generated Android manifest. |
| 3 | +# |
| 4 | +# Why this exists: |
| 5 | +# The auth flow finishes by redirecting the system browser to a custom scheme, |
| 6 | +# iblai-skills:///sso-login-complete?data=…, which must route back into the app. |
| 7 | +# iOS handles this scheme via its WebView delegate; Android requires an explicit |
| 8 | +# <intent-filter> in AndroidManifest.xml. Once the OS routes it, the deep-link |
| 9 | +# plugin emits the URL and handle_deep_link_url (src-tauri/src/lib.rs) navigates |
| 10 | +# the WebView to the real https completion URL. |
| 11 | +# |
| 12 | +# src-tauri/gen/android is generated and gitignored, so a fresh checkout or a |
| 13 | +# `cargo tauri android init` loses the manifest edit. This script re-applies it |
| 14 | +# and is wired into the `tauri-android-*` Makefile targets so it runs before |
| 15 | +# every Android build. It is idempotent. |
| 16 | +set -e |
| 17 | + |
| 18 | +MANIFEST="$(dirname "$0")/../src-tauri/gen/android/app/src/main/AndroidManifest.xml" |
| 19 | + |
| 20 | +if [ ! -f "$MANIFEST" ]; then |
| 21 | + echo "⚠ Android manifest not found at: $MANIFEST" |
| 22 | + echo " Run 'cargo tauri android init' (make tauri-android-init) first." |
| 23 | + exit 0 |
| 24 | +fi |
| 25 | + |
| 26 | +if grep -q 'android:scheme="iblai-skills"' "$MANIFEST"; then |
| 27 | + echo "✓ Custom-scheme intent filters already present in AndroidManifest.xml — nothing to do." |
| 28 | + exit 0 |
| 29 | +fi |
| 30 | + |
| 31 | +echo "→ Injecting iblai-skills / ai.ibl.skills intent filters into AndroidManifest.xml…" |
| 32 | + |
| 33 | +# Insert the filters immediately before the closing </activity> of MainActivity |
| 34 | +# (the manifest has a single <activity>). |
| 35 | +awk ' |
| 36 | + /<\/activity>/ && !done { |
| 37 | + print " <!-- Custom URL scheme for the SSO deep-link return from the" |
| 38 | + print " system browser (iblai-skills:///sso-login-complete?data=…)." |
| 39 | + print " iOS handles this scheme via its WebView delegate; Android" |
| 40 | + print " needs an explicit intent filter so the OS routes the redirect" |
| 41 | + print " back into the app. Re-applied by" |
| 42 | + print " scripts/android-add-deep-link-scheme.sh because gen/android is" |
| 43 | + print " generated/gitignored. Custom schemes cannot use autoVerify. -->" |
| 44 | + print " <intent-filter>" |
| 45 | + print " <action android:name=\"android.intent.action.VIEW\" />" |
| 46 | + print " <category android:name=\"android.intent.category.DEFAULT\" />" |
| 47 | + print " <category android:name=\"android.intent.category.BROWSABLE\" />" |
| 48 | + print " <data android:scheme=\"iblai-skills\" />" |
| 49 | + print " </intent-filter>" |
| 50 | + print " <intent-filter>" |
| 51 | + print " <action android:name=\"android.intent.action.VIEW\" />" |
| 52 | + print " <category android:name=\"android.intent.category.DEFAULT\" />" |
| 53 | + print " <category android:name=\"android.intent.category.BROWSABLE\" />" |
| 54 | + print " <data android:scheme=\"ai.ibl.skills\" />" |
| 55 | + print " </intent-filter>" |
| 56 | + done = 1 |
| 57 | + } |
| 58 | + { print } |
| 59 | +' "$MANIFEST" > "$MANIFEST.tmp" && mv "$MANIFEST.tmp" "$MANIFEST" |
| 60 | + |
| 61 | +echo "✓ Intent filters injected into AndroidManifest.xml." |
0 commit comments