From d8c7f962e4fe2d4a46f0aeb1c9d9a371d5e41ee0 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Fri, 19 Aug 2022 16:32:35 +0200 Subject: 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 --- internal/fsm/fsm.go | 8 +++++++- internal/server/common.go | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'internal') 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 diff --git a/internal/server/common.go b/internal/server/common.go index 7ee8be6..56c8af0 100644 --- a/internal/server/common.go +++ b/internal/server/common.go @@ -523,6 +523,10 @@ func GetConfig(server Server, forceTCP bool) (string, string, error) { return getConfigWithProfile(server, forceTCP) } +func Disconnect(server Server) { + APIDisconnect(server) +} + type ServerGetCurrentProfileNotFoundError struct { ProfileID string } -- cgit v1.2.3