-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
197 lines (173 loc) · 4.55 KB
/
app.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package main
import (
"context"
_ "embed"
"fmt"
"io/ioutil"
"github.com/KnockOutEZ/Kodee/backend/healthReminder"
"github.com/KnockOutEZ/Kodee/backend/server"
"github.com/KnockOutEZ/Kodee/backend/systemUsage"
"github.com/KnockOutEZ/Kodee/backend/utils"
"github.com/KnockOutEZ/Kodee/backend/weatherApi"
"github.com/KnockOutEZ/Kodee/backend/windowControl"
// "github.com/getlantern/systray"
"fyne.io/systray"
"github.com/sadlil/go-avro-phonetic"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
var myCtx context.Context
//go:embed frontend/src/assets/wails.ico
var logoICO []byte
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called at application startup
func (a *App) startup(ctx context.Context) {
// Perform your setup here
a.ctx = ctx
systray.Run(onReady, onExit)
}
// domReady is called after front-end resources have been loaded
func (a *App) domReady(ctx context.Context) {
// Add your action here
myCtx = ctx
utils.CopyIconInStartup()
ConvertBanglishToBangla("ki obostha korechi")
// server.TestAuth()
server.TestOut()
// call reminderFuncs here
go healthReminder.LookAwayReminder()
go healthReminder.StandUpReminder()
go healthReminder.HydrateReminder()
}
func ConvertBanglishToBangla(text string) string {
// Parse() tries to parse the given string
// In case of failure it returns an erros
text, err := avro.Parse("ami banglay gan gai")
if err != nil {
return err.Error()
}
fmt.Println(text) // আমি বাংলায় গান গাই
return text
}
func onReady() {
fmt.Println("onReady")
systray.SetIcon(logoICO)
systray.SetTitle("Kodee")
systray.SetTooltip("Kodee")
mOpen := systray.AddMenuItem("Open", "Open the app")
go func() {
for {
<-mOpen.ClickedCh
runtime.Show(myCtx)
}
}()
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
go func() {
<-mQuit.ClickedCh
systray.Quit()
runtime.Quit(myCtx)
}()
// Sets the icon of a menu item.
// mQuit.SetIcon(logoICO)
}
func onExit() {
// clean up here
}
func getIcon(s string) []byte {
b, err := ioutil.ReadFile(s)
utils.CheckErr(err)
return b
}
// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name)
}
// beforeClose is called when the application is about to quit,
// either by clicking the window close button or calling runtime.Quit.
// Returning true will cause the application to continue, false will continue shutdown as normal.
func (a *App) beforeClose(ctx context.Context) (prevent bool) {
// dialog, err := runtime.MessageDialog(ctx, runtime.MessageDialogOptions{
// Type: runtime.QuestionDialog,
// Title: "Quit?",
// Message: "Are you sure you want to quit?",
// })
// if err != nil {
return false
// }
// return dialog != "Yes"
}
// shutdown is called at application termination
func (a *App) shutdown(ctx context.Context) {
// Perform your teardown here
}
// Meet returns a greeting for the given name
func (a *App) Notification(title, message string) {
utils.NotificationFunc(title, message)
}
func (a *App) GetSystemUsage(usageType string) interface{} {
switch usageType {
case "cpu":
return systemUsage.GetCpuUsage()
case "ram":
return systemUsage.GetRamUsage()
case "bandwidth":
return systemUsage.GetBandwithSpeed()
default:
return nil
}
}
func (a *App) UseWindowControl(usageType string) interface{} {
switch usageType {
case "minimize":
if err := windowControl.Minimize(); err != nil {
return err
}
case "normalize":
if err := windowControl.Normalize(); err != nil {
return err
}
case "move":
if err := windowControl.Move(); err != nil {
return err
}
default:
return nil
}
return nil
}
func (a *App) Auth(usageType string, user server.User, jwt string) (interface{}, error) {
fmt.Println("Auth called", usageType, user, jwt)
switch usageType {
case "signup":
userData := &server.User{Username: user.Username, Email: user.Email, Password: user.Password}
res, err := server.SignUp(userData)
if err != nil {
return nil, err
}
return res, nil
case "signin":
userData := server.User{Username: user.Username, Password: user.Password}
res, err := server.Login(userData.Username, userData.Password)
if err != nil {
return nil, err
}
return res, nil
case "me":
res, err := server.Me(jwt)
if err != nil {
return nil, err
}
return res, nil
default:
return nil, nil
}
}
func (a *App) GetWeather() {
weatherApi.GetWeather()
}