-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (86 loc) · 2.57 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"flag"
"encoding/json"
"github.com/asticode/go-astilectron"
"github.com/asticode/go-astilectron-bootstrap"
"github.com/asticode/go-astilog"
"github.com/pkg/errors"
)
// Constants
const htmlAbout = `图片来源必应.`
// Vars
var (
AppName string
BuiltAt string
debug = flag.Bool("d", false, "enables the debug mode")
w *astilectron.Window
)
func main() {
// Init
flag.Parse()
astilog.FlagInit()
AppName = "BingDesktop"
// Run bootstrap
astilog.Debugf("Running app built at %s", BuiltAt)
if err := bootstrap.Run(bootstrap.Options{
Asset: Asset,
AssetDir: AssetDir,
AstilectronOptions: astilectron.Options{
AppName: AppName,
AppIconDarwinPath: "resources/icon.icns",
AppIconDefaultPath: "resources/icon.png",
//BaseDirectoryPath:"D:/GOPATH/src/yin/BingDesktop",
},
Debug: false,
MenuOptions: []*astilectron.MenuItemOptions{{
Label: astilectron.PtrStr("文件"),
SubMenu: []*astilectron.MenuItemOptions{
{
Label: astilectron.PtrStr("关于"),
OnClick: func(e astilectron.Event) (deleteListener bool) {
if err := bootstrap.SendMessage(w, "about", htmlAbout, func(m *bootstrap.MessageIn) {
// Unmarshal payload
var s string
if err := json.Unmarshal(m.Payload, &s); err != nil {
astilog.Error(errors.Wrap(err, "unmarshaling payload failed"))
return
}
astilog.Info(s)
astilog.Infof("关于 is %s!", s)
}); err != nil {
astilog.Error(errors.Wrap(err, "sending about event failed"))
}
return
},
},
{Role: astilectron.MenuItemRoleClose},
},
}},
OnWait: func(_ *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
w = ws[0]
// go func() {
// time.Sleep(5 * time.Second)
// if err := bootstrap.SendMessage(w, "check.out.menu", "Don't forget to check out the menu!"); err != nil {
// astilog.Error(errors.Wrap(err, "sending check.out.menu event failed"))
// }
// }()
//w.OpenDevTools()
return nil
},
RestoreAssets: RestoreAssets,
Windows: []*bootstrap.Window{{
Homepage: "index.html",
MessageHandler: bingHandleMessages,
Options: &astilectron.WindowOptions{
BackgroundColor: astilectron.PtrStr("#333"),
Center: astilectron.PtrBool(true),
Height: astilectron.PtrInt(600),
Width: astilectron.PtrInt(1000),
//AlwaysOnTop: astilectron.PtrBool(true),
},
}},
}); err != nil {
astilog.Fatal(errors.Wrap(err, "running bootstrap failed"))
}
}