mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-15 15:15:51 +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>
82 lines
1.6 KiB
Go
82 lines
1.6 KiB
Go
//go:build linux && !android
|
|
|
|
package webview
|
|
|
|
/*
|
|
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.1 gio-unix-2.0
|
|
|
|
#include "gtk/gtk.h"
|
|
#include "webkit2/webkit2.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"unsafe"
|
|
)
|
|
|
|
// NewRequest creates as new WebViewRequest based on a pointer to an `WebKitURISchemeRequest`
|
|
func NewRequest(webKitURISchemeRequest unsafe.Pointer) Request {
|
|
webkitReq := (*C.WebKitURISchemeRequest)(webKitURISchemeRequest)
|
|
C.g_object_ref(C.gpointer(webkitReq))
|
|
|
|
req := &request{req: webkitReq}
|
|
return newRequestFinalizer(req)
|
|
}
|
|
|
|
var _ Request = &request{}
|
|
|
|
type request struct {
|
|
req *C.WebKitURISchemeRequest
|
|
|
|
header http.Header
|
|
body io.ReadCloser
|
|
rw *responseWriter
|
|
}
|
|
|
|
func (r *request) URL() (string, error) {
|
|
return C.GoString(C.webkit_uri_scheme_request_get_uri(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
|
|
}
|
|
|
|
r.body = webkit_uri_scheme_request_get_http_body(r.req)
|
|
|
|
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()
|
|
C.g_object_unref(C.gpointer(r.req))
|
|
return err
|
|
}
|