mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 08:06:59 +00:00
GODT-1815: Focus service docs
This commit is contained in:
@ -11,6 +11,8 @@ import (
|
|||||||
"google.golang.org/protobuf/types/known/emptypb"
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TryRaise tries to raise the application by dialing the focus service.
|
||||||
|
// It returns true if the service is running and the application was told to raise.
|
||||||
func TryRaise() bool {
|
func TryRaise() bool {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
@ -10,11 +10,13 @@ import (
|
|||||||
"google.golang.org/protobuf/types/known/emptypb"
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// Host is the local host to listen on.
|
||||||
Host = "127.0.0.1"
|
const Host = "127.0.0.1"
|
||||||
Port = 1042
|
|
||||||
)
|
|
||||||
|
|
||||||
|
// Port is the port to listen on.
|
||||||
|
var Port = 1042
|
||||||
|
|
||||||
|
// FocusService is a gRPC service that can be used to raise the application.
|
||||||
type FocusService struct {
|
type FocusService struct {
|
||||||
proto.UnimplementedFocusServer
|
proto.UnimplementedFocusServer
|
||||||
|
|
||||||
@ -23,6 +25,8 @@ type FocusService struct {
|
|||||||
raiseCh chan struct{}
|
raiseCh chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewService creates a new focus service.
|
||||||
|
// It listens on the local host and port 1042 (by default).
|
||||||
func NewService() (*FocusService, error) {
|
func NewService() (*FocusService, error) {
|
||||||
listener, err := net.Listen("tcp", net.JoinHostPort(Host, fmt.Sprint(Port)))
|
listener, err := net.Listen("tcp", net.JoinHostPort(Host, fmt.Sprint(Port)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -46,15 +50,18 @@ func NewService() (*FocusService, error) {
|
|||||||
return service, nil
|
return service, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Raise implements the gRPC FocusService interface; it raises the application.
|
||||||
func (service *FocusService) Raise(context.Context, *emptypb.Empty) (*emptypb.Empty, error) {
|
func (service *FocusService) Raise(context.Context, *emptypb.Empty) (*emptypb.Empty, error) {
|
||||||
service.raiseCh <- struct{}{}
|
service.raiseCh <- struct{}{}
|
||||||
return &emptypb.Empty{}, nil
|
return &emptypb.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRaiseCh returns a channel on which events are sent when the application should be raised.
|
||||||
func (service *FocusService) GetRaiseCh() <-chan struct{} {
|
func (service *FocusService) GetRaiseCh() <-chan struct{} {
|
||||||
return service.raiseCh
|
return service.raiseCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the service.
|
||||||
func (service *FocusService) Close() {
|
func (service *FocusService) Close() {
|
||||||
service.server.Stop()
|
service.server.Stop()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user