GODT-1388: Refactor Alternative routing

This commit is contained in:
Alexander Bilyak
2021-10-27 16:14:18 +02:00
committed by Jakub
parent af0c5e6bae
commit 42ced6694e
6 changed files with 26 additions and 27 deletions

View File

@ -223,3 +223,19 @@ func (b *Bridge) MigrateCache(from, to string) error {
return nil return nil
} }
// SetProxyAllowed instructs the app whether to use DoH to access an API proxy if necessary.
// It also needs to work before the app is initialised (because we may need to use the proxy at startup).
func (b *Bridge) SetProxyAllowed(proxyAllowed bool) {
b.settings.SetBool(settings.AllowProxyKey, proxyAllowed)
if proxyAllowed {
b.clientManager.AllowProxy()
} else {
b.clientManager.DisallowProxy()
}
}
// GetProxyAllowed returns whether use of DoH is enabled to access an API proxy if necessary.
func (b *Bridge) GetProxyAllowed() bool {
return b.settings.GetBool(settings.AllowProxyKey)
}

View File

@ -129,7 +129,7 @@ func (f *frontendCLI) changePort(c *ishell.Context) {
} }
func (f *frontendCLI) allowProxy(c *ishell.Context) { func (f *frontendCLI) allowProxy(c *ishell.Context) {
if f.settings.GetBool(settings.AllowProxyKey) { if f.bridge.GetProxyAllowed() {
f.Println("Bridge is already set to use alternative routing to connect to Proton if it is being blocked.") f.Println("Bridge is already set to use alternative routing to connect to Proton if it is being blocked.")
return return
} }
@ -137,13 +137,12 @@ func (f *frontendCLI) allowProxy(c *ishell.Context) {
f.Println("Bridge is currently set to NOT use alternative routing to connect to Proton if it is being blocked.") f.Println("Bridge is currently set to NOT use alternative routing to connect to Proton if it is being blocked.")
if f.yesNoQuestion("Are you sure you want to allow bridge to do this") { if f.yesNoQuestion("Are you sure you want to allow bridge to do this") {
f.settings.SetBool(settings.AllowProxyKey, true) f.bridge.SetProxyAllowed(true)
f.bridge.AllowProxy()
} }
} }
func (f *frontendCLI) disallowProxy(c *ishell.Context) { func (f *frontendCLI) disallowProxy(c *ishell.Context) {
if !f.settings.GetBool(settings.AllowProxyKey) { if !f.bridge.GetProxyAllowed() {
f.Println("Bridge is already set to NOT use alternative routing to connect to Proton if it is being blocked.") f.Println("Bridge is already set to NOT use alternative routing to connect to Proton if it is being blocked.")
return return
} }
@ -151,8 +150,7 @@ func (f *frontendCLI) disallowProxy(c *ishell.Context) {
f.Println("Bridge is currently set to use alternative routing to connect to Proton if it is being blocked.") f.Println("Bridge is currently set to use alternative routing to connect to Proton if it is being blocked.")
if f.yesNoQuestion("Are you sure you want to stop bridge from doing this") { if f.yesNoQuestion("Are you sure you want to stop bridge from doing this") {
f.settings.SetBool(settings.AllowProxyKey, false) f.bridge.SetProxyAllowed(false)
f.bridge.DisallowProxy()
} }
} }

View File

@ -99,12 +99,8 @@ func (f *FrontendQt) toggleAutostart(makeItEnabled bool) {
} }
func (f *FrontendQt) toggleDoH(makeItEnabled bool) { func (f *FrontendQt) toggleDoH(makeItEnabled bool) {
if f.settings.GetBool(settings.AllowProxyKey) == makeItEnabled { f.bridge.SetProxyAllowed(makeItEnabled)
f.qml.SetIsDoHEnabled(makeItEnabled) f.qml.SetIsDoHEnabled(f.bridge.GetProxyAllowed())
return
}
f.settings.SetBool(settings.AllowProxyKey, makeItEnabled)
f.restart()
} }
func (f *FrontendQt) toggleUseSSLforSMTP(makeItEnabled bool) { func (f *FrontendQt) toggleUseSSLforSMTP(makeItEnabled bool) {

View File

@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>. // along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
//go:build build_qt
// +build build_qt // +build build_qt
package qt package qt
@ -232,7 +233,7 @@ func (q *QMLBackend) setup(f *FrontendQt) {
}() }()
}) })
q.SetIsDoHEnabled(f.settings.GetBool(settings.AllowProxyKey)) q.SetIsDoHEnabled(f.bridge.GetProxyAllowed())
q.ConnectToggleDoH(f.toggleDoH) q.ConnectToggleDoH(f.toggleDoH)
q.SetUseSSLforSMTP(f.settings.GetBool(settings.SMTPSSLKey)) q.SetUseSSLforSMTP(f.settings.GetBool(settings.SMTPSSLKey))

View File

@ -75,8 +75,8 @@ type Bridger interface {
UserManager UserManager
ReportBug(osType, osVersion, description, accountName, address, emailClient string, attachLogs bool) error ReportBug(osType, osVersion, description, accountName, address, emailClient string, attachLogs bool) error
AllowProxy() SetProxyAllowed(bool)
DisallowProxy() GetProxyAllowed() bool
EnableCache() error EnableCache() error
DisableCache() error DisableCache() error
MigrateCache(from, to string) error MigrateCache(from, to string) error

View File

@ -419,18 +419,6 @@ func (u *Users) SendMetric(m metrics.Metric) error {
return nil return nil
} }
// AllowProxy instructs the app to use DoH to access an API proxy if necessary.
// It also needs to work before the app is initialised (because we may need to use the proxy at startup).
func (u *Users) AllowProxy() {
u.clientManager.AllowProxy()
}
// DisallowProxy instructs the app to not use DoH to access an API proxy if necessary.
// It also needs to work before the app is initialised (because we may need to use the proxy at startup).
func (u *Users) DisallowProxy() {
u.clientManager.DisallowProxy()
}
// hasUser returns whether the struct currently has a user with ID `id`. // hasUser returns whether the struct currently has a user with ID `id`.
func (u *Users) hasUser(id string) (user *User, ok bool) { func (u *Users) hasUser(id string) (user *User, ok bool) {
for _, u := range u.users { for _, u := range u.users {