diff options
Diffstat (limited to 'lib/observer/src/observer_wx.erl')
-rw-r--r-- | lib/observer/src/observer_wx.erl | 69 |
1 files changed, 50 insertions, 19 deletions
diff --git a/lib/observer/src/observer_wx.erl b/lib/observer/src/observer_wx.erl index 07e2fb1b29..321f189fc9 100644 --- a/lib/observer/src/observer_wx.erl +++ b/lib/observer/src/observer_wx.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2011-2021. All Rights Reserved. +%% Copyright Ericsson AB 2011-2022. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ %% Includes -include_lib("wx/include/wx.hrl"). +-include_lib("kernel/include/file.hrl"). -include("observer_defs.hrl"). @@ -157,7 +158,7 @@ setup(#state{frame = Frame} = State) -> wxNotebook:connect(Notebook, command_notebook_page_changed, [{skip, true}, {id, ?ID_NOTEBOOK}]), wxFrame:connect(Frame, close_window, []), - wxMenu:connect(Frame, command_menu_selected), + wxMenu:connect(Frame, command_menu_selected, [{skip, true}]), wxFrame:show(Frame), %% Freeze and thaw is buggy currently @@ -390,6 +391,10 @@ handle_event(#wx{id = Id, event = #wxCommand{type = command_menu_selected}}, end, {noreply, change_node_view(Node, LState)}; +handle_event(#wx{id = Id, event = #wxCommand{type = command_menu_selected}}, State) + when Id >= ?wxID_OSX_MENU_FIRST, Id =< ?wxID_OSX_MENU_LAST -> + {noreply, State}; + handle_event(Event, #state{active_tab=Pid} = State) -> Pid ! Event, {noreply, State}. @@ -558,7 +563,7 @@ try_rpc(Node, Mod, Func, Args) -> return_to_localnode(Frame, Node) -> case node() =/= Node of true -> - create_txt_dialog(Frame, "Error occured on remote node", + create_txt_dialog(Frame, "Error occurred on remote node", "Error", ?wxICON_ERROR), disconnect_node(Node); false -> @@ -658,14 +663,16 @@ create_connect_dialog(connect, #state{frame = Frame}) -> wxWindow:setSizerAndFit(Dialog, VSizer), wxSizer:setSizeHints(VSizer, Dialog), {ok,[[HomeDir]]} = init:get_argument(home), - CookiePath = filename:join(HomeDir, ".erlang.cookie"), - DefaultCookie = case filelib:is_file(CookiePath) of - true -> - {ok, Bin} = file:read_file(CookiePath), - binary_to_list(Bin); - false -> - "" - end, + XDGHome = filename:basedir(user_config,"erlang"), + DefaultCookie = + case file:path_open([HomeDir,XDGHome], ".erlang.cookie", [read]) of + {ok, File, _} -> + {ok, #file_info{ size = Sz }} = file:read_file_info(File), + {ok, Data} = file:read(File, Sz), + Data; + _ -> + "" + end, wxTextCtrl:setValue(CookieCtrl, DefaultCookie), case wxDialog:showModal(Dialog) of ?wxID_OK -> @@ -740,21 +747,45 @@ get_nodes() -> Nodes0 = case erlang:is_alive() of false -> []; true -> - case net_adm:names() of - {error, _} -> nodes(); - {ok, Names} -> - epmd_nodes(Names) ++ nodes() - end + case net_adm:names() of + {error, _} -> []; + {ok, Names} -> epmd_nodes(Names) + end + ++ + [node() | nodes(connected)] end, Nodes = lists:usort(Nodes0), + WarningText = "WARNING: connecting to non-erlang nodes may crash them", {_, Menues} = lists:foldl(fun(Node, {Id, Acc}) when Id < ?LAST_NODES_MENU_ID -> {Id + 1, [#create_menu{id=Id + ?FIRST_NODES_MENU_ID, - text=atom_to_list(Node)} | Acc]} + text=atom_to_list(Node), + help=WarningText} | Acc]} end, {1, []}, Nodes), {Nodes, lists:reverse(Menues)}. -epmd_nodes(Names) -> +%% see erl_epmd:(listen_)port_please/2 +erl_dist_port() -> + try + erl_epmd = net_kernel:epmd_module(), + {ok, [[StringPort]]} = init:get_argument(erl_epmd_port), + list_to_integer(StringPort) + catch + _:_ -> + undefined + end. + +%% If the default epmd module erl_epmd is used and erl_epmd_port is +%% set to `DistPort' then it is only possible to connect to the node +%% listening on DistPort (if any), so exclude other nodes registered +%% in EPMD +epmd_nodes(Names0) -> + Names = case erl_dist_port() of + undefined -> + Names0; + DistPort -> + [NP || NP = {_, Port} <- Names0, Port =:= DistPort] + end, [_, Host] = string:lexemes(atom_to_list(node()),"@"), [list_to_atom(Name ++ [$@|Host]) || {Name, _} <- Names]. @@ -833,7 +864,7 @@ is_rb_compatible(Node) -> is_rb_server_running(Node, LogState) -> %% If already started, somebody else may use it. - %% We cannot use it too, as far log file would be overriden. Not fair. + %% We cannot use it too, as far log file would be overridden. Not fair. case rpc:block_call(Node, erlang, whereis, [rb_server]) of Pid when is_pid(Pid), (LogState == false) -> throw("Error: rb_server is already started and maybe used by someone."); |