Other(refactor): Move Settings out of frontend

This commit is contained in:
James Houlahan
2022-08-22 12:32:55 +02:00
committed by Jakub
parent 310c6a1ccf
commit 0c7453684b
17 changed files with 178 additions and 129 deletions

View File

@ -66,13 +66,13 @@ func (f *frontendCLI) showAccountInfo(c *ishell.Context) {
func (f *frontendCLI) showAccountAddressInfo(user types.User, address string) {
smtpSecurity := "STARTTLS"
if f.settings.GetBool(settings.SMTPSSLKey) {
if f.bridge.GetBool(settings.SMTPSSLKey) {
smtpSecurity = "SSL"
}
f.Println(bold("Configuration for " + address))
f.Printf("IMAP Settings\nAddress: %s\nIMAP port: %d\nUsername: %s\nPassword: %s\nSecurity: %s\n",
bridge.Host,
f.settings.GetInt(settings.IMAPPortKey),
f.bridge.GetInt(settings.IMAPPortKey),
address,
user.GetBridgePassword(),
"STARTTLS",
@ -80,7 +80,7 @@ func (f *frontendCLI) showAccountAddressInfo(user types.User, address string) {
f.Println("")
f.Printf("SMTP Settings\nAddress: %s\nSMTP port: %d\nUsername: %s\nPassword: %s\nSecurity: %s\n",
bridge.Host,
f.settings.GetInt(settings.SMTPPortKey),
f.bridge.GetInt(settings.SMTPPortKey),
address,
user.GetBridgePassword(),
smtpSecurity,

View File

@ -19,7 +19,6 @@
package cli
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/updater"
@ -34,7 +33,6 @@ var log = logrus.WithField("pkg", "frontend/cli") //nolint:gochecknoglobals
type frontendCLI struct {
*ishell.Shell
settings *settings.Settings
eventListener listener.Listener
updater types.Updater
bridge types.Bridger
@ -46,7 +44,6 @@ type frontendCLI struct {
func New( //nolint:funlen
panicHandler types.PanicHandler,
settings *settings.Settings,
eventListener listener.Listener,
updater types.Updater,
bridge types.Bridger,
@ -55,7 +52,6 @@ func New( //nolint:funlen
fe := &frontendCLI{
Shell: ishell.New(),
settings: settings,
eventListener: eventListener,
updater: updater,
bridge: bridge,

View File

@ -75,7 +75,7 @@ func (f *frontendCLI) changeSMTPSecurity(c *ishell.Context) {
f.ShowPrompt(false)
defer f.ShowPrompt(true)
isSSL := f.settings.GetBool(settings.SMTPSSLKey)
isSSL := f.bridge.GetBool(settings.SMTPSSLKey)
newSecurity := "SSL"
if isSSL {
newSecurity = "STARTTLS"
@ -84,7 +84,7 @@ func (f *frontendCLI) changeSMTPSecurity(c *ishell.Context) {
msg := fmt.Sprintf("Are you sure you want to change SMTP setting to %q and restart the Bridge", newSecurity)
if f.yesNoQuestion(msg) {
f.settings.SetBool(settings.SMTPSSLKey, !isSSL)
f.bridge.SetBool(settings.SMTPSSLKey, !isSSL)
f.Println("Restarting Bridge...")
f.restarter.SetToRestart()
f.Stop()
@ -95,14 +95,14 @@ func (f *frontendCLI) changePort(c *ishell.Context) {
f.ShowPrompt(false)
defer f.ShowPrompt(true)
currentPort = f.settings.Get(settings.IMAPPortKey)
currentPort = f.bridge.Get(settings.IMAPPortKey)
newIMAPPort := f.readStringInAttempts("Set IMAP port (current "+currentPort+")", c.ReadLine, f.isPortFree)
if newIMAPPort == "" {
newIMAPPort = currentPort
}
imapPortChanged := newIMAPPort != currentPort
currentPort = f.settings.Get(settings.SMTPPortKey)
currentPort = f.bridge.Get(settings.SMTPPortKey)
newSMTPPort := f.readStringInAttempts("Set SMTP port (current "+currentPort+")", c.ReadLine, f.isPortFree)
if newSMTPPort == "" {
newSMTPPort = currentPort
@ -116,8 +116,8 @@ func (f *frontendCLI) changePort(c *ishell.Context) {
if imapPortChanged || smtpPortChanged {
f.Println("Saving values IMAP:", newIMAPPort, "SMTP:", newSMTPPort)
f.settings.Set(settings.IMAPPortKey, newIMAPPort)
f.settings.Set(settings.SMTPPortKey, newSMTPPort)
f.bridge.Set(settings.IMAPPortKey, newIMAPPort)
f.bridge.Set(settings.SMTPPortKey, newSMTPPort)
f.Println("Restarting Bridge...")
f.restarter.SetToRestart()
f.Stop()
@ -179,7 +179,7 @@ func (f *frontendCLI) showAllMail(c *ishell.Context) {
}
func (f *frontendCLI) enableCacheOnDisk(c *ishell.Context) {
if f.settings.GetBool(settings.CacheEnabledKey) {
if f.bridge.GetBool(settings.CacheEnabledKey) {
f.Println("The local cache is already enabled.")
return
}
@ -196,7 +196,7 @@ func (f *frontendCLI) enableCacheOnDisk(c *ishell.Context) {
}
func (f *frontendCLI) disableCacheOnDisk(c *ishell.Context) {
if !f.settings.GetBool(settings.CacheEnabledKey) {
if !f.bridge.GetBool(settings.CacheEnabledKey) {
f.Println("The local cache is already disabled.")
return
}
@ -213,17 +213,17 @@ func (f *frontendCLI) disableCacheOnDisk(c *ishell.Context) {
}
func (f *frontendCLI) setCacheOnDiskLocation(c *ishell.Context) {
if !f.settings.GetBool(settings.CacheEnabledKey) {
if !f.bridge.GetBool(settings.CacheEnabledKey) {
f.Println("The local cache must be enabled.")
return
}
if location := f.settings.Get(settings.CacheLocationKey); location != "" {
if location := f.bridge.Get(settings.CacheLocationKey); location != "" {
f.Println("The current local cache location is:", location)
}
if location := f.readStringInAttempts("Enter a new location for the cache", c.ReadLine, f.isCacheLocationUsable); location != "" {
if err := f.bridge.MigrateCache(f.settings.Get(settings.CacheLocationKey), location); err != nil {
if err := f.bridge.MigrateCache(f.bridge.Get(settings.CacheLocationKey), location); err != nil {
f.Println("The local cache location could not be changed.")
return
}

View File

@ -47,7 +47,7 @@ func (f *frontendCLI) printCredits(c *ishell.Context) {
}
func (f *frontendCLI) enableAutoUpdates(c *ishell.Context) {
if f.settings.GetBool(settings.AutoUpdateKey) {
if f.bridge.GetBool(settings.AutoUpdateKey) {
f.Println("Bridge is already set to automatically install updates.")
return
}
@ -55,12 +55,12 @@ func (f *frontendCLI) enableAutoUpdates(c *ishell.Context) {
f.Println("Bridge is currently set to NOT automatically install updates.")
if f.yesNoQuestion("Are you sure you want to allow bridge to do this") {
f.settings.SetBool(settings.AutoUpdateKey, true)
f.bridge.SetBool(settings.AutoUpdateKey, true)
}
}
func (f *frontendCLI) disableAutoUpdates(c *ishell.Context) {
if !f.settings.GetBool(settings.AutoUpdateKey) {
if !f.bridge.GetBool(settings.AutoUpdateKey) {
f.Println("Bridge is already set to NOT automatically install updates.")
return
}
@ -68,7 +68,7 @@ func (f *frontendCLI) disableAutoUpdates(c *ishell.Context) {
f.Println("Bridge is currently set to automatically install updates.")
if f.yesNoQuestion("Are you sure you want to stop bridge from doing this") {
f.settings.SetBool(settings.AutoUpdateKey, false)
f.bridge.SetBool(settings.AutoUpdateKey, false)
}
}