Make menus to be displayed on Windows OS in v3\examples\dialogs (#4928)

* fix: make menus to be displayed on Windows OS in `v3\examples\dialogs`

* refactor: use cross-platform user home dir in `v3/examples/dialogs/main.go`

* fix: handle os.UserHomeDir() error with fallback to os.TempDir()

* fix: use = instead of := for err (already declared)

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
Ndianabasi Udonkang 2026-02-02 09:41:35 +01:00 committed by GitHub
commit 470c929b42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 5 deletions

View file

@ -25,6 +25,7 @@ After processing, the content will be moved to the main changelog and this file
<!-- Bug fixes -->
- Fix potential panic when setting empty icon or bitmap on Linux (#4923) by @ddmoney420
- Fix ErrorDialog crash when called from service binding on macOS (#3631) by @leaanthony
- Make menus to be displayed on Windows OS in `v3\examples\dialogs` by @ndianabasi
## Deprecated
<!-- Soon-to-be removed features -->

View file

@ -27,7 +27,14 @@ func main() {
// Create a custom menu
menu := app.NewMenu()
menu.AddRole(application.AppMenu)
// macOS: Add application menu
if runtime.GOOS == "darwin" {
menu.AddRole(application.AppMenu)
}
// All platforms: Add standard menus
menu.AddRole(application.FileMenu)
menu.AddRole(application.EditMenu)
menu.AddRole(application.WindowMenu)
menu.AddRole(application.ServicesMenu)
@ -332,12 +339,18 @@ func main() {
app.Dialog.Info().SetMessage(result).Show()
}
})
userHomeDir, err := os.UserHomeDir()
if err != nil || userHomeDir == "" {
userHomeDir = os.TempDir()
}
saveMenu.Add("Select File (Full Example)").OnClick(func(ctx *application.Context) {
result, _ := app.Dialog.SaveFile().
CanCreateDirectories(false).
ShowHiddenFiles(true).
SetMessage("Select a file").
SetDirectory("/Applications").
SetDirectory(userHomeDir).
SetButtonText("Let's do this!").
SetFilename("README.md").
HideExtension(true).
@ -350,11 +363,15 @@ func main() {
}
})
app.Menu.Set(menu)
window := app.Window.New()
app.Window.New()
if runtime.GOOS == "darwin" {
app.Menu.Set(menu)
} else {
window.SetMenu(menu)
}
err := app.Run()
err = app.Run()
if err != nil {
log.Fatal(err.Error())