-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (79 loc) · 2.25 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
package main
import (
"log/slog"
"os"
"os/signal"
"runtime"
"syscall"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/x/fyne/theme"
ollamaApi "github.com/ollama/ollama/api"
"github.com/bahelit/ctrl_plus_revise/internal/config"
"github.com/bahelit/ctrl_plus_revise/internal/gui/loading"
"github.com/bahelit/ctrl_plus_revise/internal/gui/settings"
"github.com/bahelit/ctrl_plus_revise/internal/gui/shortcuts"
"github.com/bahelit/ctrl_plus_revise/internal/hardware"
"github.com/bahelit/ctrl_plus_revise/internal/ollama"
"github.com/bahelit/ctrl_plus_revise/version"
)
var (
guiApp fyne.App
stopOllamaOnShutDown = false
)
func main() {
slog.Info("Starting Ctr+Revise gui Service...", "Version", version.Version, "Compiler", runtime.Version())
guiApp = app.NewWithID("com.ctrlplusrevise.app")
guiApp.Settings().SetTheme(theme.AdwaitaTheme())
loadIcon(guiApp)
var ollamaClient *ollamaApi.Client
ollamaClient = ollama.CheckOllamaConnection(guiApp, ollamaClient, nil)
// Prepare the loading screen and system tray
startupWindow := loading.StartupScreen(guiApp)
sysTray := SetupSysTray(guiApp, ollamaClient)
if guiApp.Preferences().BoolWithFallback(config.ShowStartWindowKey, true) {
slog.Debug("Hiding start window")
sysTray.Show()
startupWindow.Show()
}
// Start the services
hardware.DetectProcessingDevice()
hardware.DetectMemory()
go func() {
if ollamaClient == nil {
ollamaClient = settings.SetupServices(guiApp, ollamaClient)
if ollamaClient == nil {
slog.Error("Failed to connect to Ollama")
ollama.InstallOrUpdateOllamaWindow(guiApp, ollamaClient)
}
}
fetchModel(ollamaClient)
time.Sleep(1 * time.Second)
startupWindow.Close()
}()
//sayHello()
// Listen for global hotkeys
setKeyboardShortcuts()
go func() {
shortcuts.StartKeyboardListener(guiApp, ollamaClient)
}()
// Handle shutdown signals
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
<-c
slog.Info("Received shutdown signal")
handleShutdown(nil)
os.Exit(0)
}()
defer func() {
slog.Info("Shutting down")
signal.Stop(c)
close(c)
handleShutdown(nil)
}()
slog.Info("Ctrl+Revise is ready to help you!")
// Run the gui event loop
guiApp.Run()
}