From 8913cada80ecac5c7f7421c91db9ed2f1a6cf532 Mon Sep 17 00:00:00 2001 From: Lukasz Janyst Date: Fri, 7 Jan 2022 18:07:46 +0100 Subject: [PATCH] cleanup: Get rid of useless parameters to the base Issue #6 --- cmd/peroxide/main.go | 22 +--------------------- pkg/app/base/base.go | 32 +++++++------------------------- 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/cmd/peroxide/main.go b/cmd/peroxide/main.go index 63d41fe..deeb86f 100644 --- a/cmd/peroxide/main.go +++ b/cmd/peroxide/main.go @@ -40,31 +40,11 @@ import ( "github.com/sirupsen/logrus" ) -const ( - appName = "ProtonMail Bridge" - appUsage = "ProtonMail IMAP and SMTP Bridge" - configName = "bridge" - updateURLName = "bridge" - keychainName = "bridge" - cacheVersion = "c11" -) - func main() { - base, err := base.New( - appName, - appUsage, - configName, - updateURLName, - keychainName, - cacheVersion, - ) + base, err := base.New() if err != nil { logrus.WithError(err).Fatal("Failed to create app base") } - // Other instance already running. - if base == nil { - return - } if bridge.MailLoop(base); err != nil { logrus.WithError(err).Fatal("Bridge exited with error") diff --git a/pkg/app/base/base.go b/pkg/app/base/base.go index d572e90..4d70565 100644 --- a/pkg/app/base/base.go +++ b/pkg/app/base/base.go @@ -60,34 +60,20 @@ type Base struct { CookieJar *cookies.Jar UserAgent *useragent.UserAgent TLS *tls.TLS - - Name string // the app's name - usage string // the app's usage description - command string // the command used to launch the app (either the exe path or the launcher path) - restart bool // whether the app is currently set to restart - - teardown []func() error // actions to perform when app is exiting } -func New( // nolint[funlen] - appName, - appUsage, - configName, - updateURLName, - keychainName, - cacheVersion string, -) (*Base, error) { +func New() (*Base, error) { userAgent := useragent.New() rand.Seed(time.Now().UnixNano()) os.Args = StripProcessSerialNumber(os.Args) - locationsProvider, err := locations.NewDefaultProvider(filepath.Join(constants.VendorName, configName)) + locationsProvider, err := locations.NewDefaultProvider(filepath.Join("protonmail", "bridge")) if err != nil { return nil, err } - locations := locations.New(locationsProvider, configName) + locations := locations.New(locationsProvider, "bridge") logsPath, err := locations.ProvideLogsPath() if err != nil { @@ -97,7 +83,7 @@ func New( // nolint[funlen] return nil, err } - if err := migrateFiles(configName); err != nil { + if err := migrateFiles("bridge"); err != nil { logrus.WithError(err).Warn("Old config files could not be migrated") } @@ -115,7 +101,7 @@ func New( // nolint[funlen] if err != nil { return nil, err } - cache, err := cache.New(cachePath, cacheVersion) + cache, err := cache.New(cachePath, "c11") if err != nil { return nil, err } @@ -126,14 +112,12 @@ func New( // nolint[funlen] listener := listener.New() events.SetupEvents(listener) - // If we can't load the keychain for whatever reason, - // we signal to frontend and supply a dummy keychain that always returns errors. - kc, err := keychain.NewKeychain(settingsObj, keychainName) + kc, err := keychain.NewKeychain(settingsObj, "bridge") if err != nil { return nil, err } - cfg := pmapi.NewConfig(configName, constants.Version) + cfg := pmapi.NewConfig("bridge", constants.Version) cfg.GetUserAgent = userAgent.String cfg.UpgradeApplicationHandler = func() { listener.Emit(events.UpgradeApplicationEvent, "") } cfg.TLSIssueHandler = func() { listener.Emit(events.TLSCertIssue, "") } @@ -162,7 +146,5 @@ func New( // nolint[funlen] CookieJar: jar, UserAgent: userAgent, TLS: tls.New(settingsPath), - - Name: appName, }, nil }