Other(refactor): Move Locations out of frontend

This commit is contained in:
James Houlahan
2022-08-18 15:51:40 +02:00
committed by Jakub
parent 2aaec3b6bd
commit e4f08f79c3
8 changed files with 22 additions and 17 deletions

View File

@ -158,7 +158,6 @@ func main(b *base.Base, c *cli.Context) error { //nolint:funlen
frontendMode, frontendMode,
!c.Bool(base.FlagNoWindow), !c.Bool(base.FlagNoWindow),
b.CrashHandler, b.CrashHandler,
b.Locations,
b.Settings, b.Settings,
b.Listener, b.Listener,
b.Updater, b.Updater,

View File

@ -0,0 +1,13 @@
package bridge
func (bridge *Bridge) ProvideLogsPath() (string, error) {
panic("TODO")
}
func (bridge *Bridge) GetLicenseFilePath() string {
panic("TODO")
}
func (bridge *Bridge) GetDependencyLicensesLink() string {
panic("TODO")
}

View File

@ -22,7 +22,6 @@ import (
"github.com/ProtonMail/proton-bridge/v2/internal/config/settings" "github.com/ProtonMail/proton-bridge/v2/internal/config/settings"
"github.com/ProtonMail/proton-bridge/v2/internal/events" "github.com/ProtonMail/proton-bridge/v2/internal/events"
"github.com/ProtonMail/proton-bridge/v2/internal/frontend/types" "github.com/ProtonMail/proton-bridge/v2/internal/frontend/types"
"github.com/ProtonMail/proton-bridge/v2/internal/locations"
"github.com/ProtonMail/proton-bridge/v2/internal/updater" "github.com/ProtonMail/proton-bridge/v2/internal/updater"
"github.com/ProtonMail/proton-bridge/v2/pkg/listener" "github.com/ProtonMail/proton-bridge/v2/pkg/listener"
@ -35,7 +34,6 @@ var log = logrus.WithField("pkg", "frontend/cli") //nolint:gochecknoglobals
type frontendCLI struct { type frontendCLI struct {
*ishell.Shell *ishell.Shell
locations *locations.Locations
settings *settings.Settings settings *settings.Settings
eventListener listener.Listener eventListener listener.Listener
updater types.Updater updater types.Updater
@ -48,7 +46,6 @@ type frontendCLI struct {
func New( //nolint:funlen func New( //nolint:funlen
panicHandler types.PanicHandler, panicHandler types.PanicHandler,
locations *locations.Locations,
settings *settings.Settings, settings *settings.Settings,
eventListener listener.Listener, eventListener listener.Listener,
updater types.Updater, updater types.Updater,
@ -58,7 +55,6 @@ func New( //nolint:funlen
fe := &frontendCLI{ fe := &frontendCLI{
Shell: ishell.New(), Shell: ishell.New(),
locations: locations,
settings: settings, settings: settings,
eventListener: eventListener, eventListener: eventListener,
updater: updater, updater: updater,

View File

@ -39,7 +39,7 @@ func (f *frontendCLI) restart(c *ishell.Context) {
} }
func (f *frontendCLI) printLogDir(c *ishell.Context) { func (f *frontendCLI) printLogDir(c *ishell.Context) {
if path, err := f.locations.ProvideLogsPath(); err != nil { if path, err := f.bridge.ProvideLogsPath(); err != nil {
f.Println("Failed to determine location of log files") f.Println("Failed to determine location of log files")
} else { } else {
f.Println("Log files are stored in\n\n ", path) f.Println("Log files are stored in\n\n ", path)

View File

@ -25,7 +25,6 @@ import (
"github.com/ProtonMail/proton-bridge/v2/internal/frontend/cli" "github.com/ProtonMail/proton-bridge/v2/internal/frontend/cli"
"github.com/ProtonMail/proton-bridge/v2/internal/frontend/grpc" "github.com/ProtonMail/proton-bridge/v2/internal/frontend/grpc"
"github.com/ProtonMail/proton-bridge/v2/internal/frontend/types" "github.com/ProtonMail/proton-bridge/v2/internal/frontend/types"
"github.com/ProtonMail/proton-bridge/v2/internal/locations"
"github.com/ProtonMail/proton-bridge/v2/internal/updater" "github.com/ProtonMail/proton-bridge/v2/internal/updater"
"github.com/ProtonMail/proton-bridge/v2/pkg/listener" "github.com/ProtonMail/proton-bridge/v2/pkg/listener"
) )
@ -44,7 +43,6 @@ func New(
frontendType string, frontendType string,
showWindowOnStart bool, showWindowOnStart bool,
panicHandler types.PanicHandler, panicHandler types.PanicHandler,
locations *locations.Locations,
settings *settings.Settings, settings *settings.Settings,
eventListener listener.Listener, eventListener listener.Listener,
updater types.Updater, updater types.Updater,
@ -59,7 +57,6 @@ func New(
return grpc.NewService( return grpc.NewService(
showWindowOnStart, showWindowOnStart,
panicHandler, panicHandler,
locations,
settings, settings,
eventListener, eventListener,
updater, updater,
@ -72,13 +69,13 @@ func New(
case "cli": case "cli":
return cli.New( return cli.New(
panicHandler, panicHandler,
locations,
settings, settings,
eventListener, eventListener,
updater, updater,
bridgeWrap, bridgeWrap,
restarter, restarter,
) )
default: default:
return nil return nil
} }

View File

@ -31,7 +31,6 @@ import (
"github.com/ProtonMail/proton-bridge/v2/internal/config/useragent" "github.com/ProtonMail/proton-bridge/v2/internal/config/useragent"
"github.com/ProtonMail/proton-bridge/v2/internal/events" "github.com/ProtonMail/proton-bridge/v2/internal/events"
"github.com/ProtonMail/proton-bridge/v2/internal/frontend/types" "github.com/ProtonMail/proton-bridge/v2/internal/frontend/types"
"github.com/ProtonMail/proton-bridge/v2/internal/locations"
"github.com/ProtonMail/proton-bridge/v2/internal/updater" "github.com/ProtonMail/proton-bridge/v2/internal/updater"
"github.com/ProtonMail/proton-bridge/v2/internal/users" "github.com/ProtonMail/proton-bridge/v2/internal/users"
"github.com/ProtonMail/proton-bridge/v2/pkg/keychain" "github.com/ProtonMail/proton-bridge/v2/pkg/keychain"
@ -52,7 +51,6 @@ type Service struct { // nolint:structcheck
eventStreamDoneCh chan struct{} eventStreamDoneCh chan struct{}
panicHandler types.PanicHandler panicHandler types.PanicHandler
locations *locations.Locations
settings *settings.Settings settings *settings.Settings
eventListener listener.Listener eventListener listener.Listener
updater types.Updater updater types.Updater
@ -75,7 +73,6 @@ type Service struct { // nolint:structcheck
func NewService( func NewService(
showOnStartup bool, showOnStartup bool,
panicHandler types.PanicHandler, panicHandler types.PanicHandler,
locations *locations.Locations,
settings *settings.Settings, settings *settings.Settings,
eventListener listener.Listener, eventListener listener.Listener,
updater types.Updater, updater types.Updater,
@ -88,7 +85,6 @@ func NewService(
s := Service{ s := Service{
UnimplementedBridgeServer: UnimplementedBridgeServer{}, UnimplementedBridgeServer: UnimplementedBridgeServer{},
panicHandler: panicHandler, panicHandler: panicHandler,
locations: locations,
settings: settings, settings: settings,
eventListener: eventListener, eventListener: eventListener,
updater: updater, updater: updater,

View File

@ -205,7 +205,7 @@ func (s *Service) Version(context.Context, *emptypb.Empty) (*wrapperspb.StringVa
func (s *Service) LogsPath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { func (s *Service) LogsPath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) {
s.log.Info("LogsPath") s.log.Info("LogsPath")
path, err := s.locations.ProvideLogsPath() path, err := s.bridge.ProvideLogsPath()
if err != nil { if err != nil {
s.log.WithError(err).Error("Cannot determine logs path") s.log.WithError(err).Error("Cannot determine logs path")
return nil, err return nil, err
@ -215,11 +215,11 @@ func (s *Service) LogsPath(context.Context, *emptypb.Empty) (*wrapperspb.StringV
func (s *Service) LicensePath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { func (s *Service) LicensePath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) {
s.log.Info("LicensePath") s.log.Info("LicensePath")
return wrapperspb.String(s.locations.GetLicenseFilePath()), nil return wrapperspb.String(s.bridge.GetLicenseFilePath()), nil
} }
func (s *Service) DependencyLicensesLink(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { func (s *Service) DependencyLicensesLink(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) {
return wrapperspb.String(s.locations.GetDependencyLicensesLink()), nil return wrapperspb.String(s.bridge.GetDependencyLicensesLink()), nil
} }
func (s *Service) ReleaseNotesPageLink(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) { func (s *Service) ReleaseNotesPageLink(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) {

View File

@ -81,6 +81,10 @@ type Bridger interface {
GetTLSConfig() (*tls.Config, error) GetTLSConfig() (*tls.Config, error)
ProvideLogsPath() (string, error)
GetLicenseFilePath() string
GetDependencyLicensesLink() string
// -- old -- // -- old --
ReportBug(osType, osVersion, description, accountName, address, emailClient string, attachLogs bool) error ReportBug(osType, osVersion, description, accountName, address, emailClient string, attachLogs bool) error