diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-01-14 16:31:32 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-01-14 16:31:32 +0200 |
| commit | 8184c8d18799feb7ef0aa0eed7e5a2e67a01c791 (patch) | |
| tree | 45a0174ed90b11c6ce89db06ee7237e6ae4dad20 /internal/client/ui/core/core.go | |
| parent | fa2ba2fe8bf24cc9ddc28ec30ea64647d17af1d6 (diff) | |
Added a way to change network properties both server side and client
side
Diffstat (limited to 'internal/client/ui/core/core.go')
| -rw-r--r-- | internal/client/ui/core/core.go | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go index 9e8bd93..d8e4c1f 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -19,6 +19,7 @@ import ( "github.com/kyren223/eko/internal/client/ui/core/networkcreation" "github.com/kyren223/eko/internal/client/ui/core/networkjoin" "github.com/kyren223/eko/internal/client/ui/core/networklist" + "github.com/kyren223/eko/internal/client/ui/core/networkupdate" "github.com/kyren223/eko/internal/client/ui/core/state" "github.com/kyren223/eko/internal/client/ui/loadscreen" "github.com/kyren223/eko/internal/packet" @@ -51,6 +52,7 @@ type Model struct { connected bool networkCreationPopup *networkcreation.Model + networkUpdatePopup *networkupdate.Model networkJoinPopup *networkjoin.Model frequencyCreationPopup *frequencycreation.Model networkList networklist.Model @@ -68,6 +70,7 @@ func New(privKey ed25519.PrivateKey, name string) Model { timeout: initialTimeout, connected: false, networkCreationPopup: nil, + networkUpdatePopup: nil, networkJoinPopup: nil, frequencyCreationPopup: nil, networkList: networklist.New(), @@ -103,6 +106,8 @@ func (m Model) View() string { var popup string if m.networkCreationPopup != nil { popup = m.networkCreationPopup.View() + } else if m.networkUpdatePopup != nil { + popup = m.networkUpdatePopup.View() } else if m.frequencyCreationPopup != nil { popup = m.frequencyCreationPopup.View() } else if m.networkJoinPopup != nil { @@ -220,7 +225,7 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { case "n": switch m.focus { case FocusNetworkList: - if m.networkCreationPopup == nil && m.networkJoinPopup == nil { + if !m.HasPopup() { popup := networkcreation.New() m.networkCreationPopup = &popup } else { @@ -230,7 +235,7 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { } } case FocusFrequencyList: - if m.frequencyCreationPopup == nil { + if !m.HasPopup() { networkId := state.NetworkId(m.networkList.Index()) if networkId == nil { return nil @@ -256,7 +261,7 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { } case "a": - if m.focus == FocusNetworkList && m.networkJoinPopup == nil && m.networkCreationPopup == nil { + if m.focus == FocusNetworkList && !m.HasPopup() { popup := networkjoin.New() m.networkJoinPopup = &popup } else { @@ -265,7 +270,8 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { case "i": index := m.networkList.Index() - if m.focus == FocusNetworkList && index != networklist.PeersIndex { + networkFocus := m.focus == FocusNetworkList + if !m.HasPopup() && networkFocus && index != networklist.PeersIndex { networkId := state.NetworkId(index) if networkId != nil { _ = clipboard.WriteAll(networkId.String()) @@ -274,12 +280,27 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { m.updatePopups(msg) } + case "u": + index := m.networkList.Index() + networkFocus := m.focus == FocusNetworkList + if !m.HasPopup() && networkFocus && index != networklist.PeersIndex { + networkId := state.NetworkId(index) + if networkId != nil { + popup := networkupdate.New(*networkId) + m.networkUpdatePopup = &popup + } + } else { + cmd := m.updatePopups(msg) + if cmd != nil { + return cmd + } + } + case "esc": - if m.networkCreationPopup != nil { + if m.HasPopup() { m.networkCreationPopup = nil - } else if m.frequencyCreationPopup != nil { + m.networkUpdatePopup = nil m.frequencyCreationPopup = nil - } else if m.networkJoinPopup != nil { m.networkJoinPopup = nil } @@ -290,6 +311,12 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { m.networkCreationPopup = nil } return cmd + } else if m.networkUpdatePopup != nil { + cmd := m.networkUpdatePopup.Select() + if cmd != nil { + m.networkUpdatePopup = nil + } + return cmd } else if m.frequencyCreationPopup != nil { cmd := m.frequencyCreationPopup.Select() if cmd != nil { @@ -324,10 +351,7 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { } } - isPopup := m.networkCreationPopup != nil || - m.frequencyCreationPopup != nil || - m.networkJoinPopup != nil - if isPopup { + if m.HasPopup() { return nil } @@ -385,6 +409,10 @@ func (m *Model) updatePopups(msg tea.Msg) tea.Cmd { popup, cmd := m.networkCreationPopup.Update(msg) m.networkCreationPopup = &popup return cmd + } else if m.networkUpdatePopup != nil { + popup, cmd := m.networkUpdatePopup.Update(msg) + m.networkUpdatePopup = &popup + return cmd } else if m.frequencyCreationPopup != nil { popup, cmd := m.frequencyCreationPopup.Update(msg) m.frequencyCreationPopup = &popup @@ -396,3 +424,10 @@ func (m *Model) updatePopups(msg tea.Msg) tea.Cmd { } return nil } + +func (m *Model) HasPopup() bool { + return m.networkCreationPopup != nil || + m.networkUpdatePopup != nil || + m.frequencyCreationPopup != nil || + m.networkJoinPopup != nil +} |
