Stop screen pid when screen process changes
This commit is contained in:
parent
06f1ca7603
commit
5dbe76f6c2
@ -21,13 +21,17 @@ defmodule Chessh.SSH.Client do
|
|||||||
screen_state_initials: []
|
screen_state_initials: []
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
def link_menu_screen(player_session) do
|
||||||
def init([%State{player_session: player_session} = state]) do
|
|
||||||
send(
|
send(
|
||||||
self(),
|
self(),
|
||||||
{:set_screen_process, Chessh.SSH.Client.MainMenu,
|
{:set_screen_process, Chessh.SSH.Client.MainMenu,
|
||||||
%Chessh.SSH.Client.SelectPaginatePoller.State{player_session: player_session}}
|
%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}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
@ -38,14 +42,9 @@ defmodule Chessh.SSH.Client do
|
|||||||
%State{
|
%State{
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
screen_state_initials: screen_state_initials,
|
screen_state_initials: screen_state_initials
|
||||||
screen_pid: screen_pid
|
|
||||||
} = state
|
} = state
|
||||||
) do
|
) do
|
||||||
if screen_pid do
|
|
||||||
Process.unlink(screen_pid)
|
|
||||||
end
|
|
||||||
|
|
||||||
{:ok, new_screen_pid} =
|
{:ok, new_screen_pid} =
|
||||||
GenServer.start_link(module, [%{screen_state_initial | client_pid: self()}])
|
GenServer.start_link(module, [%{screen_state_initial | client_pid: self()}])
|
||||||
|
|
||||||
@ -95,7 +94,8 @@ defmodule Chessh.SSH.Client do
|
|||||||
%State{
|
%State{
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
screen_pid: screen_pid
|
screen_pid: screen_pid,
|
||||||
|
player_session: player_session
|
||||||
} = state
|
} = state
|
||||||
) do
|
) do
|
||||||
case keymap(data) do
|
case keymap(data) do
|
||||||
@ -103,7 +103,10 @@ defmodule Chessh.SSH.Client do
|
|||||||
{:stop, :normal, state}
|
{:stop, :normal, state}
|
||||||
|
|
||||||
:previous_screen ->
|
:previous_screen ->
|
||||||
{:noreply, go_back_one_screen(state)}
|
GenServer.stop(screen_pid)
|
||||||
|
link_menu_screen(player_session)
|
||||||
|
|
||||||
|
{:noreply, state}
|
||||||
|
|
||||||
action ->
|
action ->
|
||||||
send(screen_pid, {:input, width, height, action})
|
send(screen_pid, {:input, width, height, action})
|
||||||
@ -185,6 +188,7 @@ defmodule Chessh.SSH.Client do
|
|||||||
|
|
||||||
defp go_back_one_screen(
|
defp go_back_one_screen(
|
||||||
%State{
|
%State{
|
||||||
|
screen_pid: screen_pid,
|
||||||
screen_state_initials: [_ | rest_initial]
|
screen_state_initials: [_ | rest_initial]
|
||||||
} = state,
|
} = state,
|
||||||
previous_state
|
previous_state
|
||||||
@ -197,10 +201,10 @@ defmodule Chessh.SSH.Client do
|
|||||||
if(is_nil(previous_state), do: prev_state_initial, else: previous_state)}
|
if(is_nil(previous_state), do: prev_state_initial, else: previous_state)}
|
||||||
)
|
)
|
||||||
|
|
||||||
%State{state | screen_state_initials: rest_initial}
|
if screen_pid do
|
||||||
|
GenServer.stop(screen_pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp go_back_one_screen(%State{} = state) do
|
%State{state | screen_state_initials: rest_initial}
|
||||||
go_back_one_screen(state, nil)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ defmodule Chessh.SSH.Client.SelectJoinableGame do
|
|||||||
use Chessh.SSH.Client.SelectPaginatePoller
|
use Chessh.SSH.Client.SelectPaginatePoller
|
||||||
|
|
||||||
def refresh_options_ms(), do: 4000
|
def refresh_options_ms(), do: 4000
|
||||||
def max_displayed_options(), do: 1
|
def max_displayed_options(), do: 10
|
||||||
def title(), do: ["-- Joinable Games --"]
|
def title(), do: ["-- Joinable Games --"]
|
||||||
def dynamic_options(), do: true
|
def dynamic_options(), do: true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user