Merge remote-tracking branch 'origin/v3-alpha-linux' into v3-alpha

This commit is contained in:
Lea Anthony
2024-03-14 08:39:19 +11:00
89 changed files with 2006 additions and 2511 deletions
@@ -1,4 +1,4 @@
//go:build linux && (webkit2_36 || webkit2_40)
//go:build linux
package webview
@@ -12,11 +12,15 @@ package webview
import "C"
import (
"fmt"
"io"
"net/http"
"strings"
"unsafe"
)
const Webkit2MinMinorVersion = 40
func webkit_uri_scheme_request_get_http_method(req *C.WebKitURISchemeRequest) string {
method := C.GoString(C.webkit_uri_scheme_request_get_http_method(req))
return strings.ToUpper(method)
@@ -67,3 +71,67 @@ func webkit_uri_scheme_request_finish(req *C.WebKitURISchemeRequest, code int, h
C.webkit_uri_scheme_request_finish_with_response(req, resp)
return nil
}
func webkit_uri_scheme_request_get_http_body(req *C.WebKitURISchemeRequest) io.ReadCloser {
stream := C.webkit_uri_scheme_request_get_http_body(req)
if stream == nil {
return http.NoBody
}
return &webkitRequestBody{stream: stream}
}
type webkitRequestBody struct {
stream *C.GInputStream
closed bool
}
// Read implements io.Reader
func (r *webkitRequestBody) Read(p []byte) (int, error) {
if r.closed {
return 0, io.ErrClosedPipe
}
var content unsafe.Pointer
var contentLen int
if p != nil {
content = unsafe.Pointer(&p[0])
contentLen = len(p)
}
var n C.gsize
var gErr *C.GError
res := C.g_input_stream_read_all(r.stream, content, C.gsize(contentLen), &n, nil, &gErr)
if res == 0 {
return 0, formatGError("stream read failed", gErr)
} else if n == 0 {
return 0, io.EOF
}
return int(n), nil
}
func (r *webkitRequestBody) Close() error {
if r.closed {
return nil
}
r.closed = true
// https://docs.gtk.org/gio/method.InputStream.close.html
// Streams will be automatically closed when the last reference is dropped, but you might want to call this function
// to make sure resources are released as early as possible.
var err error
var gErr *C.GError
if C.g_input_stream_close(r.stream, nil, &gErr) == 0 {
err = formatGError("stream close failed", gErr)
}
C.g_object_unref(C.gpointer(r.stream))
r.stream = nil
return err
}
func formatGError(msg string, gErr *C.GError, args ...any) error {
if gErr != nil && gErr.message != nil {
msg += ": " + C.GoString(gErr.message)
C.g_error_free(gErr)
}
return fmt.Errorf(msg, args...)
}
@@ -1,21 +0,0 @@
//go:build linux && webkit2_36
package webview
/*
#cgo linux pkg-config: webkit2gtk-4.0
#include "webkit2/webkit2.h"
*/
import "C"
import (
"io"
"net/http"
)
const Webkit2MinMinorVersion = 36
func webkit_uri_scheme_request_get_http_body(_ *C.WebKitURISchemeRequest) io.ReadCloser {
return http.NoBody
}
@@ -1,83 +0,0 @@
//go:build linux && webkit2_40
package webview
/*
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0 gio-unix-2.0
#include "gtk/gtk.h"
#include "webkit2/webkit2.h"
#include "gio/gunixinputstream.h"
*/
import "C"
import (
"fmt"
"io"
"net/http"
"unsafe"
)
func webkit_uri_scheme_request_get_http_body(req *C.WebKitURISchemeRequest) io.ReadCloser {
stream := C.webkit_uri_scheme_request_get_http_body(req)
if stream == nil {
return http.NoBody
}
return &webkitRequestBody{stream: stream}
}
type webkitRequestBody struct {
stream *C.GInputStream
closed bool
}
// Read implements io.Reader
func (r *webkitRequestBody) Read(p []byte) (int, error) {
if r.closed {
return 0, io.ErrClosedPipe
}
var content unsafe.Pointer
var contentLen int
if p != nil {
content = unsafe.Pointer(&p[0])
contentLen = len(p)
}
var n C.gsize
var gErr *C.GError
res := C.g_input_stream_read_all(r.stream, content, C.gsize(contentLen), &n, nil, &gErr)
if res == 0 {
return 0, formatGError("stream read failed", gErr)
} else if n == 0 {
return 0, io.EOF
}
return int(n), nil
}
func (r *webkitRequestBody) Close() error {
if r.closed {
return nil
}
r.closed = true
// https://docs.gtk.org/gio/method.InputStream.close.html
// Streams will be automatically closed when the last reference is dropped, but you might want to call this function
// to make sure resources are released as early as possible.
var err error
var gErr *C.GError
if C.g_input_stream_close(r.stream, nil, &gErr) == 0 {
err = formatGError("stream close failed", gErr)
}
C.g_object_unref(C.gpointer(r.stream))
r.stream = nil
return err
}
func formatGError(msg string, gErr *C.GError, args ...any) error {
if gErr != nil && gErr.message != nil {
msg += ": " + C.GoString(gErr.message)
C.g_error_free(gErr)
}
return fmt.Errorf(msg, args...)
}
@@ -1,74 +0,0 @@
//go:build linux && webkit2_40 && purego
package webview
import (
"fmt"
"io"
"net/http"
"unsafe"
)
func webkit_uri_scheme_request_get_http_body(req *C.WebKitURISchemeRequest) io.ReadCloser {
stream := C.webkit_uri_scheme_request_get_http_body(req)
if stream == nil {
return http.NoBody
}
return &webkitRequestBody{stream: stream}
}
type webkitRequestBody struct {
stream *C.GInputStream
closed bool
}
// Read implements io.Reader
func (r *webkitRequestBody) Read(p []byte) (int, error) {
if r.closed {
return 0, io.ErrClosedPipe
}
var content unsafe.Pointer
var contentLen int
if p != nil {
content = unsafe.Pointer(&p[0])
contentLen = len(p)
}
var n C.gsize
var gErr *C.GError
res := C.g_input_stream_read_all(r.stream, content, C.gsize(contentLen), &n, nil, &gErr)
if res == 0 {
return 0, formatGError("stream read failed", gErr)
} else if n == 0 {
return 0, io.EOF
}
return int(n), nil
}
func (r *webkitRequestBody) Close() error {
if r.closed {
return nil
}
r.closed = true
// https://docs.gtk.org/gio/method.InputStream.close.html
// Streams will be automatically closed when the last reference is dropped, but you might want to call this function
// to make sure resources are released as early as possible.
var err error
var gErr *C.GError
if C.g_input_stream_close(r.stream, nil, &gErr) == 0 {
err = formatGError("stream close failed", gErr)
}
C.g_object_unref(C.gpointer(r.stream))
r.stream = nil
return err
}
func formatGError(msg string, gErr *C.GError, args ...any) error {
if gErr != nil && gErr.message != nil {
msg += ": " + C.GoString(gErr.message)
C.g_error_free(gErr)
}
return fmt.Errorf(msg, args...)
}
@@ -1,5 +0,0 @@
//go:build linux && webkit2_40
package webview
const Webkit2MinMinorVersion = 40
@@ -1,48 +0,0 @@
//go:build linux && !(webkit2_36 || webkit2_40)
package webview
/*
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
#include "gtk/gtk.h"
#include "webkit2/webkit2.h"
*/
import "C"
import (
"fmt"
"io"
"net/http"
"unsafe"
)
const Webkit2MinMinorVersion = 0
func webkit_uri_scheme_request_get_http_method(_ *C.WebKitURISchemeRequest) string {
return http.MethodGet
}
func webkit_uri_scheme_request_get_http_headers(_ *C.WebKitURISchemeRequest) http.Header {
// Fake some basic default headers that are needed if e.g. request are being proxied to the an external sever, like
// we do in the devserver.
h := http.Header{}
h.Add("Accept", "*/*")
h.Add("User-Agent", "wails.io/605.1.15")
return h
}
func webkit_uri_scheme_request_get_http_body(_ *C.WebKitURISchemeRequest) io.ReadCloser {
return http.NoBody
}
func webkit_uri_scheme_request_finish(req *C.WebKitURISchemeRequest, code int, header http.Header, stream *C.GInputStream, streamLength int64) error {
if code != http.StatusOK {
return fmt.Errorf("StatusCodes not supported: %d - %s", code, http.StatusText(code))
}
cMimeType := C.CString(header.Get(HeaderContentType))
C.webkit_uri_scheme_request_finish(req, stream, C.gint64(streamLength), cMimeType)
C.free(unsafe.Pointer(cMimeType))
return nil
}
@@ -1,36 +0,0 @@
//go:build linux && !(webkit2_36 || webkit2_40) && purego
package webview
import (
"fmt"
"io"
"net/http"
"github.com/ebitengine/purego"
)
const Webkit2MinMinorVersion = 0
func webkit_uri_scheme_request_get_http_method(_ uintptr) string {
return http.MethodGet
}
func webkit_uri_scheme_request_get_http_headers(_ uintptr) http.Header {
return http.Header{}
}
func webkit_uri_scheme_request_get_http_body(_ uintptr) io.ReadCloser {
return http.NoBody
}
func webkit_uri_scheme_request_finish(req uintptr, code int, header http.Header, stream uintptr, streamLength int64) error {
if code != http.StatusOK {
return fmt.Errorf("StatusCodes not supported: %d - %s", code, http.StatusText(code))
}
var requestFinish func(uintptr, uintptr, int64, string)
purego.RegisterLibFunc(&requestFinish, webkit, "webkit_uri_scheme_request_finish")
requestFinish(req, stream, streamLength, header.Get(HeaderContentType))
return nil
}
@@ -1,4 +1,4 @@
//go:build linux && (webkit2_36 || webkit2_40) && purego
//go:build linux && purego
package webview
@@ -92,3 +92,67 @@ func webkit_uri_scheme_request_finish(req uintptr, code int, header http.Header,
return nil
}
func webkit_uri_scheme_request_get_http_body(req *C.WebKitURISchemeRequest) io.ReadCloser {
stream := C.webkit_uri_scheme_request_get_http_body(req)
if stream == nil {
return http.NoBody
}
return &webkitRequestBody{stream: stream}
}
type webkitRequestBody struct {
stream *C.GInputStream
closed bool
}
// Read implements io.Reader
func (r *webkitRequestBody) Read(p []byte) (int, error) {
if r.closed {
return 0, io.ErrClosedPipe
}
var content unsafe.Pointer
var contentLen int
if p != nil {
content = unsafe.Pointer(&p[0])
contentLen = len(p)
}
var n C.gsize
var gErr *C.GError
res := C.g_input_stream_read_all(r.stream, content, C.gsize(contentLen), &n, nil, &gErr)
if res == 0 {
return 0, formatGError("stream read failed", gErr)
} else if n == 0 {
return 0, io.EOF
}
return int(n), nil
}
func (r *webkitRequestBody) Close() error {
if r.closed {
return nil
}
r.closed = true
// https://docs.gtk.org/gio/method.InputStream.close.html
// Streams will be automatically closed when the last reference is dropped, but you might want to call this function
// to make sure resources are released as early as possible.
var err error
var gErr *C.GError
if C.g_input_stream_close(r.stream, nil, &gErr) == 0 {
err = formatGError("stream close failed", gErr)
}
C.g_object_unref(C.gpointer(r.stream))
r.stream = nil
return err
}
func formatGError(msg string, gErr *C.GError, args ...any) error {
if gErr != nil && gErr.message != nil {
msg += ": " + C.GoString(gErr.message)
C.g_error_free(gErr)
}
return fmt.Errorf(msg, args...)
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,7 +1,7 @@
package operatingsystem
/*
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0 javascriptcoregtk-4.1
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
#include <webkit2/webkit2.h>
*/
import "C"
+2
View File
@@ -38,8 +38,10 @@ tasks:
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/binding/assets/runtime.js
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/frameless/assets/runtime.js
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/window-api/assets/runtime.js
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/contextmenus/assets/runtime.js
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/wml/assets/runtime.js
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../internal/commands/build_assets/runtime/runtime.js
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/screen/assets/runtime.js
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../pkg/application/assets/alpha/runtime.js
- cmd: echo "Build Complete."
@@ -155,6 +155,11 @@ export const EventTypes = {
},
Linux: {
SystemThemeChanged: "linux:SystemThemeChanged",
WindowLoadChanged: "linux:WindowLoadChanged",
WindowDeleteEvent: "linux:WindowDeleteEvent",
WindowFocusIn: "linux:WindowFocusIn",
WindowFocusOut: "linux:WindowFocusOut",
ApplicationStartup: "linux:ApplicationStartup",
},
Common: {
ApplicationStarted: "common:ApplicationStarted",
@@ -155,6 +155,11 @@ export declare const EventTypes: {
},
Linux: {
SystemThemeChanged: string,
WindowLoadChanged: string,
WindowDeleteEvent: string,
WindowFocusIn: string,
WindowFocusOut: string,
ApplicationStartup: string,
},
Common: {
ApplicationStarted: string,