diff --git a/docs/src/content/docs/changelog.mdx b/docs/src/content/docs/changelog.mdx index 67f832ea4..33c76b99f 100644 --- a/docs/src/content/docs/changelog.mdx +++ b/docs/src/content/docs/changelog.mdx @@ -127,6 +127,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed system trays not showing after taskbar restarts by [@leaanthony](https://github.com/leaanthony) based on work by @kron. - Fixed fallbackResponseWriter not implementing Flush() in [#4245](https://github.com/wailsapp/wails/pull/4245) - Fixed fallbackResponseWriter not implementing Flush() by [@superDingda] in [#4236](https://github.com/wailsapp/wails/issues/4236) +- Fixed window not responding when using HTML field on Windows by [@leaanthony](https://github.com/leaanthony) ### Changed diff --git a/v3/examples/menu-fixes/README.md b/v3/examples/menu-fixes/README.md new file mode 100644 index 000000000..cc926df73 --- /dev/null +++ b/v3/examples/menu-fixes/README.md @@ -0,0 +1,27 @@ +# Menu Example + +This example is a demonstration of different ways to create applications without using npm. + +## Running the example + +To run the example, simply run the following command: + +```bash +go run . +``` + +# Status + +| Platform | Status | +|----------|---------| +| Mac | Working | +| Windows | Working | +| Linux | | + +# Known Issues + +- [Resize cursor still visible when not resizable](https://github.com/orgs/wailsapp/projects/6/views/1?pane=issue&itemId=40962163) + +--- + +Icon attribution: [Click icons created by kusumapotter - Flaticon](https://www.flaticon.com/free-icons/click) \ No newline at end of file diff --git a/v3/examples/menu-fixes/icon.png b/v3/examples/menu-fixes/icon.png new file mode 100644 index 000000000..e934687ca Binary files /dev/null and b/v3/examples/menu-fixes/icon.png differ diff --git a/v3/examples/menu-fixes/main.go b/v3/examples/menu-fixes/main.go new file mode 100644 index 000000000..4e69f0933 --- /dev/null +++ b/v3/examples/menu-fixes/main.go @@ -0,0 +1,160 @@ +package main + +import ( + _ "embed" + "log" + "runtime" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +//go:embed icon.png +var clickBitmap []byte + +func main() { + + app := application.New(application.Options{ + Name: "Menu Demo", + Description: "A demo of the menu system", + Assets: application.AlphaAssets, + Mac: application.MacOptions{ + ApplicationShouldTerminateAfterLastWindowClosed: true, + }, + }) + + // Create a custom menu + menu := app.NewMenu() + if runtime.GOOS == "darwin" { + menu.AddRole(application.AppMenu) + } + menu.AddRole(application.FileMenu) + menu.AddRole(application.EditMenu) + menu.AddRole(application.WindowMenu) + menu.AddRole(application.HelpMenu) + + // Let's make a "Demo" menu + myMenu := menu.AddSubmenu("Demo") + + // Hidden menu item that can be unhidden + hidden := myMenu.Add("I was hidden").SetHidden(true) + myMenu.Add("Toggle the hidden menu").OnClick(func(ctx *application.Context) { + hidden.SetHidden(!hidden.Hidden()) + }) + + disabledMenuItem := myMenu.Add("Show window").SetEnabled(false).OnClick(func(ctx *application.Context) { + // Create the window with HTML content + app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + Title: "Success", + Width: 300, + Height: 300, + HTML: "It worked", + }).Show() + }) + myMenu.Add("Enable show window").OnClick(func(ctx *application.Context) { + disabledMenuItem.SetEnabled(true) + }) + + // Add an example of URL-based window creation + myMenu.Add("Show window with URL").OnClick(func(ctx *application.Context) { + // Create a window with a URL + app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + Title: "URL Example", + Width: 800, + Height: 600, + URL: "https://wails.io", + }).Show() + }) + + // Not Enabled menu item (left for backwards compatibility) + myMenu.Add("Not Enabled").SetEnabled(false) + + // Click callbacks + myMenu.Add("Click Me!").SetAccelerator("CmdOrCtrl+l").OnClick(func(ctx *application.Context) { + switch ctx.ClickedMenuItem().Label() { + case "Click Me!": + ctx.ClickedMenuItem().SetLabel("Thanks mate!") + case "Thanks mate!": + ctx.ClickedMenuItem().SetLabel("Click Me!") + } + }) + + // You can control the current window from the menu + myMenu.Add("Lock WebviewWindow Resize").OnClick(func(ctx *application.Context) { + if app.CurrentWindow().Resizable() { + app.CurrentWindow().SetResizable(false) + ctx.ClickedMenuItem().SetLabel("Unlock WebviewWindow Resize") + } else { + app.CurrentWindow().SetResizable(true) + ctx.ClickedMenuItem().SetLabel("Lock WebviewWindow Resize") + } + }) + + myMenu.AddSeparator() + + // Checkboxes will tell you their new state so you don't need to track it + myMenu.AddCheckbox("My checkbox", true).OnClick(func(context *application.Context) { + println("Clicked checkbox. Checked:", context.ClickedMenuItem().Checked()) + }) + myMenu.AddSeparator() + + // Callbacks can be shared. This is useful for radio groups + radioCallback := func(ctx *application.Context) { + menuItem := ctx.ClickedMenuItem() + menuItem.SetLabel(menuItem.Label() + "!") + } + + // Radio groups are created implicitly by placing radio items next to each other in a menu + myMenu.AddRadio("Radio 1", true).OnClick(radioCallback) + myMenu.AddRadio("Radio 2", false).OnClick(radioCallback) + myMenu.AddRadio("Radio 3", false).OnClick(radioCallback) + + // Submenus are also supported + submenu := myMenu.AddSubmenu("Submenu") + submenu.Add("Submenu item 1") + submenu.Add("Submenu item 2") + submenu.Add("Submenu item 3") + + myMenu.AddSeparator() + + // This used to crash + myMenu.Update() + + // This used to do nothing on windows + myMenu.Add("Reset menu").OnClick(func(ctx *application.Context) { + myMenu.Clear() + myMenu.Add("New option") + myMenu.Update() + }) + + beatles := myMenu.Add("Hello").OnClick(func(*application.Context) { + println("The beatles would be proud") + }) + myMenu.Add("Toggle the menuitem above").OnClick(func(*application.Context) { + if beatles.Enabled() { + beatles.SetEnabled(false) + beatles.SetLabel("Goodbye") + } else { + beatles.SetEnabled(true) + beatles.SetLabel("Hello") + } + }) + myMenu.Add("Hide the beatles").OnClick(func(ctx *application.Context) { + if beatles.Hidden() { + ctx.ClickedMenuItem().SetLabel("Hide the beatles!") + beatles.SetHidden(false) + } else { + beatles.SetHidden(true) + ctx.ClickedMenuItem().SetLabel("Unhide the beatles!") + } + }) + app.SetMenu(menu) + + window := app.NewWebviewWindow().SetBackgroundColour(application.NewRGB(33, 37, 41)) + window.SetMenu(menu) + + err := app.Run() + + if err != nil { + log.Fatal(err.Error()) + } +} diff --git a/v3/examples/menu-fixes/menu_demo b/v3/examples/menu-fixes/menu_demo new file mode 100644 index 000000000..78926ad95 Binary files /dev/null and b/v3/examples/menu-fixes/menu_demo differ