wails/v3/examples/android/frontend/index.html
Lea Anthony 4d8ec29feb feat: Add Android support for Wails v3
This commit adds comprehensive Android support for Wails v3, enabling
Go applications to run as native Android apps with WebView-based UI.

Key features:
- Android-specific application implementation with JNI bridge
- WebView integration via WebViewAssetLoader for serving assets
- JavaScript runtime injection and execution via JNI callbacks
- Binding call support with async result callbacks
- Event system support for Android platform
- Full example Android app with Gradle build system

Technical details:
- Uses CGO with Android NDK for cross-compilation
- Implements JNI callbacks for Go <-> Java communication
- Supports both ARM64 and x86_64 architectures
- WebView debugging support via Chrome DevTools Protocol
- Handles empty response body case in binding calls to prevent panic

Files added:
- v3/pkg/application/*_android.go - Android platform implementations
- v3/pkg/events/events_android.go - Android event definitions
- v3/internal/*/\*_android.go - Android-specific internal packages
- v3/examples/android/ - Complete example Android application
- v3/ANDROID_ARCHITECTURE.md - Architecture documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 21:06:59 +11:00

110 lines
5.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<link rel="icon" type="image/svg+xml" href="/wails.png"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/style.css"/>
<title>Wails App</title>
<!-- Android WebView setup - must run before module scripts to enable window._wails.invoke -->
<script>
// Android WebView exposes window.wails via addJavascriptInterface
// We need to set up window._wails.invoke before the module scripts run
if (window.wails && window.wails.invoke) {
console.log('[Wails Android Bootstrap] window.wails.invoke detected, setting up _wails');
window._wails = window._wails || {};
window._wails.invoke = function(m) {
return window.wails.invoke(typeof m === 'string' ? m : JSON.stringify(m));
};
} else {
console.log('[Wails Android Bootstrap] window.wails not available yet');
}
</script>
</head>
<body>
<div class="container">
<div>
<a data-wml-openURL="https://wails.io">
<img src="/wails.png" class="logo" alt="Wails logo"/>
</a>
<a data-wml-openURL="https://developer.mozilla.org/en-US/docs/Web/JavaScript">
<img src="/javascript.svg" class="logo vanilla" alt="JavaScript logo"/>
</a>
</div>
<h1>Wails + Javascript</h1>
<div class="card mobile-pane">
<div class="result">Demo Screens</div>
<div class="p-mobile-tabs-content">
<!-- Screen 1: Bindings -->
<div class="p-mobile-tabs--content active" id="screen-bindings">
<div class="result" id="result">Please enter your name below 👇</div>
<div class="input-box" id="input">
<input class="input" id="name" type="text" autocomplete="off"/>
<button class="p-btn p-prim-col" onclick="doGreet()">Greet</button>
</div>
</div>
<!-- Screen 2: Go Runtime -->
<div class="p-mobile-tabs--content" id="screen-go">
<div class="input-box">
<label><input type="checkbox" id="goScrollEnabled" checked onchange="setGoToggle('ios:setScrollEnabled', this.checked)"> Scroll Enabled (Go)</label>
</div>
<div class="input-box">
<label><input type="checkbox" id="goBounceEnabled" checked onchange="setGoToggle('ios:setBounceEnabled', this.checked)"> Bounce Enabled (Go)</label>
</div>
<div class="input-box">
<label><input type="checkbox" id="goIndicatorsEnabled" checked onchange="setGoToggle('ios:setScrollIndicatorsEnabled', this.checked)"> Scroll Indicators (Go)</label>
</div>
<div class="input-box">
<label><input type="checkbox" id="goNavGesturesEnabled" onchange="setGoToggle('ios:setBackForwardGesturesEnabled', this.checked)"> Back/Forward Gestures (Go)</label>
</div>
<div class="input-box">
<label><input type="checkbox" id="goLinkPreviewEnabled" checked onchange="setGoToggle('ios:setLinkPreviewEnabled', this.checked)"> Link Preview (Go)</label>
</div>
<div class="input-box">
<input class="input" id="uaInputGo" type="text" placeholder="Custom User Agent"/>
<button class="p-btn" onclick="emitGo('ios:setCustomUserAgent', {ua: document.getElementById('uaInputGo').value})">Set UA (Go)</button>
</div>
</div>
<!-- Screen 3: JS Runtime -->
<div class="p-mobile-tabs--content" id="screen-js">
<div class="input-box">
<button class="p-btn" onclick="doHaptic('light')">Haptic: Light</button>
<button class="p-btn" onclick="doHaptic('medium')">Haptic: Medium</button>
<button class="p-btn" onclick="doHaptic('heavy')">Haptic: Heavy</button>
<button class="p-btn p-prim-col" onclick="getDeviceInfo();">Get Device Info</button>
</div>
<div class="input-box">
<label><input type="checkbox" id="jsScrollEnabled" checked onchange="setJsToggle('Scroll.SetEnabled', this.checked)"> Scroll Enabled (JS)</label>
</div>
<div class="input-box">
<label><input type="checkbox" id="jsBounceEnabled" checked onchange="setJsToggle('Scroll.SetBounceEnabled', this.checked)"> Bounce Enabled (JS)</label>
</div>
<div class="input-box">
<label><input type="checkbox" id="jsIndicatorsEnabled" checked onchange="setJsToggle('Scroll.SetIndicatorsEnabled', this.checked)"> Scroll Indicators (JS)</label>
</div>
<div class="input-box">
<label><input type="checkbox" id="jsNavGesturesEnabled" onchange="setJsToggle('Navigation.SetBackForwardGesturesEnabled', this.checked)"> Back/Forward Gestures (JS)</label>
</div>
<div class="input-box">
<label><input type="checkbox" id="jsLinkPreviewEnabled" checked onchange="setJsToggle('Links.SetPreviewEnabled', this.checked)"> Link Preview (JS)</label>
</div>
<div class="input-box">
<input class="input" id="uaInputJs" type="text" placeholder="Custom User Agent"/>
<button class="p-btn" onclick="iosJsSet('UserAgent.Set', {ua: document.getElementById('uaInputJs').value})">Set UA</button>
</div>
<pre id="deviceInfo" style="white-space: pre-wrap; word-break: break-word;"></pre>
</div>
</div>
</div>
<div class="footer">
<div><p>Click on the Wails logo to learn more</p></div>
<div><p id="time">Listening for Time event...</p></div>
</div>
</div>
<script type="module" src="/main.js"></script>
</body>
</html>