Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
  • Loading branch information
dgud committed Sep 29, 2022
2 parents 269ca9e + ba72505 commit 05e7486
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
38 changes: 31 additions & 7 deletions lib/observer/src/observer_wx.erl
Original file line number Diff line number Diff line change
Expand Up @@ -747,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].

Expand Down
16 changes: 9 additions & 7 deletions lib/wx/c_src/wxe_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,16 @@ void WxeApp::MacReopenApp() {
send_msg("reopen_app", &empty);
}

// See: https://github.com/wxWidgets/wxWidgets/blob/v3.1.5/src/osx/cocoa/utils.mm#L76:L93
bool WxeApp::OSXIsGUIApplication() {
// wx manually activates the application if it's not in the bundle [1]. In particular, it calls
// `[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular]` which prevents the app
// from running in the background and we cannot control it with `LSUIElement` [2]. Their check
// if it's a bundle always returns false for wxErlang. Thus we use our own way of detecting it.
// [1] https://github.com/wxWidgets/wxWidgets/blob/v3.1.5/src/osx/cocoa/utils.mm#L76:L93
// [2] https://developer.apple.com/documentation/bundleresources/information_property_list/lsuielement
return !is_packaged_app();
char val_buf[8];
size_t val_len = 7;
int res = enif_getenv("WX_MACOS_NON_GUI_APP", val_buf, &val_len);
if (res == 0) {
return FALSE;
} else {
return TRUE;
}
}
#endif

Expand Down

0 comments on commit 05e7486

Please sign in to comment.