[v3] Update dev guide. Remove implLock.

This commit is contained in:
Lea Anthony 2023-06-21 19:37:39 +10:00
commit 4d2b4b4ee7
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
2 changed files with 16 additions and 12 deletions

View file

@ -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:

View file

@ -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
}