@@ -144,24 +144,33 @@ function onMessage(message, sender, sendResponse) {
144144 activeDownloads . push ( message . download )
145145 chrome . runtime
146146 . sendNativeMessage ( nativeApp , message )
147- . then ( ( response ) => {
148- console . log ( 'response:' , response )
149- sendNotification (
150- 'Download Complete.' ,
151- response . path ,
152- response . path
153- )
154- const index = activeDownloads . indexOf ( message . download )
155- if ( index !== - 1 ) {
156- activeDownloads . splice ( index , 1 )
157- }
158- } )
147+ . then ( ( response ) => downloadResponse ( response , message ) )
159148 } catch ( e ) {
160149 console . log ( e )
161150 }
162151 }
163152}
164153
154+ /**
155+ * This function should be moved to a better home
156+ * Download File Response Handler
157+ * @function downloadResponse
158+ * @param {Object } response
159+ * @param {Object } message
160+ */
161+ function downloadResponse ( response , message ) {
162+ console . log ( 'response, message:' , response , message )
163+ const index = activeDownloads . indexOf ( message . download )
164+ if ( index !== - 1 ) {
165+ activeDownloads . splice ( index , 1 )
166+ }
167+ if ( response . success ) {
168+ sendNotification ( 'Download Complete' , response . path , response . path )
169+ } else {
170+ sendNotification ( 'Download Error' , response . message )
171+ }
172+ }
173+
165174/**
166175 * On Changed Callback
167176 * @function onChanged
@@ -193,6 +202,11 @@ function onChanged(changes, namespace) {
193202async function notificationsClicked ( notificationId ) {
194203 console . debug ( 'notifications.onClicked:' , notificationId )
195204 chrome . notifications . clear ( notificationId )
205+ const uuidRegex =
206+ / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - 4 [ 0 - 9 a - f ] { 3 } - [ 8 9 a b ] [ 0 - 9 a - f ] { 3 } - [ 0 - 9 a - f ] { 12 } $ / i
207+ if ( ! isNaN ( parseInt ( notificationId ) ) || uuidRegex . test ( notificationId ) ) {
208+ return console . log ( 'normal notification' )
209+ }
196210 const message = { open : notificationId }
197211 console . log ( 'message:' , message )
198212 try {
0 commit comments