summaryrefslogtreecommitdiff
path: root/state.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-07-12 14:13:32 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-07-12 14:13:32 +0200
commit3dc35af5e0b194c0f23b6b8cfd24337a2861380a (patch)
treeb4c3c13bf1eba8156629d8eecced89991f2a3b0a /state.go
parentfc345f1623d83d3c2e9acb8b3c9139656b2797d1 (diff)
State + FSM: Add an easy way to go back to the previous 'Main' state
The 'Main' state here is a main UI menu, e.g. the intial state, the server search page, the configuring server page or the connected/has config page
Diffstat (limited to 'state.go')
-rw-r--r--state.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/state.go b/state.go
index d4aa3df..e3608ac 100644
--- a/state.go
+++ b/state.go
@@ -97,6 +97,16 @@ func (state *VPNState) Deregister() error {
return nil
}
+func (state *VPNState) GoBack() error {
+ errorMessage := "failed to go back"
+ if state.FSM.InState(fsm.DEREGISTERED) {
+ return &types.WrappedErrorMessage{Message: errorMessage, Err: fsm.DeregisteredError{}.CustomError()}
+ }
+
+ state.FSM.GoBack()
+ return nil
+}
+
func (state *VPNState) getConfig(chosenServer server.Server, forceTCP bool) (string, string, error) {
errorMessage := "failed to get a configuration for OpenVPN/Wireguard"
if state.FSM.InState(fsm.DEREGISTERED) {
@@ -110,8 +120,8 @@ func (state *VPNState) getConfig(chosenServer server.Server, forceTCP bool) (str
if loginErr != nil {
// We are possibly in oauth started
- // So go to no server
- state.FSM.GoTransition(fsm.NO_SERVER)
+ // Go back
+ state.GoBack()
return "", "", &types.WrappedErrorMessage{Message: errorMessage, Err: loginErr}
}
} else { // OAuth was valid, ensure we are in the authorized state
@@ -123,8 +133,8 @@ func (state *VPNState) getConfig(chosenServer server.Server, forceTCP bool) (str
config, configType, configErr := server.GetConfig(chosenServer, forceTCP)
if configErr != nil {
- // Go back to no server if possible
- state.FSM.GoTransition(fsm.NO_SERVER)
+ // Go back
+ state.GoBack()
return "", "", &types.WrappedErrorMessage{Message: errorMessage, Err: configErr}
} else {
state.FSM.GoTransition(fsm.HAS_CONFIG)