@@ -488,6 +488,18 @@ angular.module('mm.core.emulator')
488488 return options ;
489489 }
490490
491+ /**
492+ * Function called when a notification is clicked.
493+ *
494+ * @param {Object } notification Clicked notification.
495+ * @return {Void }
496+ */
497+ function notificationClicked ( notification ) {
498+ $rootScope . $broadcast ( '$cordovaLocalNotification:click' , notification , 'foreground' ) ;
499+ // Focus the app.
500+ require ( 'electron' ) . ipcRenderer . send ( 'focusApp' ) ;
501+ }
502+
491503 /**
492504 * Parse a interval and convert it to a number of milliseconds (0 if not valid).
493505 * Code extracted from the Cordova plugin.
@@ -570,20 +582,24 @@ angular.module('mm.core.emulator')
570582
571583 // Listen for click events.
572584 notifInstance . on ( 'activated' , function ( ) {
573- $rootScope . $broadcast ( '$cordovaLocalNotification:click' , notification , 'foreground' ) ;
585+ notificationClicked ( notification ) ;
574586 } ) ;
575587
576- notifInstance . show ( )
577-
578- // Show it in Tile too.
579- var tileNotif = new winNotif . TileNotification ( {
580- tag : notification . id + '' ,
581- template : tileTemplate ,
582- strings : [ notification . title , notification . text , notification . title , notification . text , notification . title , notification . text ] ,
583- expirationTime : new Date ( Date . now ( ) + mmCoreSecondsHour * 1000 ) // Expire in 1 hour.
584- } )
588+ notifInstance . show ( ) ;
585589
586- tileNotif . show ( )
590+ try {
591+ // Show it in Tile too.
592+ var tileNotif = new winNotif . TileNotification ( {
593+ tag : notification . id + '' ,
594+ template : tileTemplate ,
595+ strings : [ notification . title , notification . text , notification . title , notification . text , notification . title , notification . text ] ,
596+ expirationTime : new Date ( Date . now ( ) + mmCoreSecondsHour * 1000 ) // Expire in 1 hour.
597+ } )
598+
599+ tileNotif . show ( )
600+ } catch ( ex ) {
601+ $log . warn ( 'Error showing TileNotification. Please notice they only work with the app installed.' , ex ) ;
602+ }
587603 } else {
588604 // Use Electron default notifications.
589605 var notifInstance = new Notification ( notification . title , {
@@ -592,7 +608,7 @@ angular.module('mm.core.emulator')
592608
593609 // Listen for click events.
594610 notifInstance . onclick = function ( ) {
595- $rootScope . $broadcast ( '$cordovaLocalNotification:click' , notification , 'foreground' ) ;
611+ notificationClicked ( notification ) ;
596612 } ;
597613 }
598614 }
0 commit comments