summaryrefslogtreecommitdiffstats
path: root/src/core/ephraim_gui.erl
blob: b049da351d30d4902405f1f469c466b19299c9e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-module(ephraim_gui).
-compile([debug_info, export_all]).

-spec init() -> ok.
init() ->
    %{jid,JID} = ephraim_config:get(jid),
    Port = open_port({spawn_executable, "ephraim-gtk"}, [binary, nouse_stdio, {packet, 4}]),
    ephraim ! {register_ui, self()},
    loop(Port),
    ephraim ! {unregister_ui, self()}.

-spec loop(port()) -> ok.
loop(Port) ->
    receive
	stop ->
	    ok;
	{Port, {data, Data}} ->
	    Msg = binary_to_term(Data),
	    case Msg of
		stop ->
		    ok;
		_ ->
		    ephraim ! Msg,
		    loop(Port)
	    end;
	Msg ->
	    Port ! {self(), {command, term_to_binary(Msg)}},
	    loop(Port)
    end.