-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.go
84 lines (72 loc) · 2.5 KB
/
interface.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
package panelplugin
import (
"context"
"time"
"github.com/hashicorp/go-plugin"
configv1 "github.com/pdf/hyprpanel/proto/hyprpanel/config/v1"
eventv1 "github.com/pdf/hyprpanel/proto/hyprpanel/event/v1"
hyprpanelv1 "github.com/pdf/hyprpanel/proto/hyprpanel/v1"
"google.golang.org/grpc"
)
// Compile-time check
var _ plugin.GRPCPlugin = &PanelPlugin{}
const (
// PanelPluginName constant.
PanelPluginName = `panel`
)
// Handshake default parameters.
var Handshake = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: `hyprpanel`,
MagicCookieValue: `panel`,
}
// PluginMap default parameters.
var PluginMap = map[string]plugin.Plugin{
PanelPluginName: &PanelPlugin{},
}
// Host interface.
type Host interface {
Exec(command string) error
FindApplication(query string) (*hyprpanelv1.AppInfo, error)
SystrayActivate(busName string, x, y int32) error
SystraySecondaryActivate(busName string, x, y int32) error
SystrayScroll(busName string, delta int32, orientation hyprpanelv1.SystrayScrollOrientation) error
SystrayMenuContextActivate(busName string, x, y int32) error
SystrayMenuAboutToShow(busName string, menuItemID string) error
SystrayMenuEvent(busName string, id int32, eventID hyprpanelv1.SystrayMenuEvent, data any, timestamp time.Time) error
NotificationClosed(id uint32, reason hyprpanelv1.NotificationClosedReason) error
NotificationAction(id uint32, actionKey string) error
AudioSinkVolumeAdjust(id string, direction eventv1.Direction) error
AudioSinkMuteToggle(id string) error
AudioSourceVolumeAdjust(id string, direction eventv1.Direction) error
AudioSourceMuteToggle(id string) error
BrightnessAdjust(devName string, direction eventv1.Direction) error
}
// Panel interface.
type Panel interface {
Init(host Host, id string, loglevel configv1.LogLevel, config *configv1.Panel, stylesheet []byte) error
Notify(evt *eventv1.Event)
Context() context.Context
Close()
}
// PanelPlugin definition.
type PanelPlugin struct {
plugin.NetRPCUnsupportedPlugin
Impl Panel
}
// GRPCServer satisfies the plugin interface.
func (p *PanelPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
hyprpanelv1.RegisterPanelServiceServer(s, &PanelGRPCServer{
Impl: p.Impl,
broker: broker,
})
return nil
}
// GRPCClient satsifise the plugin interface.
func (p *PanelPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &PanelGRPCClient{
client: hyprpanelv1.NewPanelServiceClient(c),
broker: broker,
ctx: ctx,
}, nil
}