mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Revert "Merge branch 'v3-alpha_linux' into v3-alpha"
This reverts commitb317efaf2c, reversing changes made to29b9c5200f.
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
//go:build linux && purego
|
||||
// +build linux,purego
|
||||
|
||||
package webview
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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 {
|
||||
fmt.Println("r.Response()")
|
||||
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
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
//go:build linux && purego
|
||||
// +build linux,purego
|
||||
|
||||
package webview
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
)
|
||||
|
||||
const (
|
||||
gtk3 = "libgtk-3.so"
|
||||
gtk4 = "libgtk-4.so"
|
||||
)
|
||||
|
||||
var (
|
||||
gtk uintptr
|
||||
webkit uintptr
|
||||
version int
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
// gtk, err = purego.Dlopen(gtk4, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
||||
// if err == nil {
|
||||
// version = 4
|
||||
// return
|
||||
// }
|
||||
// log.Println("Failed to open GTK4: Falling back to GTK3")
|
||||
gtk, err = purego.Dlopen(gtk3, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
version = 3
|
||||
|
||||
var webkit4 string = "libwebkit2gtk-4.1.so"
|
||||
webkit, err = purego.Dlopen(webkit4, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
type responseWriter struct {
|
||||
req uintptr
|
||||
|
||||
header http.Header
|
||||
wroteHeader bool
|
||||
finished bool
|
||||
|
||||
w io.WriteCloser
|
||||
wErr error
|
||||
}
|
||||
|
||||
func (rw *responseWriter) Header() http.Header {
|
||||
if rw.header == nil {
|
||||
rw.header = http.Header{}
|
||||
}
|
||||
return rw.header
|
||||
}
|
||||
|
||||
func (rw *responseWriter) Write(buf []byte) (int, error) {
|
||||
if rw.finished {
|
||||
return 0, errResponseFinished
|
||||
}
|
||||
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
if rw.wErr != nil {
|
||||
return 0, rw.wErr
|
||||
}
|
||||
return rw.w.Write(buf)
|
||||
}
|
||||
|
||||
func (rw *responseWriter) WriteHeader(code int) {
|
||||
// TODO? Is this ever called? I don't think so!
|
||||
if rw.wroteHeader || rw.finished {
|
||||
return
|
||||
}
|
||||
rw.wroteHeader = true
|
||||
|
||||
contentLength := int64(-1)
|
||||
if sLen := rw.Header().Get(HeaderContentLength); sLen != "" {
|
||||
if pLen, _ := strconv.ParseInt(sLen, 10, 64); pLen > 0 {
|
||||
contentLength = pLen
|
||||
}
|
||||
}
|
||||
fmt.Println("content_length", contentLength)
|
||||
// We can't use os.Pipe here, because that returns files with a finalizer for closing the FD. But the control over the
|
||||
// read FD is given to the InputStream and will be closed there.
|
||||
// Furthermore we especially don't want to have the FD_CLOEXEC
|
||||
rFD, w, err := pipe()
|
||||
if err != nil {
|
||||
rw.finishWithError(http.StatusInternalServerError, fmt.Errorf("unable to open pipe: %s", err))
|
||||
return
|
||||
}
|
||||
rw.w = w
|
||||
|
||||
var newStream func(int, bool) uintptr
|
||||
purego.RegisterLibFunc(&newStream, gtk, "g_unix_input_stream_new")
|
||||
var unRef func(uintptr)
|
||||
purego.RegisterLibFunc(&unRef, gtk, "g_object_unref")
|
||||
stream := newStream(rFD, true)
|
||||
|
||||
/* var reqFinish func(uintptr, uintptr, uintptr, uintptr, int64) int
|
||||
purego.RegisterLibFunc(&reqFinish, webkit, "webkit_uri_scheme_request_finish")
|
||||
|
||||
header := rw.Header()
|
||||
defer unRef(stream)
|
||||
if err := reqFinish(rw.req, code, header, stream, contentLength); err != nil {
|
||||
rw.finishWithError(http.StatusInternalServerError, fmt.Errorf("unable to finish request: %s", err))
|
||||
}
|
||||
*/
|
||||
if err := webkit_uri_scheme_request_finish(rw.req, code, rw.Header(), stream, contentLength); err != nil {
|
||||
rw.finishWithError(http.StatusInternalServerError, fmt.Errorf("unable to finish request: %s", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *responseWriter) Finish() {
|
||||
if !rw.wroteHeader {
|
||||
rw.WriteHeader(http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if rw.finished {
|
||||
return
|
||||
}
|
||||
rw.finished = true
|
||||
if rw.w != nil {
|
||||
rw.w.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *responseWriter) finishWithError(code int, err error) {
|
||||
if rw.w != nil {
|
||||
rw.w.Close()
|
||||
rw.w = &nopCloser{io.Discard}
|
||||
}
|
||||
rw.wErr = err
|
||||
|
||||
var newLiteral func(uint32, string, int, string) uintptr // is this correct?
|
||||
purego.RegisterLibFunc(&newLiteral, gtk, "g_error_new_literal")
|
||||
var newQuark func(string) uintptr
|
||||
purego.RegisterLibFunc(&newQuark, gtk, "g_quark_from_string")
|
||||
var freeError func(uintptr)
|
||||
purego.RegisterLibFunc(&freeError, gtk, "g_error_free")
|
||||
var finishError func(uintptr, uintptr)
|
||||
purego.RegisterLibFunc(&finishError, webkit, "webkit_uri_scheme_request_finish_error")
|
||||
|
||||
msg := string(err.Error())
|
||||
//gquark := newQuark(msg)
|
||||
gerr := newLiteral(1, msg, code, msg)
|
||||
finishError(rw.req, gerr)
|
||||
freeError(gerr)
|
||||
}
|
||||
|
||||
type nopCloser struct {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
func (nopCloser) Close() error { return nil }
|
||||
|
||||
func pipe() (r int, w *os.File, err error) {
|
||||
var p [2]int
|
||||
e := syscall.Pipe2(p[0:], 0)
|
||||
if e != nil {
|
||||
return 0, nil, fmt.Errorf("pipe2: %s", e)
|
||||
}
|
||||
|
||||
return p[0], os.NewFile(uintptr(p[1]), "|1"), nil
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
//go:build linux && (webkit2_36 || webkit2_40) && purego
|
||||
|
||||
package webview
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
)
|
||||
|
||||
func webkit_uri_scheme_request_get_http_method(req uintptr) string {
|
||||
var getMethod func(uintptr) string
|
||||
purego.RegisterLibFunc(&getMethod, gtk, "webkit_uri_scheme_request_get_http_method")
|
||||
return strings.ToUpper(getMethod(req))
|
||||
}
|
||||
|
||||
func webkit_uri_scheme_request_get_http_headers(req uintptr) http.Header {
|
||||
var getHeaders func(uintptr) uintptr
|
||||
purego.RegisterLibFunc(&getUri, webkit, "webkit_uri_scheme_request_get_http_headers")
|
||||
|
||||
hdrs := getHeaders(req)
|
||||
|
||||
var headersIterInit func(uintptr, uintptr) uintptr
|
||||
purego.RegisterLibFunc(&headersIterInit, gtk, "soup_message_headers_iter_init")
|
||||
|
||||
// TODO: How do we get a struct?
|
||||
/*
|
||||
typedef struct {
|
||||
SoupMessageHeaders *hdrs;
|
||||
int index_common;
|
||||
int index_uncommon;
|
||||
} SoupMessageHeadersIterReal;
|
||||
*/
|
||||
iter := make([]byte, 12)
|
||||
headersIterInit(&iter, hdrs)
|
||||
|
||||
var iterNext func(uintptr, *string, *string) int
|
||||
purego.RegisterLibFunc(&iterNext, gtk, "soup_message_headers_iter_next")
|
||||
|
||||
var name string
|
||||
var value string
|
||||
h := http.Header{}
|
||||
|
||||
for iterNext(&iter, &name, &value) != 0 {
|
||||
h.Add(name, value)
|
||||
}
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func webkit_uri_scheme_request_finish(req uintptr, code int, header http.Header, stream uintptr, streamLength int64) error {
|
||||
|
||||
var newResponse func(uintptr, int64) string
|
||||
purego.RegisterLibFunc(&newResponse, webkit, "webkit_uri_scheme_response_new")
|
||||
var unRef func(uintptr)
|
||||
purego.RegisterLibFunc(&unRef, gtk, "g_object_unref")
|
||||
|
||||
resp := newResponse(stream, streamLength)
|
||||
defer unRef(resp)
|
||||
|
||||
var setStatus func(uintptr, int, string)
|
||||
purego.RegisterLibFunc(&unRef, webkit, "webkit_uri_scheme_response_set_status")
|
||||
|
||||
setStatus(resp, code, cReason)
|
||||
|
||||
var setContentType func(uintptr, string)
|
||||
purego.RegisterLibFunc(&unRef, webkit, "webkit_uri_scheme_response_set_content_type")
|
||||
|
||||
setContentType(resp, header.Get(HeaderContentType))
|
||||
|
||||
soup := gtk
|
||||
var soupHeadersNew func(int) uintptr
|
||||
purego.RegisterLibFunc(&unRef, soup, "soup_message_headers_new")
|
||||
var soupHeadersAppend func(uintptr, string, string)
|
||||
purego.RegisterLibFunc(&unRef, soup, "soup_message_headers_append")
|
||||
|
||||
hdrs := soupHeadersNew(SOUP_MESSAGE_HEADERS_RESPONSE)
|
||||
for name, values := range header {
|
||||
for _, value := range values {
|
||||
soupHeadersAppend(hdrs, name, value)
|
||||
}
|
||||
}
|
||||
|
||||
var setHttpHeaders func(uintptr, uintptr)
|
||||
purego.RegisterLibFunc(&unRef, webkit, "webkit_uri_scheme_response_set_http_headers")
|
||||
|
||||
setHttpHeaders(resp, hdrs)
|
||||
var finishWithResponse func(uintptr, uintptr)
|
||||
purego.RegisterLibFunc(&unRef, webkit, "webkit_uri_scheme_request_finish_with_response")
|
||||
finishWithResponse(req, resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -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,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
|
||||
}
|
||||
+57
-55
@@ -14,21 +14,21 @@ Status of features in v3. Incomplete - please add as you see fit.
|
||||
|
||||
Application interface methods
|
||||
|
||||
| Method | Windows | Linux | Mac | Notes |
|
||||
|---------------------------------------------------------------|---------|-------|-----|------------------------------|
|
||||
| run() error | Y | Y | Y | |
|
||||
| destroy() | | Y | Y | |
|
||||
| setApplicationMenu(menu *Menu) | Y | | Y | |
|
||||
| name() string | | | Y | |
|
||||
| getCurrentWindowID() uint | Y | Y | Y | |
|
||||
| showAboutDialog(name string, description string, icon []byte) | | Y | Y | [linux] No icon possible yet |
|
||||
| setIcon(icon []byte) | - | | Y | |
|
||||
| on(id uint) | | | Y | |
|
||||
| dispatchOnMainThread(fn func()) | Y | Y | Y | |
|
||||
| hide() | Y | | Y | |
|
||||
| show() | Y | | Y | |
|
||||
| getPrimaryScreen() (*Screen, error) | | Y | Y | |
|
||||
| getScreens() ([]*Screen, error) | | Y | Y | |
|
||||
| Method | Windows | Linux | Mac | Notes |
|
||||
|---------------------------------------------------------------|---------|-------|-----|-------|
|
||||
| run() error | Y | | Y | |
|
||||
| destroy() | | | Y | |
|
||||
| setApplicationMenu(menu *Menu) | Y | | Y | |
|
||||
| name() string | | | Y | |
|
||||
| getCurrentWindowID() uint | Y | | Y | |
|
||||
| showAboutDialog(name string, description string, icon []byte) | | | Y | |
|
||||
| setIcon(icon []byte) | - | | Y | |
|
||||
| on(id uint) | | | Y | |
|
||||
| dispatchOnMainThread(fn func()) | Y | | Y | |
|
||||
| hide() | Y | | Y | |
|
||||
| show() | Y | | Y | |
|
||||
| getPrimaryScreen() (*Screen, error) | | | Y | |
|
||||
| getScreens() ([]*Screen, error) | | | Y | |
|
||||
|
||||
## Webview Window
|
||||
|
||||
@@ -90,7 +90,7 @@ Webview Window Interface Methods
|
||||
|
||||
| Feature | Windows | Linux | Mac | Notes |
|
||||
|---------|---------|-------|-----|-------|
|
||||
| Quit | Y | Y | Y | |
|
||||
| Quit | Y | | Y | |
|
||||
| Hide | Y | | Y | |
|
||||
| Show | Y | | Y | |
|
||||
|
||||
@@ -132,9 +132,9 @@ explicitly set with `--default-contextmenu: show`.
|
||||
|
||||
| Feature | Windows | Linux | Mac | Notes |
|
||||
|------------|---------|-------|-----|-------|
|
||||
| GetAll | Y | Y | Y | |
|
||||
| GetPrimary | Y | Y | Y | |
|
||||
| GetCurrent | Y | Y | Y | |
|
||||
| GetAll | Y | | Y | |
|
||||
| GetPrimary | Y | | Y | |
|
||||
| GetCurrent | Y | | Y | |
|
||||
|
||||
### Window
|
||||
|
||||
@@ -180,37 +180,39 @@ U = Untested
|
||||
A 'Y' in the table below indicates that the option has been tested and is applied when the window is created.
|
||||
An 'X' indicates that the option is not supported by the platform.
|
||||
|
||||
| Feature | Windows | Linux | Mac | Notes |
|
||||
|---------------------------------|---------|-------|-----|---------------------------------------------------|
|
||||
| Name | | | | |
|
||||
| Title | Y | | | |
|
||||
| Width | Y | Y | | |
|
||||
| Height | Y | Y | | |
|
||||
| AlwaysOnTop | Y | Y | | |
|
||||
| URL | Y | | | |
|
||||
| DisableResize | Y | Y | | |
|
||||
| Frameless | Y | Y | | |
|
||||
| MinWidth | Y | Y | | |
|
||||
| MinHeight | Y | Y | | |
|
||||
| MaxWidth | Y | Y | | |
|
||||
| MaxHeight | Y | Y | | |
|
||||
| StartState | Y | | | |
|
||||
| Mac | - | - | | |
|
||||
| BackgroundType | | | | Acrylic seems to work but the others don't |
|
||||
| BackgroundColour | Y | Y | | |
|
||||
| HTML | Y | Y | | |
|
||||
| JS | Y | Y | | |
|
||||
| CSS | Y | Y | | |
|
||||
| X | Y | Y | | |
|
||||
| Y | Y | Y | | |
|
||||
| HideOnClose | Y | Y | | |
|
||||
| FullscreenButtonEnabled | | ? | | [linux] How is this different from DisableResize? |
|
||||
| Hidden | Y | | | |
|
||||
| EnableFraudulentWebsiteWarnings | | | | |
|
||||
| Zoom | | Y | | |
|
||||
| EnableDragAndDrop | Y | Y | | |
|
||||
| Windows | Y | - | - | |
|
||||
| Focused | Y | | | |
|
||||
| Feature | Windows | Linux | Mac | Notes |
|
||||
|---------------------------------|---------|-------|-----|--------------------------------------------|
|
||||
| AlwaysOnTop | Y | | | |
|
||||
| BackgroundColour | Y | | | |
|
||||
| BackgroundType | | | | Acrylic seems to work but the others don't |
|
||||
| CSS | Y | | | |
|
||||
| DevToolsEnabled | Y | | Y | |
|
||||
| DisableResize | Y | | | |
|
||||
| EnableDragAndDrop | | | | |
|
||||
| EnableFraudulentWebsiteWarnings | | | | |
|
||||
| Focused | Y | | | |
|
||||
| Frameless | Y | | | |
|
||||
| FullscreenButtonEnabled | Y | | | |
|
||||
| Height | Y | | | |
|
||||
| Hidden | Y | | | |
|
||||
| HTML | Y | | | |
|
||||
| JS | Y | | | |
|
||||
| Mac | - | - | | |
|
||||
| MaxHeight | Y | | | |
|
||||
| MaxWidth | Y | | | |
|
||||
| MinHeight | Y | | | |
|
||||
| MinWidth | Y | | | |
|
||||
| Name | Y | | | |
|
||||
| OpenInspectorOnStartup | | | | |
|
||||
| StartState | Y | | | |
|
||||
| Title | Y | | | |
|
||||
| URL | Y | | | |
|
||||
| Width | Y | | | |
|
||||
| Windows | Y | - | - | |
|
||||
| X | Y | | | |
|
||||
| Y | Y | | | |
|
||||
| Zoom | | | | |
|
||||
| ZoomControlEnabled | | | | |
|
||||
|
||||
### Log
|
||||
|
||||
@@ -220,7 +222,7 @@ To log or not to log? System logger vs custom logger.
|
||||
|
||||
| Event | Windows | Linux | Mac | Notes |
|
||||
|--------------------------|---------|-------|-----|-------|
|
||||
| Default Application Menu | Y | Y | Y | |
|
||||
| Default Application Menu | Y | | Y | |
|
||||
|
||||
## Tray Menus
|
||||
|
||||
@@ -293,10 +295,10 @@ Built-in plugin support:
|
||||
| Plugin | Windows | Linux | Mac | Notes |
|
||||
|-----------------|---------|-------|-----|-------|
|
||||
| Browser | Y | | Y | |
|
||||
| KV Store | Y | Y | Y | |
|
||||
| Log | Y | Y | Y | |
|
||||
| KV Store | Y | | Y | |
|
||||
| Log | Y | | Y | |
|
||||
| Single Instance | Y | | Y | |
|
||||
| SQLite | Y | Y | Y | |
|
||||
| SQLite | Y | | Y | |
|
||||
| Start at login | | | Y | |
|
||||
| Server | | | | |
|
||||
|
||||
@@ -381,4 +383,4 @@ Built-in plugin support:
|
||||
|
||||
# Beta Release TODO
|
||||
|
||||
- [ ] Make better looking examples
|
||||
- [ ] Make better looking examples
|
||||
|
||||
@@ -3,7 +3,6 @@ module github.com/wailsapp/wails/v3
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/ebitengine/purego v0.3.2
|
||||
github.com/bep/debounce v1.2.1
|
||||
github.com/go-ole/go-ole v1.2.6
|
||||
github.com/go-task/task/v3 v3.20.0
|
||||
@@ -76,5 +75,3 @@ require (
|
||||
)
|
||||
|
||||
replace github.com/wailsapp/wails/v2 => ../v2
|
||||
|
||||
replace github.com/ebitengine/purego v0.3.2 => github.com/TotallyGamerJet/purego v0.2.0-alpha.0.20230404174033-5655abccca7e
|
||||
|
||||
@@ -11,8 +11,6 @@ github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzX
|
||||
github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c=
|
||||
github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE=
|
||||
github.com/MarvinJWendt/testza v0.5.1 h1:a9Fqx6vQrHQ4CyiaLhktfTTelwGotmFWy8MNhyaohw8=
|
||||
github.com/TotallyGamerJet/purego v0.2.0-alpha.0.20230404174033-5655abccca7e h1:wQ7ot+e0mwJYkbomtIX9tU0dOV9lFTmwAgUGqvQTIUg=
|
||||
github.com/TotallyGamerJet/purego v0.2.0-alpha.0.20230404174033-5655abccca7e/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
||||
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
|
||||
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
||||
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
|
||||
|
||||
@@ -333,9 +333,7 @@ func (a *App) error(message string, args ...any) {
|
||||
func (a *App) NewWebviewWindowWithOptions(windowOptions WebviewWindowOptions) *WebviewWindow {
|
||||
newWindow := NewWindow(windowOptions)
|
||||
id := newWindow.id
|
||||
if a.windows == nil {
|
||||
a.windows = make(map[uint]*WebviewWindow)
|
||||
}
|
||||
|
||||
a.windowsLock.Lock()
|
||||
a.windows[id] = newWindow
|
||||
a.windowsLock.Unlock()
|
||||
|
||||
@@ -1,268 +0,0 @@
|
||||
//go:build linux && !purego
|
||||
|
||||
package application
|
||||
|
||||
/*
|
||||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <webkit2/webkit2.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct App {
|
||||
void *app;
|
||||
} App;
|
||||
|
||||
extern void processApplicationEvent(uint);
|
||||
|
||||
extern void activateLinux(gpointer data);
|
||||
|
||||
static void activate (GtkApplication* app, gpointer data) {
|
||||
// FIXME: should likely emit a WAILS specific code
|
||||
// events.Mac.EventApplicationDidFinishLaunching == 1032
|
||||
//processApplicationEvent(1032);
|
||||
|
||||
activateLinux(data);
|
||||
}
|
||||
|
||||
static GtkApplication* init(char* name) {
|
||||
return gtk_application_new(name, G_APPLICATION_DEFAULT_FLAGS);
|
||||
}
|
||||
|
||||
static int run(void *app, void *data) {
|
||||
g_signal_connect (app, "activate", G_CALLBACK (activate), data);
|
||||
g_application_hold(app); // allows it to run without a window
|
||||
int status = g_application_run (G_APPLICATION (app), 0, NULL);
|
||||
g_application_release(app);
|
||||
g_object_unref (app);
|
||||
return status;
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Set GDK_BACKEND=x11 if currently unset and XDG_SESSION_TYPE is unset, unspecified or x11 to prevent warnings
|
||||
_ = os.Setenv("GDK_BACKEND", "x11")
|
||||
}
|
||||
|
||||
type linuxApp struct {
|
||||
application unsafe.Pointer
|
||||
applicationMenu unsafe.Pointer
|
||||
parent *App
|
||||
|
||||
startupActions []func()
|
||||
|
||||
// Native -> uint
|
||||
windows map[*C.GtkWindow]uint
|
||||
windowsLock sync.Mutex
|
||||
}
|
||||
|
||||
func getNativeApplication() *linuxApp {
|
||||
return globalApplication.impl.(*linuxApp)
|
||||
}
|
||||
|
||||
func (m *linuxApp) hide() {
|
||||
windows := C.gtk_application_get_windows((*C.GtkApplication)(m.application))
|
||||
for {
|
||||
fmt.Println("hiding", windows.data)
|
||||
C.gtk_widget_hide((*C.GtkWidget)(windows.data))
|
||||
windows = windows.next
|
||||
if windows == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *linuxApp) show() {
|
||||
windows := C.gtk_application_get_windows((*C.GtkApplication)(m.application))
|
||||
for {
|
||||
fmt.Println("hiding", windows.data)
|
||||
C.gtk_widget_show_all((*C.GtkWidget)(windows.data))
|
||||
windows = windows.next
|
||||
if windows == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *linuxApp) on(eventID uint) {
|
||||
log.Println("linuxApp.on()", eventID)
|
||||
// TODO: Setup signal handling as appropriate
|
||||
// Note: GTK signals seem to be strings!
|
||||
}
|
||||
|
||||
func (m *linuxApp) setIcon(icon []byte) {
|
||||
/* // FIXME: WIP
|
||||
loader := C.gdk_pixbuf_loader_new()
|
||||
|
||||
if loader == nil {
|
||||
return
|
||||
}
|
||||
|
||||
loaded := C.gdk_pixbuf_loader_write(loader, (*C.guchar)(&icon[0]), (C.gsize)(len(icon)), 0)
|
||||
|
||||
if loaded == C.bool(1) && C.gdk_pixbuf_loader_close(loader, 0) {
|
||||
pixbuf := C.gdk_pixbuf_loader_get_pixbuf(loader)
|
||||
if pixbuf != nil {
|
||||
ww := m.parent.CurrentWindow()
|
||||
window := ww.impl.window
|
||||
C.gtk_window_set_icon(window, pixbuf)
|
||||
}
|
||||
}
|
||||
|
||||
C.g_object_unref(loader)
|
||||
*/
|
||||
}
|
||||
|
||||
func (m *linuxApp) name() string {
|
||||
// appName := C.getAppName()
|
||||
// defer C.free(unsafe.Pointer(appName))
|
||||
// return C.GoString(appName)
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *linuxApp) getCurrentWindowID() uint {
|
||||
// TODO: Add extra metadata to window
|
||||
window := (*C.GtkWindow)(C.gtk_application_get_active_window((*C.GtkApplication)(m.application)))
|
||||
if window == nil {
|
||||
return uint(1)
|
||||
}
|
||||
m.windowsLock.Lock()
|
||||
defer m.windowsLock.Unlock()
|
||||
identifier, ok := m.windows[window]
|
||||
if ok {
|
||||
return identifier
|
||||
}
|
||||
return uint(1)
|
||||
}
|
||||
|
||||
func (m *linuxApp) setApplicationMenu(menu *Menu) {
|
||||
if menu == nil {
|
||||
// Create a default menu
|
||||
menu = defaultApplicationMenu()
|
||||
}
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
fmt.Println("setApplicationMenu")
|
||||
|
||||
menu.Update()
|
||||
m.applicationMenu = (menu.impl).(*linuxMenu).native
|
||||
})
|
||||
}
|
||||
|
||||
func (m *linuxApp) run() error {
|
||||
|
||||
// Add a hook to the ApplicationDidFinishLaunching event
|
||||
// FIXME: add Wails specific events - i.e. Shouldn't platform specific ones be translated to Wails events?
|
||||
m.parent.On(events.Mac.ApplicationDidFinishLaunching, func() {
|
||||
// Do we need to do anything now?
|
||||
fmt.Println("events.Mac.ApplicationDidFinishLaunching received!")
|
||||
})
|
||||
|
||||
var app C.App
|
||||
app.app = unsafe.Pointer(m)
|
||||
C.run(m.application, m.application)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *linuxApp) destroy() {
|
||||
C.g_application_quit((*C.GApplication)(m.application))
|
||||
}
|
||||
|
||||
// register our window to our parent mapping
|
||||
func (m *linuxApp) registerWindow(window *C.GtkWindow, id uint) {
|
||||
m.windowsLock.Lock()
|
||||
m.windows[window] = id
|
||||
m.windowsLock.Unlock()
|
||||
}
|
||||
|
||||
func newPlatformApp(parent *App) *linuxApp {
|
||||
name := strings.ToLower(strings.Replace(parent.options.Name, " ", "", -1))
|
||||
if name == "" {
|
||||
name = "undefined"
|
||||
}
|
||||
nameC := C.CString(fmt.Sprintf("org.wails.%s", name))
|
||||
app := &linuxApp{
|
||||
parent: parent,
|
||||
application: unsafe.Pointer(C.init(nameC)),
|
||||
// name: fmt.Sprintf("org.wails.%s", name),
|
||||
windows: map[*C.GtkWindow]uint{},
|
||||
}
|
||||
C.free(unsafe.Pointer(nameC))
|
||||
return app
|
||||
}
|
||||
|
||||
// executeStartupActions is called by `activateLinux` below to execute
|
||||
// code which needs to be run after the 'activate' signal is received
|
||||
func (m *linuxApp) executeStartupActions() {
|
||||
for _, fn := range m.startupActions {
|
||||
fn()
|
||||
}
|
||||
}
|
||||
|
||||
//export activateLinux
|
||||
func activateLinux(data unsafe.Pointer) {
|
||||
getNativeApplication().executeStartupActions()
|
||||
}
|
||||
|
||||
//export processApplicationEvent
|
||||
func processApplicationEvent(eventID C.uint) {
|
||||
// TODO: add translation to Wails events
|
||||
// currently reusing Mac specific values
|
||||
applicationEvents <- uint(eventID)
|
||||
}
|
||||
|
||||
//export processWindowEvent
|
||||
func processWindowEvent(windowID C.uint, eventID C.uint) {
|
||||
windowEvents <- &WindowEvent{
|
||||
WindowID: uint(windowID),
|
||||
EventID: uint(eventID),
|
||||
}
|
||||
}
|
||||
|
||||
//export processMessage
|
||||
func processMessage(windowID C.uint, message *C.char) {
|
||||
windowMessageBuffer <- &windowMessage{
|
||||
windowId: uint(windowID),
|
||||
message: C.GoString(message),
|
||||
}
|
||||
}
|
||||
|
||||
//export processDragItems
|
||||
func processDragItems(windowID C.uint, arr **C.char, length C.int) {
|
||||
var filenames []string
|
||||
// Convert the C array to a Go slice
|
||||
goSlice := (*[1 << 30]*C.char)(unsafe.Pointer(arr))[:length:length]
|
||||
for _, str := range goSlice {
|
||||
filenames = append(filenames, C.GoString(str))
|
||||
}
|
||||
windowDragAndDropBuffer <- &dragAndDropMessage{
|
||||
windowId: uint(windowID),
|
||||
filenames: filenames,
|
||||
}
|
||||
}
|
||||
|
||||
//export processMenuItemClick
|
||||
func processMenuItemClick(menuID C.uint) {
|
||||
menuItemClicked <- uint(menuID)
|
||||
}
|
||||
|
||||
func setIcon(icon []byte) {
|
||||
if icon == nil {
|
||||
return
|
||||
}
|
||||
//C.setApplicationIcon(unsafe.Pointer(&icon[0]), C.int(len(icon)))
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
//go:build linux && purego
|
||||
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
"github.com/wailsapp/wails/v2/pkg/assetserver/webview"
|
||||
)
|
||||
|
||||
const (
|
||||
gtk3 = "libgtk-3.so"
|
||||
gtk4 = "libgtk-4.so"
|
||||
)
|
||||
|
||||
var (
|
||||
gtk uintptr
|
||||
version int
|
||||
webkit uintptr
|
||||
)
|
||||
|
||||
func init() {
|
||||
// needed for GTK4 to function
|
||||
_ = os.Setenv("GDK_BACKEND", "x11")
|
||||
var err error
|
||||
/*
|
||||
gtk, err = purego.Dlopen(gtk4, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
||||
if err == nil {
|
||||
version = 4
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Failed to open GTK4: Falling back to GTK3")
|
||||
*/
|
||||
gtk, err = purego.Dlopen(gtk3, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
version = 3
|
||||
|
||||
var webkit4 string = "libwebkit2gtk-4.1.so"
|
||||
webkit, err = purego.Dlopen(webkit4, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
type linuxApp struct {
|
||||
appName string
|
||||
application uintptr
|
||||
applicationMenu uintptr
|
||||
parent *App
|
||||
|
||||
// Native -> uint
|
||||
windows map[uintptr]uint
|
||||
windowsLock sync.Mutex
|
||||
}
|
||||
|
||||
func getNativeApplication() *linuxApp {
|
||||
return globalApplication.impl.(*linuxApp)
|
||||
}
|
||||
|
||||
func (m *linuxApp) hide() {
|
||||
// C.hide()
|
||||
}
|
||||
|
||||
func (m *linuxApp) show() {
|
||||
// C.show()
|
||||
}
|
||||
|
||||
func (m *linuxApp) on(eventID uint) {
|
||||
log.Println("linuxApp.on()", eventID)
|
||||
|
||||
// TODO: Setup signal handling as appropriate
|
||||
// Note: GTK signals seem to be strings!
|
||||
}
|
||||
|
||||
func (m *linuxApp) setIcon(icon []byte) {
|
||||
// C.setApplicationIcon(unsafe.Pointer(&icon[0]), C.int(len(icon)))
|
||||
}
|
||||
|
||||
func (m *linuxApp) name() string {
|
||||
return m.appName
|
||||
}
|
||||
|
||||
func (m *linuxApp) getCurrentWindowID() uint {
|
||||
var getCurrentWindow func(uintptr) uintptr
|
||||
purego.RegisterLibFunc(&getCurrentWindow, gtk, "gtk_application_get_active_window")
|
||||
window := getCurrentWindow(m.application)
|
||||
if window == 0 {
|
||||
return 1
|
||||
}
|
||||
m.windowsLock.Lock()
|
||||
defer m.windowsLock.Unlock()
|
||||
if identifier, ok := m.windows[window]; ok {
|
||||
return identifier
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
func (m *linuxApp) setApplicationMenu(menu *Menu) {
|
||||
if menu == nil {
|
||||
// Create a default menu
|
||||
menu = defaultApplicationMenu()
|
||||
}
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
menu.Update()
|
||||
m.applicationMenu = (menu.impl).(*linuxMenu).native
|
||||
})
|
||||
}
|
||||
|
||||
func (m *linuxApp) activate() {
|
||||
fmt.Println("linuxApp.activated!", m.application)
|
||||
var hold func(uintptr)
|
||||
purego.RegisterLibFunc(&hold, gtk, "g_application_hold")
|
||||
|
||||
hold(m.application)
|
||||
|
||||
// time.Sleep(50 * time.Millisecond)
|
||||
// m.parent.activate()
|
||||
}
|
||||
|
||||
func (m *linuxApp) run() error {
|
||||
// Add a hook to the ApplicationDidFinishLaunching event
|
||||
// FIXME: add Wails specific events - i.e. Shouldn't platform specific ones be translated to Wails events?
|
||||
/* m.parent.On(events.Mac.ApplicationDidFinishLaunching, func() {
|
||||
// Do we need to do anything now?
|
||||
fmt.Println("ApplicationDidFinishLaunching!")
|
||||
})
|
||||
*/
|
||||
m.parent.OnWindowCreation(func(window *WebviewWindow) {
|
||||
fmt.Println("OnWindowCreation: ", window)
|
||||
|
||||
})
|
||||
|
||||
var g_signal_connect func(uintptr, string, uintptr, uintptr, bool, int) int
|
||||
purego.RegisterLibFunc(&g_signal_connect, gtk, "g_signal_connect_data")
|
||||
g_signal_connect(m.application, "activate", purego.NewCallback(m.activate), m.application, false, 0)
|
||||
|
||||
var run func(uintptr, int, []string) int
|
||||
purego.RegisterLibFunc(&run, gtk, "g_application_run")
|
||||
|
||||
// FIXME: Convert status to 'error' if needed
|
||||
status := run(m.application, 0, []string{})
|
||||
fmt.Println("status", status)
|
||||
|
||||
var release func(uintptr)
|
||||
purego.RegisterLibFunc(&release, gtk, "g_application_release")
|
||||
release(m.application)
|
||||
|
||||
purego.RegisterLibFunc(&release, gtk, "g_object_unref")
|
||||
release(m.application)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *linuxApp) destroy() {
|
||||
var quit func(uintptr)
|
||||
purego.RegisterLibFunc(&quit, gtk, "g_application_quit")
|
||||
quit(m.application)
|
||||
}
|
||||
|
||||
func (m *linuxApp) registerWindow(address uintptr, window uint) {
|
||||
m.windowsLock.Lock()
|
||||
m.windows[address] = window
|
||||
m.windowsLock.Unlock()
|
||||
}
|
||||
|
||||
func newPlatformApp(parent *App) *linuxApp {
|
||||
name := strings.ToLower(parent.options.Name)
|
||||
if name == "" {
|
||||
name = "undefined"
|
||||
}
|
||||
identifier := fmt.Sprintf("org.wails.%s", strings.Replace(name, " ", "-", -1))
|
||||
|
||||
var gtkNew func(string, uint) uintptr
|
||||
purego.RegisterLibFunc(>kNew, gtk, "gtk_application_new")
|
||||
app := &linuxApp{
|
||||
appName: identifier,
|
||||
parent: parent,
|
||||
application: gtkNew(identifier, 0),
|
||||
windows: map[uintptr]uint{},
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func processApplicationEvent(eventID uint) {
|
||||
// TODO: add translation to Wails events
|
||||
// currently reusing Mac specific values
|
||||
applicationEvents <- eventID
|
||||
}
|
||||
|
||||
func processWindowEvent(windowID uint, eventID uint) {
|
||||
windowEvents <- &WindowEvent{
|
||||
WindowID: windowID,
|
||||
EventID: eventID,
|
||||
}
|
||||
}
|
||||
|
||||
func processMessage(windowID uint, message string) {
|
||||
windowMessageBuffer <- &windowMessage{
|
||||
windowId: windowID,
|
||||
message: message,
|
||||
}
|
||||
}
|
||||
|
||||
func processURLRequest(windowID uint, wkUrlSchemeTask uintptr) {
|
||||
fmt.Println("processURLRequest", windowID, wkUrlSchemeTask)
|
||||
webviewRequests <- &webViewAssetRequest{
|
||||
Request: webview.NewRequest(wkUrlSchemeTask),
|
||||
windowId: windowID,
|
||||
windowName: globalApplication.getWindowForID(windowID).Name(),
|
||||
}
|
||||
}
|
||||
|
||||
func processDragItems(windowID uint, arr []string, length int) {
|
||||
windowDragAndDropBuffer <- &dragAndDropMessage{
|
||||
windowId: windowID,
|
||||
filenames: arr,
|
||||
}
|
||||
}
|
||||
|
||||
func processMenuItemClick(menuID uint) {
|
||||
menuItemClicked <- menuID
|
||||
}
|
||||
|
||||
func setIcon(icon []byte) {
|
||||
if icon == nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("setIcon")
|
||||
/*
|
||||
GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
|
||||
if (!loader)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (gdk_pixbuf_loader_write(loader, buf, len, NULL) && gdk_pixbuf_loader_close(loader, NULL))
|
||||
{
|
||||
GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
|
||||
if (pixbuf)
|
||||
{
|
||||
gtk_window_set_icon(window, pixbuf);
|
||||
}
|
||||
}
|
||||
g_object_unref(loader);*/
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package application
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var clipboardLock sync.RWMutex
|
||||
|
||||
type linuxClipboard struct{}
|
||||
|
||||
func (m linuxClipboard) setText(text string) bool {
|
||||
clipboardLock.Lock()
|
||||
defer clipboardLock.Unlock()
|
||||
// cText := C.CString(text)
|
||||
// success := C.setClipboardText(cText)
|
||||
// C.free(unsafe.Pointer(cText))
|
||||
success := false
|
||||
return bool(success)
|
||||
}
|
||||
|
||||
func (m linuxClipboard) text() string {
|
||||
clipboardLock.RLock()
|
||||
defer clipboardLock.RUnlock()
|
||||
// clipboardText := C.getClipboardText()
|
||||
// result := C.GoString(clipboardText)
|
||||
return ""
|
||||
}
|
||||
|
||||
func newClipboardImpl() *linuxClipboard {
|
||||
return &linuxClipboard{}
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package application
|
||||
|
||||
/*
|
||||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static GtkWidget* new_about_dialog(GtkWindow *parent, const gchar *msg) {
|
||||
// gtk_message_dialog_new is variadic! Can't call from cgo
|
||||
GtkWidget *dialog;
|
||||
dialog = gtk_message_dialog_new(
|
||||
parent,
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_INFO,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
msg);
|
||||
|
||||
g_signal_connect_swapped (dialog,
|
||||
"response",
|
||||
G_CALLBACK (gtk_widget_destroy),
|
||||
dialog);
|
||||
return dialog;
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const AlertStyleWarning = C.int(0)
|
||||
const AlertStyleInformational = C.int(1)
|
||||
const AlertStyleCritical = C.int(2)
|
||||
|
||||
var alertTypeMap = map[DialogType]C.int{
|
||||
WarningDialog: AlertStyleWarning,
|
||||
InfoDialog: AlertStyleInformational,
|
||||
ErrorDialog: AlertStyleCritical,
|
||||
QuestionDialog: AlertStyleInformational,
|
||||
}
|
||||
|
||||
func setWindowIcon(window *C.GtkWindow, icon []byte) {
|
||||
fmt.Println("setWindowIcon", len(icon))
|
||||
loader := C.gdk_pixbuf_loader_new()
|
||||
if loader == nil {
|
||||
return
|
||||
}
|
||||
written := C.gdk_pixbuf_loader_write(
|
||||
loader,
|
||||
(*C.uchar)(&icon[0]),
|
||||
C.ulong(len(icon)),
|
||||
nil)
|
||||
if written == 0 {
|
||||
fmt.Println("failed to write icon")
|
||||
return
|
||||
}
|
||||
C.gdk_pixbuf_loader_close(loader, nil)
|
||||
pixbuf := C.gdk_pixbuf_loader_get_pixbuf(loader)
|
||||
if pixbuf != nil {
|
||||
fmt.Println("gtk_window_set_icon", window)
|
||||
C.gtk_window_set_icon((*C.GtkWindow)(window), pixbuf)
|
||||
}
|
||||
C.g_object_unref(C.gpointer(loader))
|
||||
}
|
||||
|
||||
func (m *linuxApp) showAboutDialog(title string, message string, icon []byte) {
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
parent := C.gtk_application_get_active_window((*C.GtkApplication)(m.application))
|
||||
cMsg := C.CString(message)
|
||||
cTitle := C.CString(title)
|
||||
defer C.free(unsafe.Pointer(cMsg))
|
||||
defer C.free(unsafe.Pointer(cTitle))
|
||||
dialog := C.new_about_dialog(parent, cMsg)
|
||||
C.gtk_window_set_title(
|
||||
(*C.GtkWindow)(unsafe.Pointer(dialog)),
|
||||
cTitle)
|
||||
// setWindowIcon((*C.GtkWindow)(dialog), icon)
|
||||
C.gtk_dialog_run((*C.GtkDialog)(unsafe.Pointer(dialog)))
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
type linuxDialog struct {
|
||||
dialog *MessageDialog
|
||||
|
||||
//nsDialog unsafe.Pointer
|
||||
}
|
||||
|
||||
func (m *linuxDialog) show() {
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
|
||||
// Mac can only have 4 Buttons on a dialog
|
||||
if len(m.dialog.Buttons) > 4 {
|
||||
m.dialog.Buttons = m.dialog.Buttons[:4]
|
||||
}
|
||||
|
||||
// if m.nsDialog != nil {
|
||||
// //C.releaseDialog(m.nsDialog)
|
||||
// }
|
||||
// var title *C.char
|
||||
// if m.dialog.Title != "" {
|
||||
// title = C.CString(m.dialog.Title)
|
||||
// }
|
||||
// var message *C.char
|
||||
// if m.dialog.Message != "" {
|
||||
// message = C.CString(m.dialog.Message)
|
||||
// }
|
||||
// var iconData unsafe.Pointer
|
||||
// var iconLength C.int
|
||||
// if m.dialog.Icon != nil {
|
||||
// iconData = unsafe.Pointer(&m.dialog.Icon[0])
|
||||
// iconLength = C.int(len(m.dialog.Icon))
|
||||
// } else {
|
||||
// // if it's an error, use the application Icon
|
||||
// if m.dialog.DialogType == ErrorDialog {
|
||||
// iconData = unsafe.Pointer(&globalApplication.options.Icon[0])
|
||||
// iconLength = C.int(len(globalApplication.options.Icon))
|
||||
// }
|
||||
// }
|
||||
|
||||
// alertType, ok := alertTypeMap[m.dialog.DialogType]
|
||||
// if !ok {
|
||||
// alertType = AlertStyleInformational
|
||||
// }
|
||||
|
||||
// m.nsDialog = C.createAlert(alertType, title, message, iconData, iconLength)
|
||||
|
||||
// Reverse the Buttons so that the default is on the right
|
||||
reversedButtons := make([]*Button, len(m.dialog.Buttons))
|
||||
var count = 0
|
||||
for i := len(m.dialog.Buttons) - 1; i >= 0; i-- {
|
||||
//button := m.dialog.Buttons[i]
|
||||
//C.alertAddButton(m.nsDialog, C.CString(button.Label), C.bool(button.IsDefault), C.bool(button.IsCancel))
|
||||
reversedButtons[count] = m.dialog.Buttons[i]
|
||||
count++
|
||||
}
|
||||
|
||||
buttonPressed := int(0) //C.dialogRunModal(m.nsDialog))
|
||||
if len(m.dialog.Buttons) > buttonPressed {
|
||||
button := reversedButtons[buttonPressed]
|
||||
if button.callback != nil {
|
||||
button.callback()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func newDialogImpl(d *MessageDialog) *linuxDialog {
|
||||
return &linuxDialog{
|
||||
dialog: d,
|
||||
}
|
||||
}
|
||||
|
||||
type linuxOpenFileDialog struct {
|
||||
dialog *OpenFileDialog
|
||||
}
|
||||
|
||||
func newOpenFileDialogImpl(d *OpenFileDialog) *linuxOpenFileDialog {
|
||||
return &linuxOpenFileDialog{
|
||||
dialog: d,
|
||||
}
|
||||
}
|
||||
|
||||
func toCString(s string) *C.char {
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
return C.CString(s)
|
||||
}
|
||||
|
||||
func (m *linuxOpenFileDialog) show() ([]string, error) {
|
||||
openFileResponses[m.dialog.id] = make(chan string)
|
||||
// nsWindow := unsafe.Pointer(nil)
|
||||
if m.dialog.window != nil {
|
||||
// get NSWindow from window
|
||||
//nsWindow = m.dialog.window.impl.(*macosWebviewWindow).nsWindow
|
||||
}
|
||||
|
||||
// Massage filter patterns into macOS format
|
||||
// We iterate all filter patterns, tidy them up and then join them with a semicolon
|
||||
// This should produce a single string of extensions like "png;jpg;gif"
|
||||
// var filterPatterns string
|
||||
// if len(m.dialog.filters) > 0 {
|
||||
// var allPatterns []string
|
||||
// for _, filter := range m.dialog.filters {
|
||||
// patternComponents := strings.Split(filter.Pattern, ";")
|
||||
// for i, component := range patternComponents {
|
||||
// filterPattern := strings.TrimSpace(component)
|
||||
// filterPattern = strings.TrimPrefix(filterPattern, "*.")
|
||||
// patternComponents[i] = filterPattern
|
||||
// }
|
||||
// allPatterns = append(allPatterns, strings.Join(patternComponents, ";"))
|
||||
// }
|
||||
// filterPatterns = strings.Join(allPatterns, ";")
|
||||
// }
|
||||
|
||||
// C.showOpenFileDialog(C.uint(m.dialog.id),
|
||||
// C.bool(m.dialog.canChooseFiles),
|
||||
// C.bool(m.dialog.canChooseDirectories),
|
||||
// C.bool(m.dialog.canCreateDirectories),
|
||||
// C.bool(m.dialog.showHiddenFiles),
|
||||
// C.bool(m.dialog.allowsMultipleSelection),
|
||||
// C.bool(m.dialog.resolvesAliases),
|
||||
// C.bool(m.dialog.hideExtension),
|
||||
// C.bool(m.dialog.treatsFilePackagesAsDirectories),
|
||||
// C.bool(m.dialog.allowsOtherFileTypes),
|
||||
// toCString(filterPatterns),
|
||||
// C.uint(len(filterPatterns)),
|
||||
// toCString(m.dialog.message),
|
||||
// toCString(m.dialog.directory),
|
||||
// toCString(m.dialog.buttonText),
|
||||
// nsWindow)
|
||||
var result []string
|
||||
for filename := range openFileResponses[m.dialog.id] {
|
||||
result = append(result, filename)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
//export openFileDialogCallback
|
||||
func openFileDialogCallback(cid C.uint, cpath *C.char) {
|
||||
path := C.GoString(cpath)
|
||||
id := uint(cid)
|
||||
channel, ok := openFileResponses[id]
|
||||
if ok {
|
||||
channel <- path
|
||||
} else {
|
||||
panic("No channel found for open file dialog")
|
||||
}
|
||||
}
|
||||
|
||||
//export openFileDialogCallbackEnd
|
||||
func openFileDialogCallbackEnd(cid C.uint) {
|
||||
id := uint(cid)
|
||||
channel, ok := openFileResponses[id]
|
||||
if ok {
|
||||
close(channel)
|
||||
delete(openFileResponses, id)
|
||||
freeDialogID(id)
|
||||
} else {
|
||||
panic("No channel found for open file dialog")
|
||||
}
|
||||
}
|
||||
|
||||
type linuxSaveFileDialog struct {
|
||||
dialog *SaveFileDialog
|
||||
}
|
||||
|
||||
func newSaveFileDialogImpl(d *SaveFileDialog) *linuxSaveFileDialog {
|
||||
return &linuxSaveFileDialog{
|
||||
dialog: d,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *linuxSaveFileDialog) show() (string, error) {
|
||||
saveFileResponses[m.dialog.id] = make(chan string)
|
||||
// nsWindow := unsafe.Pointer(nil)
|
||||
if m.dialog.window != nil {
|
||||
// get NSWindow from window
|
||||
// nsWindow = m.dialog.window.impl.(*linuxWebviewWindow).nsWindow
|
||||
}
|
||||
|
||||
// C.showSaveFileDialog(C.uint(m.dialog.id),
|
||||
// C.bool(m.dialog.canCreateDirectories),
|
||||
// C.bool(m.dialog.showHiddenFiles),
|
||||
// C.bool(m.dialog.canSelectHiddenExtension),
|
||||
// C.bool(m.dialog.hideExtension),
|
||||
// C.bool(m.dialog.treatsFilePackagesAsDirectories),
|
||||
// C.bool(m.dialog.allowOtherFileTypes),
|
||||
// toCString(m.dialog.message),
|
||||
// toCString(m.dialog.directory),
|
||||
// toCString(m.dialog.buttonText),
|
||||
// toCString(m.dialog.filename),
|
||||
// nsWindow)
|
||||
return <-saveFileResponses[m.dialog.id], nil
|
||||
}
|
||||
|
||||
//export saveFileDialogCallback
|
||||
func saveFileDialogCallback(cid C.uint, cpath *C.char) {
|
||||
// Covert the path to a string
|
||||
path := C.GoString(cpath)
|
||||
id := uint(cid)
|
||||
// put response on channel
|
||||
channel, ok := saveFileResponses[id]
|
||||
if ok {
|
||||
channel <- path
|
||||
close(channel)
|
||||
delete(saveFileResponses, id)
|
||||
freeDialogID(id)
|
||||
|
||||
} else {
|
||||
panic("No channel found for save file dialog")
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
//go:build linux && purego
|
||||
|
||||
package application
|
||||
|
||||
const AlertStyleWarning = 0
|
||||
const AlertStyleInformational = 1
|
||||
const AlertStyleCritical = 2
|
||||
|
||||
var alertTypeMap = map[DialogType]int{
|
||||
WarningDialog: AlertStyleWarning,
|
||||
InfoDialog: AlertStyleInformational,
|
||||
ErrorDialog: AlertStyleCritical,
|
||||
QuestionDialog: AlertStyleInformational,
|
||||
}
|
||||
|
||||
func (m *linuxApp) showAboutDialog(title string, message string, icon []byte) {
|
||||
// var iconData unsafe.Pointer
|
||||
// if icon != nil {
|
||||
// iconData = unsafe.Pointer(&icon[0])
|
||||
// }
|
||||
//C.showAboutBox(C.CString(title), C.CString(message), iconData, C.int(len(icon)))
|
||||
}
|
||||
|
||||
type linuxDialog struct {
|
||||
dialog *MessageDialog
|
||||
|
||||
//nsDialog unsafe.Pointer
|
||||
}
|
||||
|
||||
func (m *linuxDialog) show() {
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
|
||||
// Mac can only have 4 Buttons on a dialog
|
||||
if len(m.dialog.Buttons) > 4 {
|
||||
m.dialog.Buttons = m.dialog.Buttons[:4]
|
||||
}
|
||||
|
||||
// if m.nsDialog != nil {
|
||||
// //C.releaseDialog(m.nsDialog)
|
||||
// }
|
||||
// var title *C.char
|
||||
// if m.dialog.Title != "" {
|
||||
// title = C.CString(m.dialog.Title)
|
||||
// }
|
||||
// var message *C.char
|
||||
// if m.dialog.Message != "" {
|
||||
// message = C.CString(m.dialog.Message)
|
||||
// }
|
||||
// var iconData unsafe.Pointer
|
||||
// var iconLength C.int
|
||||
// if m.dialog.Icon != nil {
|
||||
// iconData = unsafe.Pointer(&m.dialog.Icon[0])
|
||||
// iconLength = C.int(len(m.dialog.Icon))
|
||||
// } else {
|
||||
// // if it's an error, use the application Icon
|
||||
// if m.dialog.DialogType == ErrorDialog {
|
||||
// iconData = unsafe.Pointer(&globalApplication.options.Icon[0])
|
||||
// iconLength = C.int(len(globalApplication.options.Icon))
|
||||
// }
|
||||
// }
|
||||
|
||||
// alertType, ok := alertTypeMap[m.dialog.DialogType]
|
||||
// if !ok {
|
||||
// alertType = AlertStyleInformational
|
||||
// }
|
||||
|
||||
// m.nsDialog = C.createAlert(alertType, title, message, iconData, iconLength)
|
||||
|
||||
// Reverse the Buttons so that the default is on the right
|
||||
reversedButtons := make([]*Button, len(m.dialog.Buttons))
|
||||
var count = 0
|
||||
for i := len(m.dialog.Buttons) - 1; i >= 0; i-- {
|
||||
//button := m.dialog.Buttons[i]
|
||||
//C.alertAddButton(m.nsDialog, C.CString(button.Label), C.bool(button.IsDefault), C.bool(button.IsCancel))
|
||||
reversedButtons[count] = m.dialog.Buttons[i]
|
||||
count++
|
||||
}
|
||||
|
||||
buttonPressed := int(0) //C.dialogRunModal(m.nsDialog))
|
||||
if len(m.dialog.Buttons) > buttonPressed {
|
||||
button := reversedButtons[buttonPressed]
|
||||
if button.callback != nil {
|
||||
button.callback()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func newDialogImpl(d *MessageDialog) *linuxDialog {
|
||||
return &linuxDialog{
|
||||
dialog: d,
|
||||
}
|
||||
}
|
||||
|
||||
type linuxOpenFileDialog struct {
|
||||
dialog *OpenFileDialog
|
||||
}
|
||||
|
||||
func newOpenFileDialogImpl(d *OpenFileDialog) *linuxOpenFileDialog {
|
||||
return &linuxOpenFileDialog{
|
||||
dialog: d,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *linuxOpenFileDialog) show() ([]string, error) {
|
||||
openFileResponses[m.dialog.id] = make(chan string)
|
||||
// nsWindow := unsafe.Pointer(nil)
|
||||
if m.dialog.window != nil {
|
||||
// get NSWindow from window
|
||||
//nsWindow = m.dialog.window.impl.(*macosWebviewWindow).nsWindow
|
||||
}
|
||||
|
||||
// Massage filter patterns into macOS format
|
||||
// We iterate all filter patterns, tidy them up and then join them with a semicolon
|
||||
// This should produce a single string of extensions like "png;jpg;gif"
|
||||
// var filterPatterns string
|
||||
// if len(m.dialog.filters) > 0 {
|
||||
// var allPatterns []string
|
||||
// for _, filter := range m.dialog.filters {
|
||||
// patternComponents := strings.Split(filter.Pattern, ";")
|
||||
// for i, component := range patternComponents {
|
||||
// filterPattern := strings.TrimSpace(component)
|
||||
// filterPattern = strings.TrimPrefix(filterPattern, "*.")
|
||||
// patternComponents[i] = filterPattern
|
||||
// }
|
||||
// allPatterns = append(allPatterns, strings.Join(patternComponents, ";"))
|
||||
// }
|
||||
// filterPatterns = strings.Join(allPatterns, ";")
|
||||
// }
|
||||
|
||||
// C.showOpenFileDialog(C.uint(m.dialog.id),
|
||||
// C.bool(m.dialog.canChooseFiles),
|
||||
// C.bool(m.dialog.canChooseDirectories),
|
||||
// C.bool(m.dialog.canCreateDirectories),
|
||||
// C.bool(m.dialog.showHiddenFiles),
|
||||
// C.bool(m.dialog.allowsMultipleSelection),
|
||||
// C.bool(m.dialog.resolvesAliases),
|
||||
// C.bool(m.dialog.hideExtension),
|
||||
// C.bool(m.dialog.treatsFilePackagesAsDirectories),
|
||||
// C.bool(m.dialog.allowsOtherFileTypes),
|
||||
// toCString(filterPatterns),
|
||||
// C.uint(len(filterPatterns)),
|
||||
// toCString(m.dialog.message),
|
||||
// toCString(m.dialog.directory),
|
||||
// toCString(m.dialog.buttonText),
|
||||
// nsWindow)
|
||||
var result []string
|
||||
for filename := range openFileResponses[m.dialog.id] {
|
||||
result = append(result, filename)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func openFileDialogCallback(id uint, path string) {
|
||||
channel, ok := openFileResponses[id]
|
||||
if ok {
|
||||
channel <- path
|
||||
} else {
|
||||
panic("No channel found for open file dialog")
|
||||
}
|
||||
}
|
||||
|
||||
func openFileDialogCallbackEnd(id uint) {
|
||||
channel, ok := openFileResponses[id]
|
||||
if ok {
|
||||
close(channel)
|
||||
delete(openFileResponses, id)
|
||||
freeDialogID(id)
|
||||
} else {
|
||||
panic("No channel found for open file dialog")
|
||||
}
|
||||
}
|
||||
|
||||
type linuxSaveFileDialog struct {
|
||||
dialog *SaveFileDialog
|
||||
}
|
||||
|
||||
func newSaveFileDialogImpl(d *SaveFileDialog) *linuxSaveFileDialog {
|
||||
return &linuxSaveFileDialog{
|
||||
dialog: d,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *linuxSaveFileDialog) show() (string, error) {
|
||||
saveFileResponses[m.dialog.id] = make(chan string)
|
||||
// nsWindow := unsafe.Pointer(nil)
|
||||
if m.dialog.window != nil {
|
||||
// get NSWindow from window
|
||||
// nsWindow = m.dialog.window.impl.(*linuxWebviewWindow).nsWindow
|
||||
}
|
||||
|
||||
// C.showSaveFileDialog(C.uint(m.dialog.id),
|
||||
// C.bool(m.dialog.canCreateDirectories),
|
||||
// C.bool(m.dialog.showHiddenFiles),
|
||||
// C.bool(m.dialog.canSelectHiddenExtension),
|
||||
// C.bool(m.dialog.hideExtension),
|
||||
// C.bool(m.dialog.treatsFilePackagesAsDirectories),
|
||||
// C.bool(m.dialog.allowOtherFileTypes),
|
||||
// toCString(m.dialog.message),
|
||||
// toCString(m.dialog.directory),
|
||||
// toCString(m.dialog.buttonText),
|
||||
// toCString(m.dialog.filename),
|
||||
// nsWindow)
|
||||
return <-saveFileResponses[m.dialog.id], nil
|
||||
}
|
||||
|
||||
func saveFileDialogCallback(cid uint, path string) {
|
||||
// put response on channel
|
||||
channel, ok := saveFileResponses[cid]
|
||||
if ok {
|
||||
channel <- path
|
||||
close(channel)
|
||||
delete(saveFileResponses, cid)
|
||||
freeDialogID(cid)
|
||||
|
||||
} else {
|
||||
panic("No channel found for save file dialog")
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package application
|
||||
|
||||
/*
|
||||
#cgo linux pkg-config: gtk+-3.0
|
||||
|
||||
#include <stdio.h>
|
||||
#include "gtk/gtk.h"
|
||||
|
||||
typedef struct CallbackID
|
||||
{
|
||||
unsigned int value;
|
||||
} CallbackID;
|
||||
|
||||
extern void dispatchOnMainThreadCallback(unsigned int);
|
||||
|
||||
static gboolean dispatchCallback(gpointer data) {
|
||||
struct CallbackID *args = data;
|
||||
unsigned int cid = args->value;
|
||||
dispatchOnMainThreadCallback(cid);
|
||||
free(args);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
};
|
||||
|
||||
static void dispatchOnMainThread(unsigned int id) {
|
||||
CallbackID *args = malloc(sizeof(CallbackID));
|
||||
args->value = id;
|
||||
g_idle_add((GSourceFunc)dispatchCallback, (gpointer)args);
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func (m *linuxApp) dispatchOnMainThread(id uint) {
|
||||
C.dispatchOnMainThread(C.uint(id))
|
||||
}
|
||||
|
||||
//export dispatchOnMainThreadCallback
|
||||
func dispatchOnMainThreadCallback(callbackID C.uint) {
|
||||
mainThreadFunctionStoreLock.RLock()
|
||||
id := uint(callbackID)
|
||||
fn := mainThreadFunctionStore[id]
|
||||
if fn == nil {
|
||||
Fatal("dispatchCallback called with invalid id: %v", id)
|
||||
}
|
||||
delete(mainThreadFunctionStore, id)
|
||||
mainThreadFunctionStoreLock.RUnlock()
|
||||
fn()
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
//go:build linux && purego
|
||||
|
||||
package application
|
||||
|
||||
import "github.com/ebitengine/purego"
|
||||
|
||||
const (
|
||||
G_SOURCE_REMOVE = 0
|
||||
)
|
||||
|
||||
func (m *linuxApp) dispatchOnMainThread(id uint) {
|
||||
var dispatch func(uintptr)
|
||||
purego.RegisterLibFunc(&dispatch, gtk, "g_idle_add")
|
||||
dispatch(purego.NewCallback(func(uintptr) int {
|
||||
dispatchOnMainThreadCallback(id)
|
||||
return G_SOURCE_REMOVE
|
||||
}))
|
||||
}
|
||||
|
||||
func dispatchOnMainThreadCallback(callbackID uint) {
|
||||
mainThreadFunctionStoreLock.RLock()
|
||||
id := uint(callbackID)
|
||||
fn := mainThreadFunctionStore[id]
|
||||
if fn == nil {
|
||||
Fatal("dispatchCallback called with invalid id: %v", id)
|
||||
}
|
||||
delete(mainThreadFunctionStore, id)
|
||||
mainThreadFunctionStoreLock.RUnlock()
|
||||
fn()
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package application
|
||||
|
||||
/*
|
||||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
void handleClick(void*);
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
gtkSignalHandlers map[*C.GtkWidget]C.gulong
|
||||
gtkSignalToMenuItem map[*C.GtkWidget]*MenuItem
|
||||
)
|
||||
|
||||
func init() {
|
||||
gtkSignalHandlers = map[*C.GtkWidget]C.gulong{}
|
||||
gtkSignalToMenuItem = map[*C.GtkWidget]*MenuItem{}
|
||||
}
|
||||
|
||||
//export handleClick
|
||||
func handleClick(idPtr unsafe.Pointer) {
|
||||
id := (*C.GtkWidget)(idPtr)
|
||||
item, ok := gtkSignalToMenuItem[id]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
//impl := (item.impl).(*linuxMenuItem)
|
||||
|
||||
switch item.itemType {
|
||||
case text, checkbox:
|
||||
processMenuItemClick(C.uint(item.id))
|
||||
case radio:
|
||||
menuItem := (item.impl).(*linuxMenuItem)
|
||||
if menuItem.isChecked() {
|
||||
processMenuItemClick(C.uint(item.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type linuxMenu struct {
|
||||
menu *Menu
|
||||
native unsafe.Pointer
|
||||
}
|
||||
|
||||
func newMenuImpl(menu *Menu) *linuxMenu {
|
||||
result := &linuxMenu{
|
||||
menu: menu,
|
||||
native: unsafe.Pointer(C.gtk_menu_bar_new()),
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (m *linuxMenu) update() {
|
||||
// fmt.Println("linuxMenu.update()")
|
||||
// if m.native != nil {
|
||||
// C.gtk_widget_destroy((*C.GtkWidget)(m.native))
|
||||
// m.native = unsafe.Pointer(C.gtk_menu_new())
|
||||
// }
|
||||
m.processMenu(m.menu)
|
||||
}
|
||||
|
||||
func (m *linuxMenu) processMenu(menu *Menu) {
|
||||
if menu.impl == nil {
|
||||
menu.impl = &linuxMenu{
|
||||
menu: menu,
|
||||
native: unsafe.Pointer(C.gtk_menu_new()),
|
||||
}
|
||||
}
|
||||
var currentRadioGroup *C.GSList
|
||||
|
||||
for _, item := range menu.items {
|
||||
// drop the group if we have run out of radio items
|
||||
if item.itemType != radio {
|
||||
currentRadioGroup = nil
|
||||
}
|
||||
|
||||
switch item.itemType {
|
||||
case submenu:
|
||||
menuItem := newMenuItemImpl(item)
|
||||
item.impl = menuItem
|
||||
m.processMenu(item.submenu)
|
||||
m.addSubMenuToItem(item.submenu, item)
|
||||
m.addMenuItem(menu, item)
|
||||
case text, checkbox:
|
||||
menuItem := newMenuItemImpl(item)
|
||||
item.impl = menuItem
|
||||
m.addMenuItem(menu, item)
|
||||
case radio:
|
||||
menuItem := newRadioItemImpl(item, currentRadioGroup)
|
||||
item.impl = menuItem
|
||||
m.addMenuItem(menu, item)
|
||||
currentRadioGroup = C.gtk_radio_menu_item_get_group((*C.GtkRadioMenuItem)(menuItem.native))
|
||||
case separator:
|
||||
m.addMenuSeparator(menu)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, item := range menu.items {
|
||||
if item.callback != nil {
|
||||
m.attachHandler(item)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (m *linuxMenu) attachHandler(item *MenuItem) {
|
||||
signal := C.CString("activate")
|
||||
defer C.free(unsafe.Pointer(signal))
|
||||
|
||||
impl := (item.impl).(*linuxMenuItem)
|
||||
widget := impl.native
|
||||
flags := C.GConnectFlags(0)
|
||||
handlerId := C.g_signal_connect_object(
|
||||
C.gpointer(widget),
|
||||
signal,
|
||||
C.GCallback(C.handleClick),
|
||||
C.gpointer(widget),
|
||||
flags)
|
||||
|
||||
id := (*C.GtkWidget)(widget)
|
||||
gtkSignalToMenuItem[id] = item
|
||||
gtkSignalHandlers[id] = handlerId
|
||||
impl.handlerId = handlerId
|
||||
}
|
||||
|
||||
func (m *linuxMenu) addSubMenuToItem(menu *Menu, item *MenuItem) {
|
||||
if menu.impl == nil {
|
||||
menu.impl = &linuxMenu{
|
||||
menu: menu,
|
||||
native: unsafe.Pointer(C.gtk_menu_new()),
|
||||
}
|
||||
}
|
||||
|
||||
C.gtk_menu_item_set_submenu(
|
||||
(*C.GtkMenuItem)((item.impl).(*linuxMenuItem).native),
|
||||
(*C.GtkWidget)((menu.impl).(*linuxMenu).native))
|
||||
|
||||
if item.role == ServicesMenu {
|
||||
// FIXME: what does this mean?
|
||||
}
|
||||
}
|
||||
|
||||
func (m *linuxMenu) addMenuItem(parent *Menu, menu *MenuItem) {
|
||||
// fmt.Println("addMenuIteam", fmt.Sprintf("%+v", parent), fmt.Sprintf("%+v", menu))
|
||||
C.gtk_menu_shell_append(
|
||||
(*C.GtkMenuShell)((parent.impl).(*linuxMenu).native),
|
||||
(*C.GtkWidget)((menu.impl).(*linuxMenuItem).native),
|
||||
)
|
||||
/*
|
||||
C.gtk_menu_item_set_submenu(
|
||||
(*C.struct__GtkMenuItem)((menu.impl).(*linuxMenuItem).native),
|
||||
(*C.struct__GtkWidget)((parent.impl).(*linuxMenu).native),
|
||||
)
|
||||
*/
|
||||
}
|
||||
|
||||
func (m *linuxMenu) addMenuSeparator(menu *Menu) {
|
||||
// fmt.Println("addMenuSeparator", fmt.Sprintf("%+v", menu))
|
||||
sep := C.gtk_separator_menu_item_new()
|
||||
native := (menu.impl).(*linuxMenu).native
|
||||
C.gtk_menu_shell_append((*C.GtkMenuShell)(native), sep)
|
||||
}
|
||||
|
||||
func (m *linuxMenu) addServicesMenu(menu *Menu) {
|
||||
fmt.Println("addServicesMenu - not implemented")
|
||||
//C.addServicesMenu(unsafe.Pointer(menu.impl.(*linuxMenu).nsMenu))
|
||||
}
|
||||
|
||||
func (l *linuxMenu) createMenu(name string, items []*MenuItem) *Menu {
|
||||
impl := newMenuImpl(&Menu{label: name})
|
||||
menu := &Menu{
|
||||
label: name,
|
||||
items: items,
|
||||
impl: impl,
|
||||
}
|
||||
impl.menu = menu
|
||||
return menu
|
||||
}
|
||||
|
||||
func defaultApplicationMenu() *Menu {
|
||||
menu := NewMenu()
|
||||
menu.AddRole(AppMenu)
|
||||
menu.AddRole(FileMenu)
|
||||
menu.AddRole(EditMenu)
|
||||
menu.AddRole(ViewMenu)
|
||||
menu.AddRole(WindowMenu)
|
||||
menu.AddRole(HelpMenu)
|
||||
return menu
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
//go:build linux && purego
|
||||
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
)
|
||||
|
||||
type linuxMenu struct {
|
||||
menu *Menu
|
||||
native uintptr
|
||||
}
|
||||
|
||||
func newMenuImpl(menu *Menu) *linuxMenu {
|
||||
var newMenuBar func() uintptr
|
||||
purego.RegisterLibFunc(&newMenuBar, gtk, "gtk_menu_bar_new")
|
||||
result := &linuxMenu{
|
||||
menu: menu,
|
||||
native: newMenuBar(),
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (m *linuxMenu) update() {
|
||||
m.processMenu(m.menu)
|
||||
}
|
||||
|
||||
func (m *linuxMenu) processMenu(menu *Menu) {
|
||||
var newMenu func() uintptr
|
||||
purego.RegisterLibFunc(&newMenu, gtk, "gtk_menu_new")
|
||||
if menu.impl == nil {
|
||||
menu.impl = &linuxMenu{
|
||||
menu: menu,
|
||||
native: newMenu(),
|
||||
}
|
||||
}
|
||||
var currentRadioGroup uintptr
|
||||
|
||||
for _, item := range menu.items {
|
||||
// drop the group if we have run out of radio items
|
||||
if item.itemType != radio {
|
||||
currentRadioGroup = 0
|
||||
}
|
||||
|
||||
switch item.itemType {
|
||||
case submenu:
|
||||
menuItem := newMenuItemImpl(item)
|
||||
item.impl = menuItem
|
||||
m.processMenu(item.submenu)
|
||||
m.addSubMenuToItem(item.submenu, item)
|
||||
m.addMenuItem(menu, item)
|
||||
case text, checkbox:
|
||||
menuItem := newMenuItemImpl(item)
|
||||
item.impl = menuItem
|
||||
m.addMenuItem(menu, item)
|
||||
case radio:
|
||||
menuItem := newRadioItemImpl(item, currentRadioGroup)
|
||||
item.impl = menuItem
|
||||
m.addMenuItem(menu, item)
|
||||
|
||||
var radioGetGroup func(uintptr) uintptr
|
||||
purego.RegisterLibFunc(&radioGetGroup, gtk, "gtk_radio_menu_item_get_group")
|
||||
|
||||
currentRadioGroup = radioGetGroup(menuItem.native)
|
||||
case separator:
|
||||
m.addMenuSeparator(menu)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, item := range menu.items {
|
||||
if item.callback != nil {
|
||||
m.attachHandler(item)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (m *linuxMenu) attachHandler(item *MenuItem) {
|
||||
impl := (item.impl).(*linuxMenuItem)
|
||||
widget := impl.native
|
||||
flags := 0
|
||||
|
||||
var handleClick = func() {
|
||||
item := item
|
||||
switch item.itemType {
|
||||
case text, checkbox:
|
||||
processMenuItemClick(item.id)
|
||||
case radio:
|
||||
menuItem := (item.impl).(*linuxMenuItem)
|
||||
if menuItem.isChecked() {
|
||||
processMenuItemClick(item.id)
|
||||
}
|
||||
default:
|
||||
fmt.Println("handleClick", item.itemType, item.id)
|
||||
}
|
||||
}
|
||||
|
||||
var signalConnectObject func(uintptr, string, uintptr, uintptr, int) uint
|
||||
purego.RegisterLibFunc(&signalConnectObject, gtk, "g_signal_connect_object")
|
||||
handlerId := signalConnectObject(
|
||||
widget,
|
||||
"activate",
|
||||
purego.NewCallback(handleClick),
|
||||
widget,
|
||||
flags)
|
||||
|
||||
impl.handlerId = handlerId
|
||||
}
|
||||
|
||||
func (m *linuxMenu) addSubMenuToItem(menu *Menu, item *MenuItem) {
|
||||
var newMenu func() uintptr
|
||||
purego.RegisterLibFunc(&newMenu, gtk, "gtk_menu_new")
|
||||
if menu.impl == nil {
|
||||
menu.impl = &linuxMenu{
|
||||
menu: menu,
|
||||
native: newMenu(),
|
||||
N }
|
||||
}
|
||||
var itemSetSubmenu func(uintptr, uintptr)
|
||||
purego.RegisterLibFunc(&itemSetSubmenu, gtk, "gtk_menu_item_set_submenu")
|
||||
|
||||
itemSetSubmenu(
|
||||
(item.impl).(*linuxMenuItem).native,
|
||||
(menu.impl).(*linuxMenu).native)
|
||||
|
||||
if item.role == ServicesMenu {
|
||||
// FIXME: what does this mean?
|
||||
}
|
||||
}
|
||||
|
||||
func (m *linuxMenu) addMenuItem(parent *Menu, menu *MenuItem) {
|
||||
var shellAppend func(uintptr, uintptr)
|
||||
purego.RegisterLibFunc(&shellAppend, gtk, "gtk_menu_shell_append")
|
||||
shellAppend(
|
||||
(parent.impl).(*linuxMenu).native,
|
||||
(menu.impl).(*linuxMenuItem).native,
|
||||
)
|
||||
}
|
||||
|
||||
func (m *linuxMenu) addMenuSeparator(menu *Menu) {
|
||||
var newSeparator func() uintptr
|
||||
purego.RegisterLibFunc(&newSeparator, gtk, "gtk_separator_menu_item_new")
|
||||
var shellAppend func(uintptr, uintptr)
|
||||
purego.RegisterLibFunc(&shellAppend, gtk, "gtk_menu_shell_append")
|
||||
|
||||
sep := newSeparator()
|
||||
native := (menu.impl).(*linuxMenu).native
|
||||
shellAppend(native, sep)
|
||||
}
|
||||
|
||||
func (m *linuxMenu) addServicesMenu(menu *Menu) {
|
||||
fmt.Println("addServicesMenu - not implemented")
|
||||
//C.addServicesMenu(unsafe.Pointer(menu.impl.(*linuxMenu).nsMenu))
|
||||
}
|
||||
|
||||
func (l *linuxMenu) createMenu(name string, items []*MenuItem) *Menu {
|
||||
impl := newMenuImpl(&Menu{label: name})
|
||||
menu := &Menu{
|
||||
label: name,
|
||||
items: items,
|
||||
impl: impl,
|
||||
}
|
||||
impl.menu = menu
|
||||
return menu
|
||||
}
|
||||
|
||||
func defaultApplicationMenu() *Menu {
|
||||
menu := NewMenu()
|
||||
menu.AddRole(AppMenu)
|
||||
menu.AddRole(FileMenu)
|
||||
menu.AddRole(EditMenu)
|
||||
menu.AddRole(ViewMenu)
|
||||
menu.AddRole(WindowMenu)
|
||||
menu.AddRole(HelpMenu)
|
||||
return menu
|
||||
}
|
||||
@@ -203,9 +203,7 @@ func (m *MenuItem) handleClick() {
|
||||
if m.itemType == radio {
|
||||
for _, member := range m.radioGroupMembers {
|
||||
member.checked = false
|
||||
if member.impl != nil {
|
||||
member.impl.setChecked(false)
|
||||
}
|
||||
member.impl.setChecked(false)
|
||||
}
|
||||
m.checked = true
|
||||
ctx.withChecked(true)
|
||||
|
||||
@@ -1,407 +0,0 @@
|
||||
//go:build linux
|
||||
|
||||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
/*
|
||||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
||||
|
||||
#include <stdio.h>
|
||||
#include "gtk/gtk.h"
|
||||
|
||||
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
type linuxMenuItem struct {
|
||||
menuItem *MenuItem
|
||||
native unsafe.Pointer
|
||||
handlerId C.gulong
|
||||
}
|
||||
|
||||
func (l linuxMenuItem) setTooltip(tooltip string) {
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
l.blockSignal()
|
||||
defer l.unBlockSignal()
|
||||
|
||||
value := C.CString(tooltip)
|
||||
C.gtk_widget_set_tooltip_text(
|
||||
(*C.GtkWidget)(l.native),
|
||||
value)
|
||||
C.free(unsafe.Pointer(value))
|
||||
})
|
||||
}
|
||||
|
||||
func (l linuxMenuItem) blockSignal() {
|
||||
if l.handlerId != 0 {
|
||||
C.g_signal_handler_block(C.gpointer(l.native), l.handlerId)
|
||||
}
|
||||
}
|
||||
|
||||
func (l linuxMenuItem) unBlockSignal() {
|
||||
if l.handlerId != 0 {
|
||||
C.g_signal_handler_unblock(C.gpointer(l.native), l.handlerId)
|
||||
}
|
||||
}
|
||||
|
||||
func (l linuxMenuItem) setLabel(s string) {
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
l.blockSignal()
|
||||
defer l.unBlockSignal()
|
||||
value := C.CString(s)
|
||||
C.gtk_menu_item_set_label(
|
||||
(*C.GtkMenuItem)(l.native),
|
||||
value)
|
||||
C.free(unsafe.Pointer(value))
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func (l linuxMenuItem) isChecked() bool {
|
||||
if C.gtk_check_menu_item_get_active((*C.GtkCheckMenuItem)(l.native)) == C.int(1) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l linuxMenuItem) setDisabled(disabled bool) {
|
||||
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
l.blockSignal()
|
||||
defer l.unBlockSignal()
|
||||
|
||||
value := C.int(1)
|
||||
if disabled {
|
||||
value = C.int(0)
|
||||
}
|
||||
C.gtk_widget_set_sensitive(
|
||||
(*C.GtkWidget)(l.native),
|
||||
value)
|
||||
})
|
||||
}
|
||||
|
||||
func (l linuxMenuItem) setChecked(checked bool) {
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
l.blockSignal()
|
||||
defer l.unBlockSignal()
|
||||
|
||||
value := C.int(0)
|
||||
if checked {
|
||||
value = C.int(1)
|
||||
}
|
||||
|
||||
C.gtk_check_menu_item_set_active(
|
||||
(*C.GtkCheckMenuItem)(l.native),
|
||||
value)
|
||||
})
|
||||
}
|
||||
|
||||
func (l linuxMenuItem) setAccelerator(accelerator *accelerator) {
|
||||
fmt.Println("setAccelerator", accelerator)
|
||||
// Set the keyboard shortcut of the menu item
|
||||
// var modifier C.int
|
||||
// var key *C.char
|
||||
if accelerator != nil {
|
||||
// modifier = C.int(toMacModifier(accelerator.Modifiers))
|
||||
// key = C.CString(accelerator.Key)
|
||||
}
|
||||
|
||||
// Convert the key to a string
|
||||
// C.setMenuItemKeyEquivalent(m.nsMenuItem, key, modifier)
|
||||
}
|
||||
|
||||
func newMenuItemImpl(item *MenuItem) *linuxMenuItem {
|
||||
result := &linuxMenuItem{
|
||||
menuItem: item,
|
||||
}
|
||||
cLabel := C.CString(item.label)
|
||||
switch item.itemType {
|
||||
case text:
|
||||
result.native = unsafe.Pointer(C.gtk_menu_item_new_with_label(cLabel))
|
||||
|
||||
case checkbox:
|
||||
result.native = unsafe.Pointer(C.gtk_check_menu_item_new_with_label(cLabel))
|
||||
result.setChecked(item.checked)
|
||||
if item.itemType == checkbox || item.itemType == radio {
|
||||
// C.setMenuItemChecked(result.nsMenuItem, C.bool(item.checked))
|
||||
}
|
||||
if item.accelerator != nil {
|
||||
result.setAccelerator(item.accelerator)
|
||||
}
|
||||
case radio:
|
||||
panic("Shouldn't get here with a radio item")
|
||||
|
||||
case submenu:
|
||||
result.native = unsafe.Pointer(C.gtk_menu_item_new_with_label(cLabel))
|
||||
|
||||
default:
|
||||
panic("WTF")
|
||||
}
|
||||
result.setDisabled(result.menuItem.disabled)
|
||||
|
||||
C.free(unsafe.Pointer(cLabel))
|
||||
return result
|
||||
}
|
||||
|
||||
func newRadioItemImpl(item *MenuItem, group *C.GSList) *linuxMenuItem {
|
||||
cLabel := C.CString(item.label)
|
||||
defer C.free(unsafe.Pointer(cLabel))
|
||||
result := &linuxMenuItem{
|
||||
menuItem: item,
|
||||
native: unsafe.Pointer(C.gtk_radio_menu_item_new_with_label(group, cLabel)),
|
||||
}
|
||||
result.setChecked(item.checked)
|
||||
result.setDisabled(result.menuItem.disabled)
|
||||
return result
|
||||
}
|
||||
|
||||
func newSpeechMenu() *MenuItem {
|
||||
speechMenu := NewMenu()
|
||||
speechMenu.Add("Start Speaking").
|
||||
SetAccelerator("CmdOrCtrl+OptionOrAlt+Shift+.").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.startSpeaking()
|
||||
})
|
||||
speechMenu.Add("Stop Speaking").
|
||||
SetAccelerator("CmdOrCtrl+OptionOrAlt+Shift+,").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.stopSpeaking()
|
||||
})
|
||||
subMenu := newSubMenuItem("Speech")
|
||||
subMenu.submenu = speechMenu
|
||||
return subMenu
|
||||
}
|
||||
|
||||
func newHideMenuItem() *MenuItem {
|
||||
return newMenuItem("Hide " + globalApplication.options.Name).
|
||||
SetAccelerator("CmdOrCtrl+h").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.hideApplication()
|
||||
})
|
||||
}
|
||||
|
||||
func newHideOthersMenuItem() *MenuItem {
|
||||
return newMenuItem("Hide Others").
|
||||
SetAccelerator("CmdOrCtrl+OptionOrAlt+h").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.hideOthers()
|
||||
})
|
||||
}
|
||||
|
||||
func newUnhideMenuItem() *MenuItem {
|
||||
return newMenuItem("Show All").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.showAll()
|
||||
})
|
||||
}
|
||||
|
||||
func newUndoMenuItem() *MenuItem {
|
||||
return newMenuItem("Undo").
|
||||
SetAccelerator("CmdOrCtrl+z").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.undo()
|
||||
})
|
||||
}
|
||||
|
||||
// newRedoMenuItem creates a new menu item for redoing the last action
|
||||
func newRedoMenuItem() *MenuItem {
|
||||
return newMenuItem("Redo").
|
||||
SetAccelerator("CmdOrCtrl+Shift+z").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.redo()
|
||||
})
|
||||
}
|
||||
|
||||
func newCutMenuItem() *MenuItem {
|
||||
return newMenuItem("Cut").
|
||||
SetAccelerator("CmdOrCtrl+x").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.cut()
|
||||
})
|
||||
}
|
||||
|
||||
func newCopyMenuItem() *MenuItem {
|
||||
return newMenuItem("Copy").
|
||||
SetAccelerator("CmdOrCtrl+c").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.copy()
|
||||
})
|
||||
}
|
||||
|
||||
func newPasteMenuItem() *MenuItem {
|
||||
return newMenuItem("Paste").
|
||||
SetAccelerator("CmdOrCtrl+v").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.paste()
|
||||
})
|
||||
}
|
||||
|
||||
func newPasteAndMatchStyleMenuItem() *MenuItem {
|
||||
return newMenuItem("Paste and Match Style").
|
||||
SetAccelerator("CmdOrCtrl+OptionOrAlt+Shift+v").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.pasteAndMatchStyle()
|
||||
})
|
||||
}
|
||||
|
||||
func newDeleteMenuItem() *MenuItem {
|
||||
return newMenuItem("Delete").
|
||||
SetAccelerator("backspace").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.delete()
|
||||
})
|
||||
}
|
||||
|
||||
func newQuitMenuItem() *MenuItem {
|
||||
return newMenuItem("Quit " + globalApplication.options.Name).
|
||||
SetAccelerator("CmdOrCtrl+q").
|
||||
OnClick(func(ctx *Context) {
|
||||
globalApplication.Quit()
|
||||
})
|
||||
}
|
||||
|
||||
func newSelectAllMenuItem() *MenuItem {
|
||||
return newMenuItem("Select All").
|
||||
SetAccelerator("CmdOrCtrl+a").
|
||||
OnClick(func(ctx *Context) {
|
||||
// C.selectAll()
|
||||
})
|
||||
}
|
||||
|
||||
func newAboutMenuItem() *MenuItem {
|
||||
return newMenuItem("About " + globalApplication.options.Name).
|
||||
OnClick(func(ctx *Context) {
|
||||
globalApplication.ShowAboutDialog()
|
||||
})
|
||||
}
|
||||
|
||||
func newCloseMenuItem() *MenuItem {
|
||||
return newMenuItem("Close").
|
||||
SetAccelerator("CmdOrCtrl+w").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.Close()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newReloadMenuItem() *MenuItem {
|
||||
return newMenuItem("Reload").
|
||||
SetAccelerator("CmdOrCtrl+r").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.Reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newForceReloadMenuItem() *MenuItem {
|
||||
return newMenuItem("Force Reload").
|
||||
SetAccelerator("CmdOrCtrl+Shift+r").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ForceReload()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newToggleFullscreenMenuItem() *MenuItem {
|
||||
result := newMenuItem("Toggle Full Screen").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ToggleFullscreen()
|
||||
}
|
||||
})
|
||||
if runtime.GOOS == "darwin" {
|
||||
result.SetAccelerator("Ctrl+Command+F")
|
||||
} else {
|
||||
result.SetAccelerator("F11")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func newToggleDevToolsMenuItem() *MenuItem {
|
||||
return newMenuItem("Toggle Developer Tools").
|
||||
SetAccelerator("Alt+Command+I").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ToggleDevTools()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newZoomResetMenuItem() *MenuItem {
|
||||
// reset zoom menu item
|
||||
return newMenuItem("Actual Size").
|
||||
SetAccelerator("CmdOrCtrl+0").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ZoomReset()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newZoomInMenuItem() *MenuItem {
|
||||
return newMenuItem("Zoom In").
|
||||
SetAccelerator("CmdOrCtrl+plus").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ZoomIn()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newZoomOutMenuItem() *MenuItem {
|
||||
return newMenuItem("Zoom Out").
|
||||
SetAccelerator("CmdOrCtrl+-").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ZoomOut()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newMinimizeMenuItem() *MenuItem {
|
||||
return newMenuItem("Minimize").
|
||||
SetAccelerator("CmdOrCtrl+M").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.Minimise()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newZoomMenuItem() *MenuItem {
|
||||
return newMenuItem("Zoom").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.Zoom()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newFullScreenMenuItem() *MenuItem {
|
||||
return newMenuItem("Fullscreen").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.Fullscreen()
|
||||
}
|
||||
})
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user