Fix extra button (windows, macOS).

This commit is contained in:
Nuno Cruces 2021-03-04 03:32:55 +00:00
parent b9d5eb011b
commit 7dc0e92528
2 changed files with 15 additions and 15 deletions

View file

@ -102,15 +102,15 @@ func message(kind messageKind, text string, options []Option) (bool, error) {
} }
out, err := zenutil.Run(opts.ctx, "msg", data) out, err := zenutil.Run(opts.ctx, "msg", data)
if len(out) > 0 && opts.extraButton != nil &&
string(out[:len(out)-1]) == *opts.extraButton {
return false, ErrExtraButton
}
if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 {
return false, nil return false, nil
} }
if err != nil { if err != nil {
return false, err return false, err
} }
if len(out) > 0 && opts.extraButton != nil &&
string(out[:len(out)-1]) == *opts.extraButton {
return false, ErrExtraButton
}
return true, err return true, err
} }

View file

@ -19,8 +19,10 @@ func message(kind messageKind, text string, options []Option) (bool, error) {
switch { switch {
case kind == questionKind && opts.extraButton != nil: case kind == questionKind && opts.extraButton != nil:
flags |= 0x3 // MB_YESNOCANCEL flags |= 0x3 // MB_YESNOCANCEL
case kind == questionKind || opts.extraButton != nil: case kind == questionKind:
flags |= 0x1 // MB_OKCANCEL flags |= 0x1 // MB_OKCANCEL
case opts.extraButton != nil:
flags |= 0x4 // MB_YESNO
} }
switch opts.icon { switch opts.icon {
@ -66,16 +68,16 @@ func message(kind messageKind, text string, options []Option) (bool, error) {
if opts.ctx != nil && opts.ctx.Err() != nil { if opts.ctx != nil && opts.ctx.Err() != nil {
return false, opts.ctx.Err() return false, opts.ctx.Err()
} }
if s == 0 { switch s {
case 1, 6: // IDOK, IDYES
return true, nil
case 2: // IDCANCEL
return false, nil
case 7: // IDNO
return false, ErrExtraButton
default:
return false, err return false, err
} }
if s == 7 || s == 2 && kind != questionKind { // IDNO
return false, ErrExtraButton
}
if s == 1 || s == 6 { // IDOK, IDYES
return true, nil
}
return false, nil
} }
func hookMessageLabels(kind messageKind, opts options) (unhook context.CancelFunc, err error) { func hookMessageLabels(kind messageKind, opts options) (unhook context.CancelFunc, err error) {
@ -93,8 +95,6 @@ func hookMessageLabels(kind messageKind, opts options) (unhook context.CancelFun
case 2: // IDCANCEL case 2: // IDCANCEL
if kind == questionKind { if kind == questionKind {
text = opts.cancelLabel text = opts.cancelLabel
} else if opts.extraButton != nil {
text = opts.extraButton
} else { } else {
text = opts.okLabel text = opts.okLabel
} }