mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-18 00:19:58 +01:00
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>
93 lines
1.8 KiB
Go
93 lines
1.8 KiB
Go
//go:build linux && purego && !android
|
|
|
|
package webview
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/ebitengine/purego"
|
|
)
|
|
|
|
// NewRequest creates as new WebViewRequest based on a pointer to an `WebKitURISchemeRequest`
|
|
//
|
|
// Please make sure to call Release() when finished using the request.
|
|
func NewRequest(webKitURISchemeRequest uintptr) Request {
|
|
webkitReq := webKitURISchemeRequest
|
|
req := &request{req: webkitReq}
|
|
req.AddRef()
|
|
return req
|
|
}
|
|
|
|
var _ Request = &request{}
|
|
|
|
type request struct {
|
|
req uintptr
|
|
|
|
header http.Header
|
|
body io.ReadCloser
|
|
rw *responseWriter
|
|
}
|
|
|
|
func (r *request) AddRef() error {
|
|
var objectRef func(uintptr)
|
|
purego.RegisterLibFunc(&objectRef, gtk, "g_object_ref")
|
|
objectRef(r.req)
|
|
return nil
|
|
}
|
|
|
|
func (r *request) Release() error {
|
|
var objectUnref func(uintptr)
|
|
purego.RegisterLibFunc(&objectUnref, gtk, "g_object_unref")
|
|
objectUnref(r.req)
|
|
return nil
|
|
}
|
|
|
|
func (r *request) URL() (string, error) {
|
|
var getUri func(uintptr) string
|
|
purego.RegisterLibFunc(&getUri, webkit, "webkit_uri_scheme_request_get_uri")
|
|
return getUri(r.req), nil
|
|
}
|
|
|
|
func (r *request) Method() (string, error) {
|
|
return webkit_uri_scheme_request_get_http_method(r.req), nil
|
|
}
|
|
|
|
func (r *request) Header() (http.Header, error) {
|
|
if r.header != nil {
|
|
return r.header, nil
|
|
}
|
|
|
|
r.header = webkit_uri_scheme_request_get_http_headers(r.req)
|
|
return r.header, nil
|
|
}
|
|
|
|
func (r *request) Body() (io.ReadCloser, error) {
|
|
if r.body != nil {
|
|
return r.body, nil
|
|
}
|
|
|
|
// WebKit2GTK has currently no support for request bodies.
|
|
r.body = http.NoBody
|
|
|
|
return r.body, nil
|
|
}
|
|
|
|
func (r *request) Response() ResponseWriter {
|
|
if r.rw != nil {
|
|
return r.rw
|
|
}
|
|
|
|
r.rw = &responseWriter{req: r.req}
|
|
return r.rw
|
|
}
|
|
|
|
func (r *request) Close() error {
|
|
var err error
|
|
if r.body != nil {
|
|
err = r.body.Close()
|
|
}
|
|
r.Response().Finish()
|
|
r.Release()
|
|
return err
|
|
}
|