forked from diamondburned/dissent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
106 lines (90 loc) · 2.36 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
package main
import (
"context"
"embed"
"io/fs"
"github.com/diamondburned/adaptive"
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
"github.com/diamondburned/gotkit/app"
"github.com/diamondburned/gotkit/app/locale"
"github.com/diamondburned/gotkit/app/prefs"
"github.com/diamondburned/gotkit/components/logui"
"github.com/diamondburned/gotkit/components/prefui"
"github.com/diamondburned/gotkit/gtkutil/cssutil"
"github.com/diamondburned/gtkcord4/internal/gtkcord"
"github.com/diamondburned/gtkcord4/internal/window"
"github.com/diamondburned/gtkcord4/internal/window/about"
_ "github.com/diamondburned/gotkit/gtkutil/aggressivegc"
_ "github.com/diamondburned/gtkcord4/internal/icons"
)
//go:embed po/*
var po embed.FS
func init() {
po, _ := fs.Sub(po, "po")
locale.LoadLocale(po)
}
var _ = cssutil.WriteCSS(`
window.background,
window.background.solid-csd {
background-color: @theme_bg_color;
}
.adaptive-avatar > image {
background: none;
}
.adaptive-avatar > label {
background: @borders;
}
`)
func main() {
m := manager{}
m.app = app.New(context.Background(), "so.libdb.gtkcord4", "gtkcord4")
m.app.AddJSONActions(map[string]interface{}{
"app.open-channel": m.openChannel,
"app.preferences": func() { prefui.ShowDialog(m.win.Context()) },
"app.show-qs": m.openQuickSwitcher,
"app.about": func() { about.New(m.win.Context()).Present() },
"app.logs": func() { logui.ShowDefaultViewer(m.win.Context()) },
"app.quit": func() { m.app.Quit() },
})
m.app.AddActionShortcuts(map[string]string{
"<Ctrl>K": "app.show-qs",
"<Ctrl>Q": "app.quit",
})
m.app.ConnectActivate(func() { m.activate(m.app.Context()) })
m.app.RunMain()
}
type manager struct {
app *app.Application
win *window.Window
}
func (m *manager) isLoggedIn() bool {
return m.win != nil && m.win.Chat != nil
}
func (m *manager) openQuickSwitcher() {
if !m.isLoggedIn() {
return
}
m.win.Chat.ShowQuickSwitcher()
}
func (m *manager) openChannel(cmd gtkcord.OpenChannelCommand) {
if !m.isLoggedIn() {
return
}
// TODO: highlight message.
m.win.Chat.OpenChannel(cmd.ChannelID)
}
func (m *manager) activate(ctx context.Context) {
adw.Init()
adaptive.Init()
if m.win != nil {
m.win.Present()
return
}
m.win = window.NewWindow(ctx)
m.win.Show()
prefs.AsyncLoadSaved(ctx, func(err error) {
if err != nil {
app.Error(ctx, err)
}
})
}