Repository navigation
Expand file tree
/
Copy pathapp.go
More file actions
102 lines (84 loc) · 2.03 KB
/
Copy pathapp.go
File metadata and controls
102 lines (84 loc) · 2.03 KB
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
package main
import (
"context"
"github.com/wailsapp/wails/v3/pkg/application"
)
const (
launcherWindowWidth = 760
launcherWindowHeight = 96
chatWindowWidth = 920
chatWindowHeight = 680
)
type AppService struct {
app *application.App
calendar *GoogleCalendarClient
ollama *OllamaClient
}
func NewAppService(app *application.App) *AppService {
return &AppService{}
}
func (s *AppService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
s.app = application.Get()
s.calendar = NewGoogleCalendarClient()
s.ollama = NewOllamaClient("llama3")
return nil
}
func (s *AppService) ServiceShutdown() error {
return nil
}
func (s *AppService) CalendarStatus() CalendarStatus {
return s.calendarClient().Status()
}
func (s *AppService) ConnectGoogleCalendar() CalendarStatus {
return s.calendarClient().Connect()
}
func (s *AppService) Chat(req ChatRequest) ChatResponse {
return s.assistant().Chat(req)
}
func (s *AppService) SetWindowMode(mode string) WindowModeResponse {
width, height := launcherWindowWidth, launcherWindowHeight
if mode == "chat" {
width, height = chatWindowWidth, chatWindowHeight
}
if w := firstWindow(s.app); w != nil {
w.SetSize(width, height)
w.Center()
w.Focus()
}
return WindowModeResponse{Mode: mode, Width: width, Height: height}
}
func (s *AppService) HideWindow() {
if w := firstWindow(s.app); w != nil {
w.Hide()
}
}
func (s *AppService) calendarClient() *GoogleCalendarClient {
if s.calendar == nil {
s.calendar = NewGoogleCalendarClient()
}
return s.calendar
}
func (s *AppService) assistant() *Assistant {
return &Assistant{
calendar: s.calendarClient(),
ollama: s.ollamaClient(),
}
}
func (s *AppService) ollamaClient() *OllamaClient {
if s.ollama == nil {
s.ollama = NewOllamaClient("llama3")
}
return s.ollama
}
func firstWindow(app *application.App) application.Window {
if app == nil {
app = application.Get()
}
if app == nil {
return nil
}
if all := app.Window.GetAll(); len(all) > 0 {
return all[0]
}
return nil
}