mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
GODT-2213: Don't unnecessarily enable/disable autostart
This commit is contained in:
committed by
Romain Le Jeune
parent
3499fbd758
commit
e4b81063cb
@ -144,3 +144,17 @@ func (mr *MockAutostarterMockRecorder) Enable() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Enable", reflect.TypeOf((*MockAutostarter)(nil).Enable))
|
||||
}
|
||||
|
||||
// IsEnabled mocks base method.
|
||||
func (m *MockAutostarter) IsEnabled() bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "IsEnabled")
|
||||
ret0, _ := ret[0].(bool)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// IsEnabled indicates an expected call of IsEnabled.
|
||||
func (mr *MockAutostarterMockRecorder) IsEnabled() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsEnabled", reflect.TypeOf((*MockAutostarter)(nil).IsEnabled))
|
||||
}
|
||||
|
||||
@ -207,15 +207,24 @@ func (bridge *Bridge) GetAutostart() bool {
|
||||
}
|
||||
|
||||
func (bridge *Bridge) SetAutostart(autostart bool) error {
|
||||
if err := bridge.vault.SetAutostart(autostart); err != nil {
|
||||
return err
|
||||
if autostart != bridge.vault.GetAutostart() {
|
||||
if err := bridge.vault.SetAutostart(autostart); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if autostart {
|
||||
// do nothing if already enabled
|
||||
if bridge.autostarter.IsEnabled() {
|
||||
return nil
|
||||
}
|
||||
err = bridge.autostarter.Enable()
|
||||
} else {
|
||||
// do nothing if already disabled
|
||||
if !bridge.autostarter.IsEnabled() {
|
||||
return nil
|
||||
}
|
||||
err = bridge.autostarter.Disable()
|
||||
}
|
||||
|
||||
|
||||
@ -134,10 +134,19 @@ func TestBridge_Settings_Proxy(t *testing.T) {
|
||||
func TestBridge_Settings_Autostart(t *testing.T) {
|
||||
withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) {
|
||||
withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) {
|
||||
// By default, autostart is disabled.
|
||||
// By default, autostart is enabled.
|
||||
require.True(t, bridge.GetAutostart())
|
||||
|
||||
// Disable autostart.
|
||||
mocks.Autostarter.EXPECT().IsEnabled().Return(true)
|
||||
mocks.Autostarter.EXPECT().Disable().Return(nil)
|
||||
require.NoError(t, bridge.SetAutostart(false))
|
||||
|
||||
// Get the new setting.
|
||||
require.False(t, bridge.GetAutostart())
|
||||
|
||||
// Enable autostart.
|
||||
// Re Enable autostart.
|
||||
mocks.Autostarter.EXPECT().IsEnabled().Return(false)
|
||||
mocks.Autostarter.EXPECT().Enable().Return(nil)
|
||||
require.NoError(t, bridge.SetAutostart(true))
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ type TLSReporter interface {
|
||||
type Autostarter interface {
|
||||
Enable() error
|
||||
Disable() error
|
||||
IsEnabled() bool
|
||||
}
|
||||
|
||||
type Updater interface {
|
||||
|
||||
@ -191,9 +191,6 @@ func NewService(
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// GODT-1507 Windows: autostart needs to be created after Qt is initialized.
|
||||
// GODT-1206: if preferences file says it should be on enable it here.
|
||||
// TO-DO GODT-1681 Autostart needs to be properly implement for gRPC approach.
|
||||
func (s *Service) initAutostart() {
|
||||
s.firstTimeAutostart.Do(func() {
|
||||
shouldAutostartBeOn := s.bridge.GetAutostart()
|
||||
|
||||
@ -152,13 +152,13 @@ func TestVault_Settings_Autostart(t *testing.T) {
|
||||
s := newVault(t)
|
||||
|
||||
// Check the default autostart setting.
|
||||
require.Equal(t, false, s.GetAutostart())
|
||||
require.Equal(t, true, s.GetAutostart())
|
||||
|
||||
// Modify the autostart setting.
|
||||
require.NoError(t, s.SetAutostart(true))
|
||||
require.NoError(t, s.SetAutostart(false))
|
||||
|
||||
// Check the new autostart setting.
|
||||
require.Equal(t, true, s.GetAutostart())
|
||||
require.Equal(t, false, s.GetAutostart())
|
||||
}
|
||||
|
||||
func TestVault_Settings_AutoUpdate(t *testing.T) {
|
||||
|
||||
@ -78,7 +78,7 @@ func newDefaultSettings(gluonDir string) Settings {
|
||||
ColorScheme: "",
|
||||
ProxyAllowed: true,
|
||||
ShowAllMail: true,
|
||||
Autostart: false,
|
||||
Autostart: true,
|
||||
AutoUpdate: true,
|
||||
|
||||
LastVersion: "0.0.0",
|
||||
|
||||
@ -194,6 +194,7 @@ func (t *testCtx) initFrontendService(eventCh <-chan events.Event) error {
|
||||
|
||||
// When starting the frontend, we might enable autostart on bridge if it isn't already.
|
||||
t.mocks.Autostarter.EXPECT().Enable().AnyTimes()
|
||||
t.mocks.Autostarter.EXPECT().IsEnabled().AnyTimes()
|
||||
|
||||
service, err := frontend.NewService(
|
||||
new(mockCrashHandler),
|
||||
|
||||
Reference in New Issue
Block a user