Skip to content

Commit a846e3d

Browse files
committed
Add dismiss_notification()
1 parent 7b19690 commit a846e3d

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
erlang 24.3.3 24.3.4.14 system
1+
erlang 24.3.3 24.3.4.14 24.3.4.17 system
22
elixir 1.16.3-otp-24

lib/desktop/fallback.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ defmodule Desktop.Fallback do
208208
end
209209
end
210210

211+
def notification_close(notification) do
212+
call(:wxNotificationMessage, :close, [notification])
213+
end
214+
211215
def wx_subscribe() do
212216
call(:wx, :subscribe_events)
213217
end

lib/desktop/window.ex

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,7 @@ defmodule Desktop.Window do
430430
431431
## Examples
432432
433-
iex> :wx.set_env(Desktop.Env.wx_env())
434-
iex> :wxWebView.isContextMenuEnabled(Desktop.Window.webview(pid))
435-
false
433+
iex> Desktop.Window.show_notification(pid, "Hello, world!")
436434
437435
"""
438436
def show_notification(pid, text, opts \\ []) do
@@ -459,6 +457,13 @@ defmodule Desktop.Window do
459457
GenServer.cast(pid, {:show_notification, text, id, type, title, callback, timeout})
460458
end
461459

460+
@doc """
461+
Dismiss a notification
462+
"""
463+
def dismiss_notification(pid, id) do
464+
GenServer.cast(pid, {:dismiss_notification, id})
465+
end
466+
462467
@doc """
463468
Quit the application. This forces a quick termination which can
464469
be helpful on MacOS/Windows as sometimes the destruction is
@@ -600,6 +605,17 @@ defmodule Desktop.Window do
600605
{:noreply, %Window{ui | notifications: noties}}
601606
end
602607

608+
def handle_cast({:dismiss_notification, id}, ui = %Window{notifications: noties}) do
609+
case Map.pop(noties, id) do
610+
{nil, _noties} ->
611+
{:noreply, ui}
612+
613+
{{note, _callback}, noties} ->
614+
Fallback.notification_close(note)
615+
{:noreply, %Window{ui | notifications: noties}}
616+
end
617+
end
618+
603619
def handle_cast({:show, url}, ui = %Window{home_url: home, last_url: last}) do
604620
new_url = prepare_url(url || last || home)
605621
Logger.info("Showing #{new_url}")

0 commit comments

Comments
 (0)