-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.go
110 lines (93 loc) · 2.56 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
107
108
109
110
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"
"libdb.so/dissent/internal/gtkcord"
"libdb.so/dissent/internal/window"
"libdb.so/dissent/internal/window/about"
_ "github.com/diamondburned/gotkit/gtkutil/aggressivegc"
_ "libdb.so/dissent/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;
}
avatar > image {
background: none;
}
avatar > label {
background: @borders;
}
.md-textblock {
line-height: 1.35em;
}
`)
func init() {
app.Hook(func(*app.Application) {
adw.Init()
adaptive.Init()
})
}
func main() {
m := manager{}
m.app = app.New(context.Background(), "so.libdb.dissent", "Dissent")
m.app.AddJSONActions(map[string]interface{}{
"app.preferences": func() { prefui.ShowDialog(m.win.Context()) },
"app.about": func() { about.New(m.win.Context()).Present(m.win) },
"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) {
if m.win != nil {
m.win.Present()
return
}
m.win = window.NewWindow(ctx)
m.win.Present()
prefs.AsyncLoadSaved(ctx, func(err error) {
if err != nil {
app.Error(ctx, err)
}
})
}