Skip to content

Commit e794f5d

Browse files
committed
Merge branch 'v3-alpha-bugfix/event-emmission' into v3-alpha
# Conflicts: # v3/internal/runtime/desktop/@wailsio/runtime/package.json
2 parents 6bc6de6 + 8b53aa3 commit e794f5d

37 files changed

+981
-686
lines changed

docs/src/content/docs/changelog.mdx

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- New `-git` flag for `wails3 init` command by [@leaanthony](https://github.com/leaanthony)
3333
- New `wails3 generate webview2bootstrapper` command by [@leaanthony](https://github.com/leaanthony)
3434
- Added `init()` method in runtime to allow manual initialisation of the runtime by [@leaanthony](https://github.com/leaanthony)
35+
- Added `WindowDidMoveDebounceMS` option to Window's WindowOptions by [@leaanthony](https://github.com/leaanthony)
3536

3637
### Fixed
3738

@@ -45,13 +46,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4546
-  Improved window destroying logic by [@leaanthony](https://github.com/leaanthony)
4647
-  Fix window position logic when attached to system trays by [@leaanthony](https://github.com/leaanthony)
4748
-  Support fullscreen for frameless windows by [@leaanthony](https://github.com/leaanthony)
49+
- Fix event handling by [@leaanthony](https://github.com/leaanthony)
50+
- Fixed window shutdown logic by [@leaanthony](https://github.com/leaanthony)
4851

4952
### Changed
5053

5154
- Moved build assets to platform specific directories by [@leaanthony](https://github.com/leaanthony)
5255
- Moved and renamed Taskfiles to platform specific directories by [@leaanthony](https://github.com/leaanthony)
5356
- Created a much better experience when `index.html` is missing by [@leaanthony](https://github.com/leaanthony)
5457
- [Windows] Improved performance of minimise and restore by [@leaanthony](https://github.com/leaanthony). Based on original [PR](https://github.com/wailsapp/wails/pull/3955) by [562589540](https://github.com/562589540)
58+
- Removed `ShouldClose` option (Register a hook for events.Common.WindowClosing instead) by [@leaanthony](https://github.com/leaanthony)
59+
- [Windows] Reduced flicker when opening a window by [@leaanthony](https://github.com/leaanthony)
60+
- Removed `Window.Destroy` as this was intended to be an internal function by [@leaanthony](https://github.com/leaanthony)
61+
- Renamed `WindowClose` events to `WindowClosing` by [@leaanthony](https://github.com/leaanthony)
62+
5563

5664
## v3.0.0-alpha.8.3 - 2024-12-07
5765

v3/examples/frameless/assets/index.html

+17-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,27 @@
2121
}
2222
</style>
2323
<script type="module" src="/wails/runtime.js"></script>
24+
<script type="module">
25+
document.addEventListener('DOMContentLoaded', (event) => {
26+
let minimiseButton = document.querySelector('#min');
27+
minimiseButton.addEventListener('click', function(event) {
28+
window.wails.Window.Minimise();
29+
setTimeout(function() {
30+
window.wails.Window.UnMinimise();
31+
}, 3000);
32+
});
33+
let closeButton = document.querySelector('#close');
34+
closeButton.addEventListener('click', function(event) {
35+
window.wails.Window.Close();
36+
});
37+
});
38+
</script>
2439
</head>
2540
<body>
2641
<div class="container">
2742
<div class="quarter" style="background-color: lightblue; --wails-draggable: drag">Draggable</div>
28-
<div class="quarter" style="background-color: lightgreen;">Not Draggable</div>
29-
<div class="quarter" style="background-color: lightpink;">Not Draggable</div>
43+
<div class="quarter" style="background-color: lightgreen;"><div>Not Draggable</div><button id="min">Minimise for 3s</button></div>
44+
<div class="quarter" style="background-color: lightpink;"><div>Not Draggable</div><button id="close">Close</button></div>
3045
<div class="quarter" style="background-color: lightyellow; --wails-draggable: drag">Draggable</div>
3146
</div>
3247
</body>

v3/examples/hide-window/main.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package main
22

33
import (
44
_ "embed"
5-
"log"
6-
"runtime"
7-
85
"github.com/wailsapp/wails/v3/pkg/application"
96
"github.com/wailsapp/wails/v3/pkg/events"
107
"github.com/wailsapp/wails/v3/pkg/icons"
8+
"log"
9+
"runtime"
1110
)
1211

1312
func main() {
@@ -29,16 +28,16 @@ func main() {
2928
AlwaysOnTop: false,
3029
Hidden: false,
3130
DisableResize: false,
32-
ShouldClose: func(window *application.WebviewWindow) bool {
33-
println("close")
34-
window.Hide()
35-
return false
36-
},
3731
Windows: application.WindowsWindow{
3832
HiddenOnTaskbar: true,
3933
},
4034
})
4135

36+
window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
37+
window.Hide()
38+
e.Cancel()
39+
})
40+
4241
if runtime.GOOS == "darwin" {
4342
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
4443
}

v3/examples/systray-basic/main.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
_ "embed"
5+
"github.com/wailsapp/wails/v3/pkg/events"
56
"log"
67
"runtime"
78

@@ -29,10 +30,6 @@ func main() {
2930
AlwaysOnTop: true,
3031
Hidden: true,
3132
DisableResize: true,
32-
ShouldClose: func(window *application.WebviewWindow) bool {
33-
window.Hide()
34-
return false
35-
},
3633
Windows: application.WindowsWindow{
3734
HiddenOnTaskbar: true,
3835
},
@@ -43,6 +40,14 @@ func main() {
4340
},
4441
})
4542

43+
// Register a hook to hide the window when the window is closing
44+
window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
45+
// Hide the window
46+
window.Hide()
47+
// Cancel the event so it doesn't get destroyed
48+
e.Cancel()
49+
})
50+
4651
if runtime.GOOS == "darwin" {
4752
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
4853
}

v3/examples/systray-custom/main.go

+39-35
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,69 @@ package main
22

33
import (
44
_ "embed"
5-
"log"
6-
"runtime"
7-
85
"github.com/wailsapp/wails/v3/pkg/application"
6+
"github.com/wailsapp/wails/v3/pkg/events"
97
"github.com/wailsapp/wails/v3/pkg/icons"
8+
"log"
9+
"runtime"
1010
)
1111

12+
var windowShowing bool
13+
14+
func createWindow(app *application.App) {
15+
if windowShowing {
16+
return
17+
}
18+
// Log the time taken to create the window
19+
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
20+
Width: 500,
21+
Height: 500,
22+
Name: "Systray Demo Window",
23+
AlwaysOnTop: true,
24+
Hidden: true,
25+
BackgroundColour: application.NewRGB(33, 37, 41),
26+
DisableResize: true,
27+
Windows: application.WindowsWindow{
28+
HiddenOnTaskbar: true,
29+
},
30+
})
31+
windowShowing = true
32+
33+
window.OnWindowEvent(events.Common.WindowClosing, func(e *application.WindowEvent) {
34+
windowShowing = false
35+
})
36+
37+
window.Show()
38+
}
39+
1240
func main() {
1341
app := application.New(application.Options{
1442
Name: "Systray Demo",
1543
Description: "A demo of the Systray API",
1644
Assets: application.AlphaAssets,
45+
Windows: application.WindowsOptions{
46+
DisableQuitOnLastWindowClosed: true,
47+
},
1748
Mac: application.MacOptions{
1849
ActivationPolicy: application.ActivationPolicyAccessory,
1950
},
2051
})
2152

2253
systemTray := app.NewSystemTray()
23-
24-
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
25-
Width: 500,
26-
Height: 500,
27-
Name: "Systray Demo Window",
28-
Frameless: true,
29-
AlwaysOnTop: true,
30-
Hidden: true,
31-
DisableResize: true,
32-
ShouldClose: func(window *application.WebviewWindow) bool {
33-
window.Hide()
34-
return false
35-
},
36-
Windows: application.WindowsWindow{
37-
HiddenOnTaskbar: true,
38-
},
54+
menu := app.NewMenu()
55+
menu.Add("Quit").OnClick(func(data *application.Context) {
56+
app.Quit()
3957
})
58+
systemTray.SetMenu(menu)
4059

4160
if runtime.GOOS == "darwin" {
4261
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
4362
}
4463

4564
systemTray.OnClick(func() {
46-
println("System tray clicked!")
47-
if window.IsVisible() {
48-
window.Hide()
49-
} else {
50-
window.Show()
51-
}
52-
})
53-
54-
systemTray.OnDoubleClick(func() {
55-
println("System tray double clicked!")
65+
createWindow(app)
5666
})
5767

58-
systemTray.OnRightClick(func() {
59-
println("System tray right clicked!")
60-
})
61-
62-
systemTray.AttachWindow(window).WindowOffset(5)
63-
6468
err := app.Run()
6569
if err != nil {
6670
log.Fatal(err)
1.74 KB
Loading

v3/examples/systray-menu/main.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package main
22

33
import (
44
_ "embed"
5+
"github.com/wailsapp/wails/v3/pkg/events"
56
"log"
67
"runtime"
78

89
"github.com/wailsapp/wails/v3/pkg/application"
910
"github.com/wailsapp/wails/v3/pkg/icons"
1011
)
1112

13+
//go:embed logo-dark-xsmall.png
14+
var logo []byte
15+
1216
func main() {
1317
app := application.New(application.Options{
1418
Name: "Systray Demo",
@@ -29,10 +33,6 @@ func main() {
2933
AlwaysOnTop: true,
3034
Hidden: true,
3135
DisableResize: true,
32-
ShouldClose: func(window *application.WebviewWindow) bool {
33-
window.Hide()
34-
return false
35-
},
3636
Windows: application.WindowsWindow{
3737
HiddenOnTaskbar: true,
3838
},
@@ -43,12 +43,17 @@ func main() {
4343
},
4444
})
4545

46+
window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
47+
window.Hide()
48+
e.Cancel()
49+
})
50+
4651
if runtime.GOOS == "darwin" {
4752
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
4853
}
4954

5055
myMenu := app.NewMenu()
51-
myMenu.Add("Wails").SetBitmap(icons.WailsLogoBlackTransparent).SetEnabled(false)
56+
myMenu.Add("Wails").SetBitmap(logo).SetEnabled(false)
5257

5358
myMenu.Add("Hello World!").OnClick(func(ctx *application.Context) {
5459
println("Hello World!")

v3/examples/window/main.go

+19-21
Original file line numberDiff line numberDiff line change
@@ -283,31 +283,29 @@ func main() {
283283
myMenu.Add("New WebviewWindow (Hides on Close one time)").
284284
SetAccelerator("CmdOrCtrl+H").
285285
OnClick(func(ctx *application.Context) {
286-
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
287-
// This will be called when the user clicks the close button
288-
// on the window. It will hide the window for 5 seconds.
289-
// If the user clicks the close button again, the window will
290-
// close.
291-
ShouldClose: func(window *application.WebviewWindow) bool {
292-
if !lo.Contains(hiddenWindows, window) {
293-
hiddenWindows = append(hiddenWindows, window)
294-
go func() {
295-
time.Sleep(5 * time.Second)
296-
window.Show()
297-
}()
298-
window.Hide()
299-
return false
300-
}
301-
// Remove the window from the hiddenWindows list
302-
hiddenWindows = lo.Without(hiddenWindows, window)
303-
return true
304-
},
305-
}).
306-
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
286+
w := app.NewWebviewWindow()
287+
288+
w.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
289+
if !lo.Contains(hiddenWindows, w) {
290+
hiddenWindows = append(hiddenWindows, w)
291+
go func() {
292+
time.Sleep(5 * time.Second)
293+
w.Show()
294+
}()
295+
w.Hide()
296+
e.Cancel()
297+
}
298+
// Remove the window from the hiddenWindows list
299+
hiddenWindows = lo.Without(hiddenWindows, w)
300+
})
301+
302+
w.SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
307303
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
308304
SetURL("https://wails.io").
309305
Show()
306+
310307
windowCounter++
308+
311309
})
312310
myMenu.Add("New WebviewWindow (Frameless)").
313311
SetAccelerator("CmdOrCtrl+F").

v3/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
github.com/pterm/pterm v0.12.51
3131
github.com/samber/lo v1.38.1
3232
github.com/tc-hib/winres v0.3.1
33-
github.com/wailsapp/go-webview2 v1.0.18
33+
github.com/wailsapp/go-webview2 v1.0.19-0.20241227010006-11c6e567b916
3434
github.com/wailsapp/mimetype v1.4.1
3535
github.com/wailsapp/task/v3 v3.40.1-patched3
3636
golang.org/x/sys v0.28.0

v3/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
305305
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
306306
github.com/wailsapp/go-webview2 v1.0.18 h1:SSSCoLA+MYikSp1U0WmvELF/4c3x5kH8Vi31TKyZ4yk=
307307
github.com/wailsapp/go-webview2 v1.0.18/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
308+
github.com/wailsapp/go-webview2 v1.0.19-0.20241227010006-11c6e567b916 h1:W0UQJWILiXJOOCg7ec5xJNqxkg4Ced5KCGO4tFAf13w=
309+
github.com/wailsapp/go-webview2 v1.0.19-0.20241227010006-11c6e567b916/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
308310
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
309311
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
310312
github.com/wailsapp/task/v3 v3.40.1-patched3 h1:i6O1WNdSur9CGaiMDIYGjsmj/qS4465zqv+WEs6sPRs=

v3/internal/commands/appimage_testfiles/main.go

+15-21
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,21 @@ func main() {
6060
myMenu.Add("New WebviewWindow (Hides on Close one time)").
6161
SetAccelerator("CmdOrCtrl+H").
6262
OnClick(func(ctx *application.Context) {
63-
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
64-
// This will be called when the user clicks the close button
65-
// on the window. It will hide the window for 5 seconds.
66-
// If the user clicks the close button again, the window will
67-
// close.
68-
ShouldClose: func(window *application.WebviewWindow) bool {
69-
if !lo.Contains(hiddenWindows, window) {
70-
hiddenWindows = append(hiddenWindows, window)
71-
go func() {
72-
time.Sleep(5 * time.Second)
73-
window.Show()
74-
}()
75-
window.Hide()
76-
return false
77-
}
78-
// Remove the window from the hiddenWindows list
79-
hiddenWindows = lo.Without(hiddenWindows, window)
80-
return true
81-
},
82-
}).
83-
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
63+
w := app.NewWebviewWindow()
64+
w.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
65+
if !lo.Contains(hiddenWindows, w) {
66+
hiddenWindows = append(hiddenWindows, w)
67+
go func() {
68+
time.Sleep(5 * time.Second)
69+
w.Show()
70+
}()
71+
w.Hide()
72+
e.Cancel()
73+
}
74+
// Remove the window from the hiddenWindows list
75+
hiddenWindows = lo.Without(hiddenWindows, w)
76+
})
77+
w.SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
8478
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
8579
SetURL("https://wails.io").
8680
Show()

0 commit comments

Comments
 (0)