diff options
author | Simponic <loganhunt@simponic.xyz> | 2023-01-20 23:14:37 -0700 |
---|---|---|
committer | Simponic <loganhunt@simponic.xyz> | 2023-01-20 23:33:52 -0700 |
commit | 5dbe76f6c2f702dad664cce6097c189ceea181b1 (patch) | |
tree | 49fd6498f75052bd34cee65b152a7fc6e03c1169 /lib | |
parent | 06f1ca76037397fb61c69319802ed029ac73e715 (diff) | |
download | chessh-5dbe76f6c2f702dad664cce6097c189ceea181b1.tar.gz chessh-5dbe76f6c2f702dad664cce6097c189ceea181b1.zip |
Stop screen pid when screen process changes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chessh/ssh/client/client.ex | 32 | ||||
-rw-r--r-- | lib/chessh/ssh/client/menus/select_joinable_game.ex | 2 |
2 files changed, 19 insertions, 15 deletions
diff --git a/lib/chessh/ssh/client/client.ex b/lib/chessh/ssh/client/client.ex index 5c45294..381f337 100644 --- a/lib/chessh/ssh/client/client.ex +++ b/lib/chessh/ssh/client/client.ex @@ -21,13 +21,17 @@ defmodule Chessh.SSH.Client do screen_state_initials: [] end - @impl true - def init([%State{player_session: player_session} = state]) do + def link_menu_screen(player_session) do send( self(), {:set_screen_process, Chessh.SSH.Client.MainMenu, %Chessh.SSH.Client.SelectPaginatePoller.State{player_session: player_session}} ) + end + + @impl true + def init([%State{player_session: player_session} = state]) do + link_menu_screen(player_session) {:ok, state} end @@ -38,14 +42,9 @@ defmodule Chessh.SSH.Client do %State{ width: width, height: height, - screen_state_initials: screen_state_initials, - screen_pid: screen_pid + screen_state_initials: screen_state_initials } = state ) do - if screen_pid do - Process.unlink(screen_pid) - end - {:ok, new_screen_pid} = GenServer.start_link(module, [%{screen_state_initial | client_pid: self()}]) @@ -95,7 +94,8 @@ defmodule Chessh.SSH.Client do %State{ width: width, height: height, - screen_pid: screen_pid + screen_pid: screen_pid, + player_session: player_session } = state ) do case keymap(data) do @@ -103,7 +103,10 @@ defmodule Chessh.SSH.Client do {:stop, :normal, state} :previous_screen -> - {:noreply, go_back_one_screen(state)} + GenServer.stop(screen_pid) + link_menu_screen(player_session) + + {:noreply, state} action -> send(screen_pid, {:input, width, height, action}) @@ -185,6 +188,7 @@ defmodule Chessh.SSH.Client do defp go_back_one_screen( %State{ + screen_pid: screen_pid, screen_state_initials: [_ | rest_initial] } = state, previous_state @@ -197,10 +201,10 @@ defmodule Chessh.SSH.Client do if(is_nil(previous_state), do: prev_state_initial, else: previous_state)} ) - %State{state | screen_state_initials: rest_initial} - end + if screen_pid do + GenServer.stop(screen_pid) + end - defp go_back_one_screen(%State{} = state) do - go_back_one_screen(state, nil) + %State{state | screen_state_initials: rest_initial} end end diff --git a/lib/chessh/ssh/client/menus/select_joinable_game.ex b/lib/chessh/ssh/client/menus/select_joinable_game.ex index 3b3e249..7c477c0 100644 --- a/lib/chessh/ssh/client/menus/select_joinable_game.ex +++ b/lib/chessh/ssh/client/menus/select_joinable_game.ex @@ -6,7 +6,7 @@ defmodule Chessh.SSH.Client.SelectJoinableGame do use Chessh.SSH.Client.SelectPaginatePoller def refresh_options_ms(), do: 4000 - def max_displayed_options(), do: 1 + def max_displayed_options(), do: 10 def title(), do: ["-- Joinable Games --"] def dynamic_options(), do: true |