-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
133 lines (118 loc) · 4.73 KB
/
Copy pathmain.go
File metadata and controls
133 lines (118 loc) · 4.73 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
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
// catdb — a cross-platform database management tool built on Wails v3.
//
// IMPORTANT: per CLAUDE.md #1, this file is the ONLY place outside
// wailsbridge/ that may import github.com/wailsapp/wails/v3/pkg/application
// directly. Everything else routes through wailsbridge.
package main
import (
"context"
"embed"
"log"
"runtime"
"github.com/wailsapp/wails/v3/pkg/application"
"catdb/internal/agent"
"catdb/internal/core/session"
"catdb/internal/llm"
"catdb/internal/llmconfig"
"catdb/internal/platform"
"catdb/internal/services"
"catdb/internal/storage"
_ "catdb/plugins"
"catdb/wailsbridge"
)
//go:embed all:frontend/dist
var assets embed.FS
func init() {
application.RegisterEvent[map[string]any]("transfer:progress")
application.RegisterEvent[map[string]any]("window:close-blocked")
application.RegisterEvent[map[string]any]("custom:switch-english-input")
application.RegisterEvent[map[string]any]("connection:saved")
application.RegisterEvent[map[string]any]("update:progress")
application.RegisterEvent[map[string]any]("agent:delta")
application.RegisterEvent[map[string]any]("agent:thinking")
application.RegisterEvent[map[string]any]("agent:tool")
application.RegisterEvent[map[string]any]("agent:usage")
application.RegisterEvent[map[string]any]("agent:done")
application.RegisterEvent[map[string]any]("agent:error")
application.RegisterEvent[map[string]any]("agent:approval")
application.RegisterEvent[map[string]any]("agent:plan")
application.RegisterEvent[map[string]any]("agent:tx-pending")
application.RegisterEvent[map[string]any]("agent:result")
}
func main() {
store, err := storage.Open("")
if err != nil {
log.Fatalf("storage: %v", err)
}
defer store.Close()
// Empty service name → storage's build-tag default ("catdb" / "catdb-dev"),
// keeping dev keyring entries separate from a production install.
secrets := storage.NewSecrets("")
mgr := session.NewManager(store, secrets)
defer mgr.CloseAll()
settingsSvc := services.NewSettingsService(store)
agentEngine := agent.NewEngine(store, mgr, func(ctx context.Context, providerID string) (llm.Provider, error) {
return llmconfig.Resolve(ctx, store, secrets, providerID)
})
agentSettingsSvc := services.NewAgentSettingsService(store, secrets)
// Audit housekeeping: drop entries older than the retention setting
// (default 15 days) once per launch, off the startup path.
go agentSettingsSvc.AutoCleanAudit(context.Background())
app := application.New(application.Options{
Name: "catdb",
Description: "Cross-platform database management tool",
Services: []application.Service{
application.NewService(services.NewConnectionService(store, secrets, mgr)),
application.NewService(services.NewQueryService(mgr)),
application.NewService(services.NewMetadataService(mgr)),
application.NewService(services.NewEditService(mgr)),
application.NewService(services.NewTransferService(mgr)),
application.NewService(services.NewSyncService(mgr)),
application.NewService(services.NewSystemService()),
application.NewService(services.NewSavedQueryService(store)),
application.NewService(services.NewUpdateService(store, "")),
application.NewService(settingsSvc),
application.NewService(agentSettingsSvc),
application.NewService(services.NewAgentService(store, agentEngine)),
application.NewService(services.NewAgentTraceService(store)),
},
Assets: application.AssetOptions{
Handler: application.AssetFileServerFS(assets),
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
})
wailsbridge.SetApp(app)
// Listen for front-end focus events on the SQL editor — switch to English
// input source on macOS so SQL typing starts in the correct layout.
app.Event.On("custom:switch-english-input", func(_ *application.CustomEvent) {
platform.SwitchToEnglishInputSource()
})
// Seed the native-menu locale from the persisted preference so the app
// menu + context menus render in the right language from the first frame.
if loc, err := settingsSvc.GetLocale(context.Background()); err == nil {
wailsbridge.InitMenuLocale(loc)
}
app.Menu.SetApplicationMenu(wailsbridge.BuildApplicationMenu(app))
wailsbridge.RegisterContextMenus(app)
win := app.Window.NewWithOptions(application.WebviewWindowOptions{
Title: "catdb",
Width: 1200,
Height: 760,
MinWidth: 600,
MinHeight: 500,
Frameless: runtime.GOOS == "windows",
Mac: application.MacWindow{
InvisibleTitleBarHeight: 30,
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInset,
},
BackgroundColour: application.NewRGB(245, 245, 247),
URL: "/",
})
wailsbridge.AttachCloseGuard(win)
if err := app.Run(); err != nil {
log.Fatal(err)
}
}