wails/v3/pkg/application/messageprocessor_android.go
Lea Anthony 637713fae6 feat: adapt iOS and Android message processors to RuntimeRequest transport
Transport layer refactor adaptations for mobile platforms:

- Refactor processIOSMethod to use RuntimeRequest signature
- Refactor processAndroidMethod to use RuntimeRequest signature
- Add androidRequest constant (12) and handler to messageprocessor.go
- Update messageprocessor_mobile_stub.go for non-mobile builds
- Fix undefined windowID variable (use req.WebviewWindowID)
- Add iOS event generation to tasks/events/generate.go
- Add InvalidIOSCallError and InvalidAndroidCallError to errs package
- Update iOS delegate and webview files with generated event handlers

iOS methods refactored: Haptics.Impact, Device.Info, Scroll settings,
Navigation gestures, Link previews, Debug inspector, UserAgent

Android methods refactored: Haptics.Vibrate, Device.Info, Toast.Show

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-10 21:27:04 +11:00

70 lines
1.7 KiB
Go

//go:build android
package application
import (
"github.com/wailsapp/wails/v3/pkg/errs"
)
const (
AndroidHapticsVibrate = 0
AndroidDeviceInfo = 1
AndroidToast = 2
)
var androidMethodNames = map[int]string{
AndroidHapticsVibrate: "Haptics.Vibrate",
AndroidDeviceInfo: "Device.Info",
AndroidToast: "Toast.Show",
}
func (m *MessageProcessor) processAndroidMethod(req *RuntimeRequest, window Window) (any, error) {
args := req.Args.AsMap()
switch req.Method {
case AndroidHapticsVibrate:
duration := 100 // default 100ms
if d := args.Int("duration"); d != nil {
duration = *d
}
androidHapticsVibrate(duration)
return unit, nil
case AndroidDeviceInfo:
return androidDeviceInfo(), nil
case AndroidToast:
message := ""
if s := args.String("message"); s != nil {
message = *s
}
androidShowToast(message)
return unit, nil
default:
return nil, errs.NewInvalidAndroidCallErrorf("unknown method: %d", req.Method)
}
}
// processIOSMethod is a stub on Android
func (m *MessageProcessor) processIOSMethod(req *RuntimeRequest, window Window) (any, error) {
return nil, errs.NewInvalidIOSCallErrorf("iOS methods not available on Android")
}
// Android-specific runtime functions (stubs for now)
func androidHapticsVibrate(durationMs int) {
// TODO: Implement via JNI to Android Vibrator service
androidLogf("debug", "Haptics vibrate: %dms", durationMs)
}
func androidDeviceInfo() map[string]interface{} {
// TODO: Implement via JNI to get actual device info
return map[string]interface{}{
"platform": "android",
"model": "Unknown",
"version": "Unknown",
}
}
func androidShowToast(message string) {
// TODO: Implement via JNI to Android Toast
androidLogf("debug", "Toast: %s", message)
}