@@ -2,6 +2,13 @@ defmodule Desktop.Fallback do
22 require Logger
33 alias Desktop . { Wx , OS }
44
5+ @ notification_show_failed """
6+ wxWidgets failed to show a desktop notification (wxNotificationMessage:show/2 returned false). \
7+ On macOS, ensure notifications are enabled for the app in System Settings, use a packaged .app \
8+ with matching bundle id / Info.plist for the Erlang VM, and see \
9+ https://github.com/elixir-desktop/desktop/issues/38 \
10+ """
11+
512 @ moduledoc """
613 Fallback handles version differences in the :wx modules needed for showing the
714 WebView and Desktop notifications and it uses the highest available
@@ -170,7 +177,7 @@ defmodule Desktop.Fallback do
170177 webview
171178 end
172179
173- def notification_new ( title , type ) do
180+ def notification_new ( title , type , parent \\ nil ) do
174181 if module? ( :wxNotificationMessage ) do
175182 flag =
176183 case type do
@@ -180,8 +187,9 @@ defmodule Desktop.Fallback do
180187 end
181188
182189 notification = call ( :wxNotificationMessage , :new , [ title , [ flags: flag ] ] )
190+ notification_set_parent ( notification , parent )
183191
184- if notification_events_available? ( ) do
192+ if notification != nil and notification_events_available? ( ) do
185193 for event <- [
186194 :notification_message_click ,
187195 :notification_message_dismissed ,
@@ -190,9 +198,11 @@ defmodule Desktop.Fallback do
190198 call ( :wxNotificationMessage , :connect , [ notification , event ] )
191199 end
192200 else
193- Logger . warning (
194- "Missing support for wxNotificationMessage Events - upgrade to wxWidgets 3.1 - messages won't be clickable"
195- )
201+ if notification != nil do
202+ Logger . warning (
203+ "Missing support for wxNotificationMessage Events - upgrade to wxWidgets 3.1 - messages won't be clickable"
204+ )
205+ end
196206 end
197207
198208 notification
@@ -204,13 +214,20 @@ defmodule Desktop.Fallback do
204214 end
205215
206216 def notification_show ( notification , message , timeout , title \\ nil ) do
207- if module? ( :wxNotificationMessage ) do
217+ if module? ( :wxNotificationMessage ) and notification != nil do
208218 if title != nil do
209219 call ( :wxNotificationMessage , :setTitle , [ notification , to_charlist ( title ) ] )
210220 end
211221
212222 call ( :wxNotificationMessage , :setMessage , [ notification , to_charlist ( message ) ] )
213- call ( :wxNotificationMessage , :show , [ notification , [ timeout: timeout ] ] )
223+
224+ case call ( :wxNotificationMessage , :show , [ notification , [ timeout: timeout ] ] ) do
225+ false ->
226+ Logger . warning ( @ notification_show_failed )
227+
228+ _ ->
229+ :ok
230+ end
214231 else
215232 Logger . notice ( "NOTIFICATION: #{ title } : #{ message } " )
216233 end
@@ -244,6 +261,14 @@ defmodule Desktop.Fallback do
244261 end
245262 end
246263
264+ defp notification_set_parent ( notification , parent ) do
265+ if notification != nil and parent != nil and OS . macos? ( ) and
266+ module? ( :wxNotificationMessage ) and
267+ Kernel . function_exported? ( :wxNotificationMessage , :setParent , 2 ) do
268+ call ( :wxNotificationMessage , :setParent , [ notification , parent ] )
269+ end
270+ end
271+
247272 defp call ( module , method , args \\ [ ] ) do
248273 if System . get_env ( "NO_WX" ) == nil and Code . ensure_loaded? ( module ) and
249274 Kernel . function_exported? ( module , method , length ( args ) ) do
0 commit comments