forked from diamondburned/dissent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
102 lines (86 loc) · 2.54 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
package main
import (
"context"
"embed"
"io/fs"
"github.com/diamondburned/adaptive"
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
"github.com/diamondburned/gotk4/pkg/glib/v2"
"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"
"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)
}
// Version is connected to about.SetVersion.
var Version string
func init() { about.SetVersion(Version) }
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.preferences": func() { prefui.ShowDialog(m.win.Context()) },
"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.AddActionCallbacks(map[string]gtkutil.ActionCallback{
"app.open-channel": m.forwardSignalToWindow("open-channel", gtkcord.SnowflakeVariant),
"app.open-guild": m.forwardSignalToWindow("open-guild", gtkcord.SnowflakeVariant),
})
m.app.AddActionShortcuts(map[string]string{
"<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) forwardSignalToWindow(name string, t *glib.VariantType) gtkutil.ActionCallback {
return gtkutil.ActionCallback{
ArgType: t,
Func: func(args *glib.Variant) { m.win.ActivateAction(name, args) },
}
}
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)
}
})
}