5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-06 21:22:19 +08:00

[v3 windows] Support About box. Improve app menu handling.

This commit is contained in:
Lea Anthony 2023-06-06 20:40:38 +10:00
parent 23d7ac0e58
commit df0969d1c6
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
4 changed files with 27 additions and 5 deletions

View File

@ -11,13 +11,22 @@ import (
) )
func (m *windowsApp) showAboutDialog(title string, message string, icon []byte) { func (m *windowsApp) showAboutDialog(title string, message string, icon []byte) {
panic("implement me") about := newDialogImpl(&MessageDialog{
MessageDialogOptions: MessageDialogOptions{
DialogType: InfoDialog,
Title: title,
Message: message,
},
})
about.UseAppIcon = true
about.show()
} }
type windowsDialog struct { type windowsDialog struct {
dialog *MessageDialog dialog *MessageDialog
//dialogImpl unsafe.Pointer //dialogImpl unsafe.Pointer
UseAppIcon bool
} }
func (m *windowsDialog) show() { func (m *windowsDialog) show() {
@ -25,8 +34,14 @@ func (m *windowsDialog) show() {
title := w32.MustStringToUTF16Ptr(m.dialog.Title) title := w32.MustStringToUTF16Ptr(m.dialog.Title)
message := w32.MustStringToUTF16Ptr(m.dialog.Message) message := w32.MustStringToUTF16Ptr(m.dialog.Message)
flags := calculateMessageDialogFlags(m.dialog.MessageDialogOptions) flags := calculateMessageDialogFlags(m.dialog.MessageDialogOptions)
var button int32
button, _ := windows.MessageBox(windows.HWND(0), message, title, flags|windows.MB_SYSTEMMODAL) if m.UseAppIcon {
// 3 is the application icon
button, _ = w32.MessageBoxWithIcon(0, message, title, 3, windows.MB_OK|windows.MB_USERICON)
} else {
button, _ = windows.MessageBox(windows.HWND(0), message, title, flags|windows.MB_SYSTEMMODAL)
}
// This maps MessageBox return values to strings // This maps MessageBox return values to strings
responses := []string{"", "Ok", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No", "", "", "Try Again", "Continue"} responses := []string{"", "Ok", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No", "", "", "Try Again", "Continue"}
result := "Error" result := "Error"

View File

@ -54,7 +54,9 @@ func (m *Menu) AddSubmenu(s string) *Menu {
func (m *Menu) AddRole(role Role) *Menu { func (m *Menu) AddRole(role Role) *Menu {
result := newRole(role) result := newRole(role)
if result != nil {
m.items = append(m.items, result) m.items = append(m.items, result)
}
return m return m
} }

View File

@ -186,8 +186,10 @@ func newSelectAllMenuItem() *MenuItem {
} }
func newAboutMenuItem() *MenuItem { func newAboutMenuItem() *MenuItem {
panic("implement me") return newMenuItem("About " + globalApplication.options.Name).
OnClick(func(ctx *Context) {
globalApplication.ShowAboutDialog()
})
} }
func newCloseMenuItem() *MenuItem { func newCloseMenuItem() *MenuItem {

View File

@ -89,6 +89,9 @@ func newViewMenu() *MenuItem {
} }
func newAppMenu() *MenuItem { func newAppMenu() *MenuItem {
if runtime.GOOS != "darwin" {
return nil
}
appMenu := NewMenu() appMenu := NewMenu()
appMenu.AddRole(About) appMenu.AddRole(About)
appMenu.AddSeparator() appMenu.AddSeparator()