cleanup: Get rid of useless parameters to the base

Issue #6
create-reload-action
Lukasz Janyst 4 years ago
parent df0105cbfc
commit 8913cada80
No known key found for this signature in database
GPG Key ID: 32DE641041F17A9A
  1. 22
      cmd/peroxide/main.go
  2. 32
      pkg/app/base/base.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")

@ -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
}

Loading…
Cancel
Save