summaryrefslogtreecommitdiff
path: root/internal/client/ui/core
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2025-01-30 18:55:29 +0200
committerKyren223 <Kyren223@proton.me>2025-01-30 18:55:29 +0200
commita0fb12ca9a8cf762f8eb94c8d3b688dbc776018c (patch)
tree45dd5d1dd740445baed970657803c96dff3c0e38 /internal/client/ui/core
parente98132bb4aa2a30d1caa68292328f2d0d553de8a (diff)
Added automatic saving when the client exits (using ctrl+c), will abort
and not save if it takes longer than 1 second
Diffstat (limited to 'internal/client/ui/core')
-rw-r--r--internal/client/ui/core/core.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go
index 4aa5d5d..1ba0069 100644
--- a/internal/client/ui/core/core.go
+++ b/internal/client/ui/core/core.go
@@ -1,6 +1,7 @@
package core
import (
+ "context"
"crypto/ed25519"
"fmt"
"log"
@@ -258,6 +259,19 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd {
switch msg := msg.(type) {
case ui.QuitMsg:
+ data := state.JsonUserData()
+ ch := gateway.SendAsync(&packet.SetUserData{
+ Data: &data,
+ User: nil,
+ })
+
+ ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+ select {
+ case <-ctx.Done():
+ case <-ch:
+ }
+ cancel()
+
gateway.Disconnect()
case gateway.ConnectionLost: