-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskbar.exs
76 lines (62 loc) · 1.77 KB
/
taskbar.exs
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
defmodule Server do
use GenServer
require Logger
@wxID_NEW 5002
@wxID_EXIT 5006
@wxBITMAP_TYPE_PNG 15
def start_link do
GenServer.start_link(__MODULE__, nil)
end
@impl true
def init(_) do
:wx.new()
pid = self()
taskbar =
:wxTaskBarIcon.new(
createPopupMenu: fn ->
menu = :wxMenu.new()
:wxMenu.append(menu, @wxID_NEW, "Debug")
:wxMenu.append(menu, @wxID_EXIT, "Quit")
# For some reason, on macOS the menu event must be handled in another process
# but on Windows it must be either the same process OR we use the callback.
case :os.type() do
{:unix, :darwin} ->
env = :wx.get_env()
Task.start_link(fn ->
:wx.set_env(env)
:wxMenu.connect(menu, :command_menu_selected)
receive do
message ->
send(pid, message)
end
end)
{:win32, _} ->
:ok =
:wxMenu.connect(menu, :command_menu_selected,
callback: fn wx, _ ->
send(pid, wx)
end
)
end
menu
end
)
logo_path = Application.app_dir(:wx, "examples/demo/erlang.png")
icon = :wxIcon.new(logo_path, type: @wxBITMAP_TYPE_PNG)
:wxTaskBarIcon.setIcon(taskbar, icon)
{:ok, %{}}
end
@impl true
def handle_info({:wx, @wxID_EXIT, _, _, _} = event, state) do
Logger.debug(inspect(event))
System.stop()
{:noreply, state}
end
@impl true
def handle_info({:wx, @wxID_NEW, _, _, _} = event, state) do
Logger.debug(inspect(event))
{:noreply, state}
end
end
{:ok, _} = Server.start_link()
Process.sleep(:infinity)