11import { Notification , nativeImage , NativeImage } from 'electron' ;
22
33import { invoke } from '../ipc/main' ;
4- import { dispatch , listen } from '../store' ;
4+ import { dispatch , dispatchSingle , listen } from '../store' ;
5+ import { ActionIPCMeta } from '../store/actions' ;
56import { hasMeta } from '../store/fsa' ;
67import { getRootWindow } from '../ui/main/rootWindow' ;
78import {
@@ -45,7 +46,8 @@ const notifications = new Map();
4546
4647const createNotification = async (
4748 id : string ,
48- { title, body, icon, silent, canReply, actions } : ExtendedNotificationOptions
49+ { title, body, icon, silent, canReply, actions } : ExtendedNotificationOptions ,
50+ ipcMeta ?: ActionIPCMeta
4951) : Promise < string > => {
5052 const notification = new Notification ( {
5153 title,
@@ -60,29 +62,43 @@ const createNotification = async (
6062 } ) ;
6163
6264 notification . addListener ( 'show' , ( ) => {
63- dispatch ( { type : NOTIFICATIONS_NOTIFICATION_SHOWN , payload : { id } } ) ;
65+ dispatchSingle ( {
66+ type : NOTIFICATIONS_NOTIFICATION_SHOWN ,
67+ payload : { id } ,
68+ ipcMeta,
69+ } ) ;
6470 } ) ;
6571
6672 notification . addListener ( 'close' , ( ) => {
67- dispatch ( { type : NOTIFICATIONS_NOTIFICATION_CLOSED , payload : { id } } ) ;
73+ dispatchSingle ( {
74+ type : NOTIFICATIONS_NOTIFICATION_CLOSED ,
75+ payload : { id } ,
76+ ipcMeta,
77+ } ) ;
6878 notifications . delete ( id ) ;
6979 } ) ;
7080
7181 notification . addListener ( 'click' , ( ) => {
72- dispatch ( { type : NOTIFICATIONS_NOTIFICATION_CLICKED , payload : { id } } ) ;
82+ dispatchSingle ( {
83+ type : NOTIFICATIONS_NOTIFICATION_CLICKED ,
84+ payload : { id } ,
85+ ipcMeta,
86+ } ) ;
7387 } ) ;
7488
7589 notification . addListener ( 'reply' , ( _event , reply ) => {
76- dispatch ( {
90+ dispatchSingle ( {
7791 type : NOTIFICATIONS_NOTIFICATION_REPLIED ,
7892 payload : { id, reply } ,
93+ ipcMeta,
7994 } ) ;
8095 } ) ;
8196
8297 notification . addListener ( 'action' , ( _event , index ) => {
83- dispatch ( {
98+ dispatchSingle ( {
8499 type : NOTIFICATIONS_NOTIFICATION_ACTIONED ,
85100 payload : { id, index } ,
101+ ipcMeta,
86102 } ) ;
87103 } ) ;
88104
@@ -118,27 +134,26 @@ const updateNotification = async (
118134 return id ;
119135} ;
120136
121- const handleCreateEvent = async ( {
122- tag,
123- ... options
124- } : ExtendedNotificationOptions ) : Promise < string > => {
137+ const handleCreateEvent = async (
138+ { tag, ... options } : ExtendedNotificationOptions ,
139+ ipcMeta ?: ActionIPCMeta
140+ ) : Promise < string > => {
125141 if ( tag && notifications . has ( tag ) ) {
126142 return updateNotification ( tag , options ) ;
127143 }
128144
129145 const id = tag || Math . random ( ) . toString ( 36 ) . slice ( 2 ) ;
130- return createNotification ( id , options ) ;
146+ return createNotification ( id , options , ipcMeta ) ;
131147} ;
132148
133149export const setupNotifications = ( ) : void => {
134150 listen ( NOTIFICATIONS_CREATE_REQUESTED , async ( action ) => {
135151 if ( ! hasMeta ( action ) ) {
136152 return ;
137153 }
138-
139154 dispatch ( {
140155 type : NOTIFICATIONS_CREATE_RESPONDED ,
141- payload : await handleCreateEvent ( action . payload ) ,
156+ payload : await handleCreateEvent ( action . payload , action . ipcMeta ) ,
142157 meta : {
143158 id : action . meta . id ,
144159 response : true ,
0 commit comments