From 4d2b4b4ee7a62f47747a91429159cc704206ec11 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 21 Jun 2023 19:37:39 +1000 Subject: [PATCH] [v3] Update dev guide. Remove implLock. --- v3/DEVELOPMENT.md | 13 +++++++++++++ v3/pkg/application/webview_window.go | 15 +++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/v3/DEVELOPMENT.md b/v3/DEVELOPMENT.md index 468c9a5ad..04ec5a8e8 100644 --- a/v3/DEVELOPMENT.md +++ b/v3/DEVELOPMENT.md @@ -27,6 +27,8 @@ The project has the following structure: ├── cmd/wails // CLI ├── examples // Examples of Wails apps ├── internal // Internal packages + | ├── runtime // The Wails JS runtime + | └── templates // The supported project templates ├── pkg | ├── application // The core Wails library | └── events // The event definitions @@ -39,6 +41,17 @@ The project has the following structure: ## Development +### Adding window functionality + +The preferred way to add window functionality is to add a new function to the `pkg/application/webview_window.go` file. This should implement all the functionality required for all platforms. Any platform specific code should be called via a `webviewWindowImpl` interface method. This interface is implemented by each of the target platforms to provide the platform specific functionality. In some cases, this may do nothing. +Once you've added the interface method, ensure each platform implements it. A good example of this is the `SetMinSize` method. + +- Mac: `webview_window_darwin.go` +- Windows: `webview_window_windows.go` +- Linux: `webview_window_linux.go` + +Most, if not all, of the platform specific code should be run on the main thread. To simplify this, there are a number of `invokeSync` methods defined in `application.go`. + ### Updating the runtime The runtime is located in `v3/internal/runtime`. When the runtime is updated, the following steps need to be taken: diff --git a/v3/pkg/application/webview_window.go b/v3/pkg/application/webview_window.go index 27f31f90c..9394a0038 100644 --- a/v3/pkg/application/webview_window.go +++ b/v3/pkg/application/webview_window.go @@ -74,10 +74,9 @@ type WindowEventListener struct { } type WebviewWindow struct { - options WebviewWindowOptions - impl webviewWindowImpl - implLock sync.RWMutex - id uint + options WebviewWindowOptions + impl webviewWindowImpl + id uint eventListeners map[uint][]*WindowEventListener eventListenersLock sync.RWMutex @@ -149,8 +148,6 @@ func (w *WebviewWindow) addCancellationFunction(canceller func()) { // SetTitle sets the title of the window func (w *WebviewWindow) SetTitle(title string) *WebviewWindow { - w.implLock.RLock() - defer w.implLock.RUnlock() w.options.Title = title if w.impl != nil { invokeSync(func() { @@ -212,9 +209,7 @@ func (w *WebviewWindow) run() { if w.impl != nil { return } - w.implLock.Lock() w.impl = newWindowImpl(w) - w.implLock.Unlock() invokeSync(w.impl.run) } @@ -431,8 +426,6 @@ func (w *WebviewWindow) Size() (int, int) { // IsFullscreen returns true if the window is fullscreen func (w *WebviewWindow) IsFullscreen() bool { - w.implLock.RLock() - defer w.implLock.RUnlock() if w.impl == nil { return false } @@ -548,8 +541,6 @@ func (w *WebviewWindow) Height() int { // Position returns the position of the window func (w *WebviewWindow) Position() (int, int) { - w.implLock.RLock() - defer w.implLock.RUnlock() if w.impl == nil { return 0, 0 }