Skip to content

Commit

Permalink
Merge branch 'v3-alpha-bugfix/event-emmission' into v3-alpha
Browse files Browse the repository at this point in the history
# Conflicts:
#	v3/internal/runtime/desktop/@wailsio/runtime/package.json
  • Loading branch information
leaanthony committed Dec 28, 2024
2 parents 6bc6de6 + 8b53aa3 commit e794f5d
Show file tree
Hide file tree
Showing 37 changed files with 981 additions and 686 deletions.
8 changes: 8 additions & 0 deletions docs/src/content/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `-git` flag for `wails3 init` command by [@leaanthony](https://github.com/leaanthony)
- New `wails3 generate webview2bootstrapper` command by [@leaanthony](https://github.com/leaanthony)
- Added `init()` method in runtime to allow manual initialisation of the runtime by [@leaanthony](https://github.com/leaanthony)
- Added `WindowDidMoveDebounceMS` option to Window's WindowOptions by [@leaanthony](https://github.com/leaanthony)

### Fixed

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

### Changed

- Moved build assets to platform specific directories by [@leaanthony](https://github.com/leaanthony)
- Moved and renamed Taskfiles to platform specific directories by [@leaanthony](https://github.com/leaanthony)
- Created a much better experience when `index.html` is missing by [@leaanthony](https://github.com/leaanthony)
- [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)
- Removed `ShouldClose` option (Register a hook for events.Common.WindowClosing instead) by [@leaanthony](https://github.com/leaanthony)
- [Windows] Reduced flicker when opening a window by [@leaanthony](https://github.com/leaanthony)
- Removed `Window.Destroy` as this was intended to be an internal function by [@leaanthony](https://github.com/leaanthony)
- Renamed `WindowClose` events to `WindowClosing` by [@leaanthony](https://github.com/leaanthony)


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

Expand Down
19 changes: 17 additions & 2 deletions v3/examples/frameless/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,27 @@
}
</style>
<script type="module" src="/wails/runtime.js"></script>
<script type="module">
document.addEventListener('DOMContentLoaded', (event) => {
let minimiseButton = document.querySelector('#min');
minimiseButton.addEventListener('click', function(event) {
window.wails.Window.Minimise();
setTimeout(function() {
window.wails.Window.UnMinimise();
}, 3000);
});
let closeButton = document.querySelector('#close');
closeButton.addEventListener('click', function(event) {
window.wails.Window.Close();
});
});
</script>
</head>
<body>
<div class="container">
<div class="quarter" style="background-color: lightblue; --wails-draggable: drag">Draggable</div>
<div class="quarter" style="background-color: lightgreen;">Not Draggable</div>
<div class="quarter" style="background-color: lightpink;">Not Draggable</div>
<div class="quarter" style="background-color: lightgreen;"><div>Not Draggable</div><button id="min">Minimise for 3s</button></div>
<div class="quarter" style="background-color: lightpink;"><div>Not Draggable</div><button id="close">Close</button></div>
<div class="quarter" style="background-color: lightyellow; --wails-draggable: drag">Draggable</div>
</div>
</body>
Expand Down
15 changes: 7 additions & 8 deletions v3/examples/hide-window/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package main

import (
_ "embed"
"log"
"runtime"

"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/events"
"github.com/wailsapp/wails/v3/pkg/icons"
"log"
"runtime"
)

func main() {
Expand All @@ -29,16 +28,16 @@ func main() {
AlwaysOnTop: false,
Hidden: false,
DisableResize: false,
ShouldClose: func(window *application.WebviewWindow) bool {
println("close")
window.Hide()
return false
},
Windows: application.WindowsWindow{
HiddenOnTaskbar: true,
},
})

window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
window.Hide()
e.Cancel()
})

if runtime.GOOS == "darwin" {
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
}
Expand Down
13 changes: 9 additions & 4 deletions v3/examples/systray-basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
_ "embed"
"github.com/wailsapp/wails/v3/pkg/events"
"log"
"runtime"

Expand Down Expand Up @@ -29,10 +30,6 @@ func main() {
AlwaysOnTop: true,
Hidden: true,
DisableResize: true,
ShouldClose: func(window *application.WebviewWindow) bool {
window.Hide()
return false
},
Windows: application.WindowsWindow{
HiddenOnTaskbar: true,
},
Expand All @@ -43,6 +40,14 @@ func main() {
},
})

// Register a hook to hide the window when the window is closing
window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
// Hide the window
window.Hide()
// Cancel the event so it doesn't get destroyed
e.Cancel()
})

if runtime.GOOS == "darwin" {
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
}
Expand Down
74 changes: 39 additions & 35 deletions v3/examples/systray-custom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,69 @@ package main

import (
_ "embed"
"log"
"runtime"

"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/events"
"github.com/wailsapp/wails/v3/pkg/icons"
"log"
"runtime"
)

var windowShowing bool

func createWindow(app *application.App) {
if windowShowing {
return
}
// Log the time taken to create the window
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Width: 500,
Height: 500,
Name: "Systray Demo Window",
AlwaysOnTop: true,
Hidden: true,
BackgroundColour: application.NewRGB(33, 37, 41),
DisableResize: true,
Windows: application.WindowsWindow{
HiddenOnTaskbar: true,
},
})
windowShowing = true

window.OnWindowEvent(events.Common.WindowClosing, func(e *application.WindowEvent) {
windowShowing = false
})

window.Show()
}

func main() {
app := application.New(application.Options{
Name: "Systray Demo",
Description: "A demo of the Systray API",
Assets: application.AlphaAssets,
Windows: application.WindowsOptions{
DisableQuitOnLastWindowClosed: true,
},
Mac: application.MacOptions{
ActivationPolicy: application.ActivationPolicyAccessory,
},
})

systemTray := app.NewSystemTray()

window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Width: 500,
Height: 500,
Name: "Systray Demo Window",
Frameless: true,
AlwaysOnTop: true,
Hidden: true,
DisableResize: true,
ShouldClose: func(window *application.WebviewWindow) bool {
window.Hide()
return false
},
Windows: application.WindowsWindow{
HiddenOnTaskbar: true,
},
menu := app.NewMenu()
menu.Add("Quit").OnClick(func(data *application.Context) {
app.Quit()
})
systemTray.SetMenu(menu)

if runtime.GOOS == "darwin" {
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
}

systemTray.OnClick(func() {
println("System tray clicked!")
if window.IsVisible() {
window.Hide()
} else {
window.Show()
}
})

systemTray.OnDoubleClick(func() {
println("System tray double clicked!")
createWindow(app)
})

systemTray.OnRightClick(func() {
println("System tray right clicked!")
})

systemTray.AttachWindow(window).WindowOffset(5)

err := app.Run()
if err != nil {
log.Fatal(err)
Expand Down
Binary file added v3/examples/systray-menu/logo-dark-xsmall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions v3/examples/systray-menu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package main

import (
_ "embed"
"github.com/wailsapp/wails/v3/pkg/events"
"log"
"runtime"

"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/icons"
)

//go:embed logo-dark-xsmall.png
var logo []byte

func main() {
app := application.New(application.Options{
Name: "Systray Demo",
Expand All @@ -29,10 +33,6 @@ func main() {
AlwaysOnTop: true,
Hidden: true,
DisableResize: true,
ShouldClose: func(window *application.WebviewWindow) bool {
window.Hide()
return false
},
Windows: application.WindowsWindow{
HiddenOnTaskbar: true,
},
Expand All @@ -43,12 +43,17 @@ func main() {
},
})

window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
window.Hide()
e.Cancel()
})

if runtime.GOOS == "darwin" {
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
}

myMenu := app.NewMenu()
myMenu.Add("Wails").SetBitmap(icons.WailsLogoBlackTransparent).SetEnabled(false)
myMenu.Add("Wails").SetBitmap(logo).SetEnabled(false)

myMenu.Add("Hello World!").OnClick(func(ctx *application.Context) {
println("Hello World!")
Expand Down
40 changes: 19 additions & 21 deletions v3/examples/window/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,31 +283,29 @@ func main() {
myMenu.Add("New WebviewWindow (Hides on Close one time)").
SetAccelerator("CmdOrCtrl+H").
OnClick(func(ctx *application.Context) {
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
// This will be called when the user clicks the close button
// on the window. It will hide the window for 5 seconds.
// If the user clicks the close button again, the window will
// close.
ShouldClose: func(window *application.WebviewWindow) bool {
if !lo.Contains(hiddenWindows, window) {
hiddenWindows = append(hiddenWindows, window)
go func() {
time.Sleep(5 * time.Second)
window.Show()
}()
window.Hide()
return false
}
// Remove the window from the hiddenWindows list
hiddenWindows = lo.Without(hiddenWindows, window)
return true
},
}).
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
w := app.NewWebviewWindow()

w.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
if !lo.Contains(hiddenWindows, w) {
hiddenWindows = append(hiddenWindows, w)
go func() {
time.Sleep(5 * time.Second)
w.Show()
}()
w.Hide()
e.Cancel()
}
// Remove the window from the hiddenWindows list
hiddenWindows = lo.Without(hiddenWindows, w)
})

w.SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
SetURL("https://wails.io").
Show()

windowCounter++

})
myMenu.Add("New WebviewWindow (Frameless)").
SetAccelerator("CmdOrCtrl+F").
Expand Down
2 changes: 1 addition & 1 deletion v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/pterm/pterm v0.12.51
github.com/samber/lo v1.38.1
github.com/tc-hib/winres v0.3.1
github.com/wailsapp/go-webview2 v1.0.18
github.com/wailsapp/go-webview2 v1.0.19-0.20241227010006-11c6e567b916
github.com/wailsapp/mimetype v1.4.1
github.com/wailsapp/task/v3 v3.40.1-patched3
golang.org/x/sys v0.28.0
Expand Down
2 changes: 2 additions & 0 deletions v3/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/wailsapp/go-webview2 v1.0.18 h1:SSSCoLA+MYikSp1U0WmvELF/4c3x5kH8Vi31TKyZ4yk=
github.com/wailsapp/go-webview2 v1.0.18/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
github.com/wailsapp/go-webview2 v1.0.19-0.20241227010006-11c6e567b916 h1:W0UQJWILiXJOOCg7ec5xJNqxkg4Ced5KCGO4tFAf13w=
github.com/wailsapp/go-webview2 v1.0.19-0.20241227010006-11c6e567b916/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
github.com/wailsapp/task/v3 v3.40.1-patched3 h1:i6O1WNdSur9CGaiMDIYGjsmj/qS4465zqv+WEs6sPRs=
Expand Down
36 changes: 15 additions & 21 deletions v3/internal/commands/appimage_testfiles/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,21 @@ func main() {
myMenu.Add("New WebviewWindow (Hides on Close one time)").
SetAccelerator("CmdOrCtrl+H").
OnClick(func(ctx *application.Context) {
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
// This will be called when the user clicks the close button
// on the window. It will hide the window for 5 seconds.
// If the user clicks the close button again, the window will
// close.
ShouldClose: func(window *application.WebviewWindow) bool {
if !lo.Contains(hiddenWindows, window) {
hiddenWindows = append(hiddenWindows, window)
go func() {
time.Sleep(5 * time.Second)
window.Show()
}()
window.Hide()
return false
}
// Remove the window from the hiddenWindows list
hiddenWindows = lo.Without(hiddenWindows, window)
return true
},
}).
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
w := app.NewWebviewWindow()
w.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
if !lo.Contains(hiddenWindows, w) {
hiddenWindows = append(hiddenWindows, w)
go func() {
time.Sleep(5 * time.Second)
w.Show()
}()
w.Hide()
e.Cancel()
}
// Remove the window from the hiddenWindows list
hiddenWindows = lo.Without(hiddenWindows, w)
})
w.SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
SetURL("https://wails.io").
Show()
Expand Down
Loading

0 comments on commit e794f5d

Please sign in to comment.