Skip to content

Commit

Permalink
Fixed example for macOS menu (#3847)
Browse files Browse the repository at this point in the history
* Fixed example for macOS menu

* Update changelog.mdx
  • Loading branch information
takuyahara authored Nov 6, 2024
1 parent bdb4151 commit 1c16342
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions website/docs/reference/menus.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ An example of how to create a menu:
app := NewApp()

AppMenu := menu.NewMenu()
if runtime.GOOS == "darwin" {
AppMenu.Append(menu.AppMenu()) // On macOS platform, this must be done right after `NewMenu()`
}
FileMenu := AppMenu.AddSubmenu("File")
FileMenu.AddText("&Open", keys.CmdOrCtrl("o"), openFile)
FileMenu.AddText("&Open", keys.CmdOrCtrl("o"), func(_ *menu.CallbackData) {
// do something
})
FileMenu.AddSeparator()
FileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
runtime.Quit(app.ctx)
// `rt` is an alias of "github.com/wailsapp/wails/v2/pkg/runtime" to prevent collision with standard package
rt.Quit(app.ctx)
})

if runtime.GOOS == "darwin" {
AppMenu.Append(menu.EditMenu()) // on macos platform, we should append EditMenu to enable Cmd+C,Cmd+V,Cmd+Z... shortcut
AppMenu.Append(menu.EditMenu()) // On macOS platform, EditMenu should be appended to enable Cmd+C, Cmd+V, Cmd+Z... shortcuts
}

err := wails.Run(&options.App{
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed cross compilation failed with CGO [PR](https://github.com/wailsapp/wails/pull/3795) by [@fcying](https://github.com/fcying)
- Using go-webview2 v0.1.17 to fix native webview2loader issue, by @leaanthony
- Fixed example for macOS menu by @takuyahara in [PR](https://github.com/wailsapp/wails/pull/3847)

### Changed
- Allow to specify macos-min-version externally. Implemented by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/3756)
Expand Down

0 comments on commit 1c16342

Please sign in to comment.