From e4f08f79c30b42e7dc57ce49d17652ab307ced59 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Thu, 18 Aug 2022 15:51:40 +0200 Subject: [PATCH] Other(refactor): Move Locations out of frontend --- internal/app/bridge/bridge.go | 1 - internal/bridge/bridge_locations.go | 13 +++++++++++++ internal/frontend/cli/frontend.go | 4 ---- internal/frontend/cli/system.go | 2 +- internal/frontend/frontend.go | 5 +---- internal/frontend/grpc/service.go | 4 ---- internal/frontend/grpc/service_methods.go | 6 +++--- internal/frontend/types/types.go | 4 ++++ 8 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 internal/bridge/bridge_locations.go diff --git a/internal/app/bridge/bridge.go b/internal/app/bridge/bridge.go index 70109a19..60caf166 100644 --- a/internal/app/bridge/bridge.go +++ b/internal/app/bridge/bridge.go @@ -158,7 +158,6 @@ func main(b *base.Base, c *cli.Context) error { //nolint:funlen frontendMode, !c.Bool(base.FlagNoWindow), b.CrashHandler, - b.Locations, b.Settings, b.Listener, b.Updater, diff --git a/internal/bridge/bridge_locations.go b/internal/bridge/bridge_locations.go new file mode 100644 index 00000000..1f67dbca --- /dev/null +++ b/internal/bridge/bridge_locations.go @@ -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") +} diff --git a/internal/frontend/cli/frontend.go b/internal/frontend/cli/frontend.go index 1105da98..448605ba 100644 --- a/internal/frontend/cli/frontend.go +++ b/internal/frontend/cli/frontend.go @@ -22,7 +22,6 @@ import ( "github.com/ProtonMail/proton-bridge/v2/internal/config/settings" "github.com/ProtonMail/proton-bridge/v2/internal/events" "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/pkg/listener" @@ -35,7 +34,6 @@ var log = logrus.WithField("pkg", "frontend/cli") //nolint:gochecknoglobals type frontendCLI struct { *ishell.Shell - locations *locations.Locations settings *settings.Settings eventListener listener.Listener updater types.Updater @@ -48,7 +46,6 @@ type frontendCLI struct { func New( //nolint:funlen panicHandler types.PanicHandler, - locations *locations.Locations, settings *settings.Settings, eventListener listener.Listener, updater types.Updater, @@ -58,7 +55,6 @@ func New( //nolint:funlen fe := &frontendCLI{ Shell: ishell.New(), - locations: locations, settings: settings, eventListener: eventListener, updater: updater, diff --git a/internal/frontend/cli/system.go b/internal/frontend/cli/system.go index a25b994c..b7658e78 100644 --- a/internal/frontend/cli/system.go +++ b/internal/frontend/cli/system.go @@ -39,7 +39,7 @@ func (f *frontendCLI) restart(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") } else { f.Println("Log files are stored in\n\n ", path) diff --git a/internal/frontend/frontend.go b/internal/frontend/frontend.go index 4b93dadb..555094da 100644 --- a/internal/frontend/frontend.go +++ b/internal/frontend/frontend.go @@ -25,7 +25,6 @@ import ( "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/types" - "github.com/ProtonMail/proton-bridge/v2/internal/locations" "github.com/ProtonMail/proton-bridge/v2/internal/updater" "github.com/ProtonMail/proton-bridge/v2/pkg/listener" ) @@ -44,7 +43,6 @@ func New( frontendType string, showWindowOnStart bool, panicHandler types.PanicHandler, - locations *locations.Locations, settings *settings.Settings, eventListener listener.Listener, updater types.Updater, @@ -59,7 +57,6 @@ func New( return grpc.NewService( showWindowOnStart, panicHandler, - locations, settings, eventListener, updater, @@ -72,13 +69,13 @@ func New( case "cli": return cli.New( panicHandler, - locations, settings, eventListener, updater, bridgeWrap, restarter, ) + default: return nil } diff --git a/internal/frontend/grpc/service.go b/internal/frontend/grpc/service.go index dc8facd8..1d530012 100644 --- a/internal/frontend/grpc/service.go +++ b/internal/frontend/grpc/service.go @@ -31,7 +31,6 @@ import ( "github.com/ProtonMail/proton-bridge/v2/internal/config/useragent" "github.com/ProtonMail/proton-bridge/v2/internal/events" "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/users" "github.com/ProtonMail/proton-bridge/v2/pkg/keychain" @@ -52,7 +51,6 @@ type Service struct { // nolint:structcheck eventStreamDoneCh chan struct{} panicHandler types.PanicHandler - locations *locations.Locations settings *settings.Settings eventListener listener.Listener updater types.Updater @@ -75,7 +73,6 @@ type Service struct { // nolint:structcheck func NewService( showOnStartup bool, panicHandler types.PanicHandler, - locations *locations.Locations, settings *settings.Settings, eventListener listener.Listener, updater types.Updater, @@ -88,7 +85,6 @@ func NewService( s := Service{ UnimplementedBridgeServer: UnimplementedBridgeServer{}, panicHandler: panicHandler, - locations: locations, settings: settings, eventListener: eventListener, updater: updater, diff --git a/internal/frontend/grpc/service_methods.go b/internal/frontend/grpc/service_methods.go index 062bb453..a6a80125 100644 --- a/internal/frontend/grpc/service_methods.go +++ b/internal/frontend/grpc/service_methods.go @@ -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) { s.log.Info("LogsPath") - path, err := s.locations.ProvideLogsPath() + path, err := s.bridge.ProvideLogsPath() if err != nil { s.log.WithError(err).Error("Cannot determine logs path") 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) { 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) { - 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) { diff --git a/internal/frontend/types/types.go b/internal/frontend/types/types.go index 58e9a7b4..d504e463 100644 --- a/internal/frontend/types/types.go +++ b/internal/frontend/types/types.go @@ -81,6 +81,10 @@ type Bridger interface { GetTLSConfig() (*tls.Config, error) + ProvideLogsPath() (string, error) + GetLicenseFilePath() string + GetDependencyLicensesLink() string + // -- old -- ReportBug(osType, osVersion, description, accountName, address, emailClient string, attachLogs bool) error