-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
126 lines (103 loc) · 2.83 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"go-anime-matrix-io/internal/gui"
"go-anime-matrix-io/pkg/utils"
"log"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"embed"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
)
//go:embed Icon.png
var IconFile embed.FS
// Main window
var _ fyne.Window
const initialScreen = "settings"
// makeTray renders the system tray menu
func makeTray(a fyne.App, w fyne.Window) {
if desk, ok := a.(desktop.App); ok {
h := fyne.NewMenuItem("Open settings", func() {
log.Println("System tray menu tapped")
w.Show()
})
h.Icon = theme.SettingsIcon()
menu := fyne.NewMenu("Settings", h)
desk.SetSystemTrayMenu(menu)
}
}
func main() {
utils.DisableAnime()
defer utils.HandleCrash()
a := app.NewWithID("com.jackbillstrom.go-anime-matrix-io")
a.SetIcon(utils.AppIcon(IconFile))
//logLifecycle(a)
w := a.NewWindow("Go Anime Matrix")
_ = w
makeTray(a, w)
//w.SetMainMenu(makeMenu(a, w))
w.SetMaster()
// Set the window close intercept to hide the window instead of exiting the app
w.SetCloseIntercept(func() {
w.Hide()
})
content := container.NewMax()
title := widget.NewLabel("")
intro := widget.NewLabel("")
intro.Wrapping = fyne.TextWrapWord
setTutorial := func(t gui.Screen) {
title.SetText(t.Title)
intro.SetText(t.Intro)
content.Objects = []fyne.CanvasObject{t.View(w)}
content.Refresh()
}
tutorial := container.NewBorder(
container.NewVBox(title, widget.NewSeparator(), intro), nil, nil, nil, content)
if fyne.CurrentDevice().IsMobile() {
w.SetContent(makeNav(setTutorial, false))
} else {
split := container.NewHSplit(makeNav(setTutorial, true), tutorial)
split.Offset = 0.2
w.SetContent(split)
}
w.Resize(fyne.NewSize(640, 460))
w.ShowAndRun()
}
// makeNav creates the navigation tree for the application list menu
func makeNav(setTutorial func(tutorial gui.Screen), loadPrevious bool) fyne.CanvasObject {
a := fyne.CurrentApp()
tree := &widget.Tree{
ChildUIDs: func(uid string) []string {
return gui.ScreenIndex[uid]
},
IsBranch: func(uid string) bool {
children, ok := gui.ScreenIndex[uid]
return ok && len(children) > 0
},
CreateNode: func(branch bool) fyne.CanvasObject {
return widget.NewLabel("")
},
UpdateNode: func(uid string, branch bool, obj fyne.CanvasObject) {
t, ok := gui.Screens[uid]
if !ok {
fyne.LogError("Missing panel: "+uid, nil)
return
}
obj.(*widget.Label).SetText(t.Title)
obj.(*widget.Label).TextStyle = fyne.TextStyle{}
},
OnSelected: func(uid string) {
if t, ok := gui.Screens[uid]; ok {
a.Preferences().SetString(initialScreen, uid)
setTutorial(t)
}
},
}
if loadPrevious {
currentPref := a.Preferences().StringWithFallback(initialScreen, "welcome")
tree.Select(currentPref)
}
return container.NewBorder(nil, nil, nil, nil, tree)
}