Skip to content

Commit

Permalink
Expose whether an IEx session is active or not
Browse files Browse the repository at this point in the history
This is useful for avoiding operations that affect remote debug of a
device when someone is actively debugging. For example, this makes it
possible to avoid upgrading the NervesHub connection to what looks like
a better network interface, but actually isn't.
  • Loading branch information
fhunleth authored and jjcarstens committed May 26, 2023
1 parent 1e91fa3 commit d020629
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/nerves_hub_link.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ defmodule NervesHubLink do
Socket.check_connection(:socket)
end

@doc """
Return whether there's currently an active console session
"""
@spec console_active?() :: boolean()
defdelegate console_active?, to: Socket

@doc """
Current status of the update manager
"""
Expand Down
14 changes: 14 additions & 0 deletions lib/nerves_hub_link/socket.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule NervesHubLink.Socket do
@moduledoc false

use Slipstream
require Logger

Expand Down Expand Up @@ -44,6 +46,14 @@ defmodule NervesHubLink.Socket do
GenServer.call(__MODULE__, {:check_connection, type})
end

@doc """
Return whether an IEx or other console session is active
"""
@spec console_active?() :: boolean()
def console_active?() do
GenServer.call(__MODULE__, :console_active?)
end

@impl Slipstream
def init(config) do
rejoin_after = Application.get_env(:nerves_hub_link, :rejoin_after, 5_000)
Expand Down Expand Up @@ -110,6 +120,10 @@ defmodule NervesHubLink.Socket do
{:reply, connected?(socket), socket}
end

def handle_call(:console_active?, _from, socket) do
{:reply, socket.assigns.iex_pid != nil, socket}
end

@impl Slipstream
def handle_cast(:reconnect, socket) do
# See handle_disconnect/2 for the reconnect call once the connection is
Expand Down

0 comments on commit d020629

Please sign in to comment.