-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
112 lines (101 loc) · 3.1 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"encoding/json"
"flag"
"fmt"
"foldest-go/utils"
"os"
"time"
"github.com/asticode/go-astikit"
"github.com/asticode/go-astilectron"
bootstrap "github.com/asticode/go-astilectron-bootstrap"
)
// Constants
const version = `3.0`
// const htmlAbout = `Welcome on <b>Astilectron</b> demo!<br>
// This is using the bootstrap and the bundler.`
// Vars injected via ldflags by bundler
var (
AppName string
BuiltAt string
VersionAstilectron string
VersionElectron string
)
// Application Vars
var (
fs = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
debug = fs.Bool("d", false, "enables the debug mode")
)
func main() {
htmlAbout := `<b>` + AppName + `</b> Ver ` + version + `<br>
Built Time: ` + BuiltAt[:10] + `<br>
Astilectron ` + VersionAstilectron + `<br>
Electron ` + VersionElectron + `<br>
<a href="https://github.com/Sciroccogti/Foldest-go">Github</a>
`
// Parse flags
fs.Parse(os.Args[1:])
// Run bootstrap
utils.L.Printf("Running app built at %s\n", BuiltAt)
if err := bootstrap.Run(bootstrap.Options{
Asset: Asset,
AssetDir: AssetDir,
AstilectronOptions: astilectron.Options{
AppName: AppName,
AppIconDarwinPath: "resources/icon.icns",
AppIconDefaultPath: "resources/icon.png",
SingleInstance: true,
VersionAstilectron: VersionAstilectron,
VersionElectron: VersionElectron,
},
Debug: *debug,
Logger: utils.L,
MenuOptions: []*astilectron.MenuItemOptions{{
Label: astikit.StrPtr("File"),
SubMenu: []*astilectron.MenuItemOptions{
{
Label: astikit.StrPtr("About"),
OnClick: func(e astilectron.Event) (deleteListener bool) {
if err := bootstrap.SendMessage(utils.W, "about", htmlAbout, func(m *bootstrap.MessageIn) {
// Unmarshal payload
var s string
if err := json.Unmarshal(m.Payload, &s); err != nil {
utils.L.Println(fmt.Errorf("unmarshaling payload failed: %w", err))
return
}
utils.L.Printf("About modal has been displayed and payload is %s!\n", s)
}); err != nil {
utils.L.Println(fmt.Errorf("sending about event failed: %w", err))
}
return
},
},
{Role: astilectron.MenuItemRoleClose},
},
}},
OnWait: func(_ *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
utils.W = ws[0]
go func() {
utils.W.OpenDevTools()
time.Sleep(5 * time.Second)
if err := bootstrap.SendMessage(utils.W, "check.out.menu", "Don't forget to check out the menu!"); err != nil {
utils.L.Println(fmt.Errorf("sending check.out.menu event failed: %w", err))
}
}()
return nil
},
RestoreAssets: RestoreAssets,
Windows: []*bootstrap.Window{{
Homepage: "index.html",
MessageHandler: handleMessages,
Options: &astilectron.WindowOptions{
BackgroundColor: astikit.StrPtr("#333"),
Center: astikit.BoolPtr(true),
Height: astikit.IntPtr(700),
Width: astikit.IntPtr(700),
},
}},
}); err != nil {
utils.L.Fatal(fmt.Errorf("running bootstrap failed: %w", err))
}
}