-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
98 lines (88 loc) · 2.85 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
package main
import (
"embed"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"log"
"simplejsoneditor/internal/lang"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
)
//go:embed frontend/dist
var assets embed.FS
//go:embed build/appicon.png
var icon []byte
func main() {
// Create an instance of the app structure
app := NewApp()
isLocaleSelected := func(l string) bool {
return app.UserLocale == l
}
// Create application with options
err := wails.Run(&options.App{
Title: "Json editor",
Width: 1200,
Height: 800,
MinWidth: 200,
MinHeight: 200,
DisableResize: false,
Fullscreen: false,
Frameless: false,
StartHidden: false,
HideWindowOnClose: false,
BackgroundColour: &options.RGBA{R: 75, G: 75, B: 75, A: 1},
AssetServer: &assetserver.Options{
Assets: assets,
},
OnStartup: app.startup,
OnDomReady: app.domReady,
OnBeforeClose: app.beforeClose,
OnShutdown: app.shutdown,
WindowStartState: options.Normal,
Linux: &linux.Options{
Icon: icon,
},
DragAndDrop: &options.DragAndDrop{
EnableFileDrop: true,
},
Menu: menu.NewMenuFromItems(
menu.SubMenu(lang.Text(app.UserLocale, "file"), menu.NewMenuFromItems(
menu.Text(lang.Text(app.UserLocale, "file.new"), keys.CmdOrCtrl("n"), func(cd *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "new-json")
}),
menu.Text(lang.Text(app.UserLocale, "file.open"), keys.CmdOrCtrl("o"), func(cd *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "open-json")
}),
menu.Text(lang.Text(app.UserLocale, "file.save"), keys.CmdOrCtrl("s"), func(cd *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "save-json")
}),
menu.Separator(),
menu.Text(lang.Text(app.UserLocale, "file.quit"), keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) {
runtime.Quit(app.ctx)
}),
)),
menu.SubMenu(lang.Text(app.UserLocale, "language"), menu.NewMenuFromItems(
menu.Radio(lang.Text(app.UserLocale, "language.en"), isLocaleSelected("en"), nil, func(cd *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "change-lang", "en")
}),
menu.Radio(lang.Text(app.UserLocale, "language.hu"), isLocaleSelected("hu"), nil, func(cd *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "change-lang", "hu")
}),
)),
menu.SubMenu(lang.Text(app.UserLocale, "view"), menu.NewMenuFromItems(
menu.Checkbox(lang.Text(app.UserLocale, "view.darkmode"), app.DarkMode, nil, func(cd *menu.CallbackData) {
runtime.EventsEmit(app.ctx, "toggle-dark-mode")
}),
)),
),
Bind: []interface{}{
app,
},
})
if err != nil {
log.Fatal(err)
}
}