-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
126 lines (99 loc) · 2.32 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 (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
)
const (
PlaceholderImage = "https://bulma.io/images/placeholders/128x128.png"
KQBAvatarImage = "avatar.png"
)
type Team struct {
Name string
Img string
Div int
Tier int
Stats Stats
}
type Stats struct {
GamesWon int
GamesLost int
MatchesWon int
MatchesLost int
}
var h Team = Team{"Blue Team", PlaceholderImage, 1, 1, Stats{1, 1, 1, 1}}
var a Team = Team{"Gold Team", PlaceholderImage, 1, 1, Stats{1, 1, 1, 1}}
var s Scoreboard = Scoreboard{&h, &a, 0, 0, 0, 0, []ScoreboardSet{}}
var logoPath string
var themePath string
var themes []string
var selectedTheme string
var FyneApp fyne.App
func setupLogs() {
f, err := os.OpenFile("./scoreboard-output.log", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
fmt.Printf("error opening file: %v", err)
}
// don't forget to close it
// defer f.Close()
// assign it to the standard logger
log.SetOutput(f)
}
func main() {
// Configure log output to file
setupLogs()
// Create Directory For Logos
SetupLogoDirectory()
// Setup HTTP handler and websocket handler
StartHTTPServer()
// Create Fyne App
FyneApp = app.New()
FyneApp.SetIcon(resourceIconPng)
_ = GameType(FyneApp)
// Add Event Hotkey Bindings
go AddEventHotkeys()
FyneApp.Run()
// Called before application exist
tidyUp()
}
// SetupLogoDirectory creates a directory to cache the local logo files
func SetupLogoDirectory() {
// Get Current Working Directory
path, err := os.Getwd()
if err != nil {
log.Println(err)
}
fmt.Println(path)
// Set Logo Path
logoPath = filepath.Join(path, "logo")
fmt.Println(logoPath)
// Set Theme Path
themePath = filepath.Join(path, "themes")
// Create directory if it doesn't exist
if _, err := os.Stat(logoPath); os.IsNotExist(err) {
os.Mkdir(logoPath, 0755)
}
// Create directory if it doesn't exist
if _, err := os.Stat(themePath); os.IsNotExist(err) {
themePath = ""
}
files, err := ioutil.ReadDir(themePath)
if err != nil {
log.Println(err)
}
themes = append(themes, "default", "bgl")
for _, file := range files {
name := file.Name()
themes = append(themes, name)
}
}
func tidyUp() {
// Remove logopath directory and files
os.RemoveAll(logoPath)
os.Remove("./output.log")
log.Println("Exiting...")
}