diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-08-19 16:32:35 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-08-19 16:32:35 +0200 |
| commit | d8c7f962e4fe2d4a46f0aeb1c9d9a371d5e41ee0 (patch) | |
| tree | d98c682b31cccb975483111e5b817d5c8d029838 /internal/fsm/fsm.go | |
| parent | f81d05226fe61b697baa91e926dd86efad9d8084 (diff) | |
State + FSM: Properly handle the disconnect flow
- /disconnect is now called
- A new state is added (DISCONNECTING) that waits for the disconnect to complete
- A helper function is exposed (InFSMState) that can be used by clients to see in which state they are in
Diffstat (limited to 'internal/fsm/fsm.go')
| -rw-r--r-- | internal/fsm/fsm.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go index 3c51ce7..f5b1507 100644 --- a/internal/fsm/fsm.go +++ b/internal/fsm/fsm.go @@ -62,6 +62,9 @@ const ( // Has config means the user has gotten a config HAS_CONFIG + // Disconnecting means the OS is disconnecting and the Go code is doing the /disconnect + DISCONNECTING + // Connecting means the OS is establishing a connection to the server CONNECTING @@ -93,6 +96,8 @@ func (s FSMStateID) String() string { return "Ask_Profile" case AUTHORIZED: return "Authorized" + case DISCONNECTING: + return "Disconnecting" case CONNECTING: return "Connecting" case CONNECTED: @@ -142,8 +147,9 @@ func (fsm *FSM) Init(name string, callback func(FSMStateID, FSMStateID, interfac REQUEST_CONFIG: FSMState{Transitions: []FSMTransition{{ASK_PROFILE, "Multiple profiles found and no profile chosen"}, {HAS_CONFIG, "Only one profile or profile already chosen"}, {NO_SERVER, "Cancel or Error"}, {OAUTH_STARTED, "Re-authorize"}}}, ASK_PROFILE: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "User chooses profile"}, {NO_SERVER, "Cancel or Error"}, {SEARCH_SERVER, "Cancel or Error"}}}, HAS_CONFIG: FSMState{Transitions: []FSMTransition{{CONNECTING, "OS reports it is trying to connect"}, {REQUEST_CONFIG, "User reconnects"}, {NO_SERVER, "User wants to choose a new server"}, {OAUTH_STARTED, "Re-authorize with OAuth"}}, BackState: NO_SERVER}, + DISCONNECTING: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "Cancel or Error"}, {HAS_CONFIG, "Done disconnecting"}}}, CONNECTING: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "Cancel or Error"}, {CONNECTED, "Done connecting"}}}, - CONNECTED: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "OS reports disconnected"}}}, + CONNECTED: FSMState{Transitions: []FSMTransition{{DISCONNECTING, "App wants to disconnect"}}}, } fsm.Current = DEREGISTERED fsm.Name = name |
