mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 11:40:56 +08:00
Init GTK in NewFrontend
, not init
(#2841)
* Init GTK in `NewFrontend`, not `init` So apps that have a headless / non-gui mode will be able to run, since they needn't call `NewFrontend` (which is called by `CreateApp`). Previously, `init` would call `C.gtk_init` regardless of whether CreateApp was called. Also change to call `C.gtk_init_check` with a panic, instead of `C.gtk_init`, since `gtk_init` just exits the process if it fails, without a sensible error message. Fixes #2628. * Update changelog
This commit is contained in:
parent
98bb3b6361
commit
427fe7e8d3
@ -76,6 +76,7 @@ import "C"
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
@ -83,6 +84,7 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"text/template"
|
||||
"unsafe"
|
||||
|
||||
@ -96,6 +98,8 @@ import (
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
)
|
||||
|
||||
var initOnce = sync.Once{}
|
||||
|
||||
const startURL = "wails://wails/"
|
||||
|
||||
type Frontend struct {
|
||||
@ -126,18 +130,19 @@ func (f *Frontend) WindowClose() {
|
||||
f.mainWindow.Destroy()
|
||||
}
|
||||
|
||||
func init() {
|
||||
runtime.LockOSThread()
|
||||
|
||||
// Set GDK_BACKEND=x11 if currently unset and XDG_SESSION_TYPE is unset, unspecified or x11 to prevent warnings
|
||||
if os.Getenv("GDK_BACKEND") == "" && (os.Getenv("XDG_SESSION_TYPE") == "" || os.Getenv("XDG_SESSION_TYPE") == "unspecified" || os.Getenv("XDG_SESSION_TYPE") == "x11") {
|
||||
_ = os.Setenv("GDK_BACKEND", "x11")
|
||||
}
|
||||
|
||||
C.gtk_init(nil, nil)
|
||||
}
|
||||
|
||||
func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
|
||||
initOnce.Do(func() {
|
||||
runtime.LockOSThread()
|
||||
|
||||
// Set GDK_BACKEND=x11 if currently unset and XDG_SESSION_TYPE is unset, unspecified or x11 to prevent warnings
|
||||
if os.Getenv("GDK_BACKEND") == "" && (os.Getenv("XDG_SESSION_TYPE") == "" || os.Getenv("XDG_SESSION_TYPE") == "unspecified" || os.Getenv("XDG_SESSION_TYPE") == "x11") {
|
||||
_ = os.Setenv("GDK_BACKEND", "x11")
|
||||
}
|
||||
|
||||
if ok := C.gtk_init_check(nil, nil); ok != 1 {
|
||||
panic(errors.New("failed to init GTK"))
|
||||
}
|
||||
})
|
||||
|
||||
result := &Frontend{
|
||||
frontendOptions: appoptions,
|
||||
|
@ -21,9 +21,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Fixed
|
||||
|
||||
- Avoid app crashing when the Linux GTK key is empty. Fixed by @aminya in [PR](https://github.com/wailsapp/wails/pull/2672)
|
||||
- Fix issue where app would exit before main() on linux if $DISPLAY env var was not set. Fixed by @phildrip in [PR](https://github.com/wailsapp/wails/pull/2841)
|
||||
- Fixed a race condition when positioning the window on Linux. Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2850)
|
||||
- Fixed `SetBackgroundColour` so it sets the window's background color to reduce resize flickering on Linux. Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2853)
|
||||
|
||||
|
||||
### Added
|
||||
|
||||
- Added correct NodeJS and Docker package names for DNF package manager of Fedora 38. Added by @aranggitoar in [PR](https://github.com/wailsapp/wails/pull/2790)
|
||||
|
Loading…
Reference in New Issue
Block a user