You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
671 B
50 lines
671 B
2 years ago
|
package ui
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
type Options struct {
|
||
|
Name string
|
||
|
Version string
|
||
|
OnClose func()
|
||
|
}
|
||
|
|
||
|
type GUIApp interface {
|
||
|
Run(exitCh chan os.Signal) int
|
||
|
Close()
|
||
|
}
|
||
|
|
||
|
func (o *Options) Validate() error {
|
||
|
if len(o.Version) == 0 {
|
||
|
return fmt.Errorf("version is required")
|
||
|
}
|
||
|
|
||
|
if o.OnClose == nil {
|
||
|
return fmt.Errorf("missing onClose function")
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type Option func(*Options)
|
||
|
|
||
|
func Version(v string) Option {
|
||
|
return func(o *Options) {
|
||
|
o.Version = v
|
||
|
}
|
||
|
}
|
||
|
func Name(n string) Option {
|
||
|
return func(o *Options) {
|
||
|
o.Name = n
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// OnClose 关闭窗口事件
|
||
|
func OnClose(f func()) Option {
|
||
|
return func(o *Options) {
|
||
|
o.OnClose = f
|
||
|
}
|
||
|
}
|