diff --git a/app-shell/src/notifications/connect.ts b/app-shell/src/notifications/connect.ts index e8ad5cb7628..4bb208a8409 100644 --- a/app-shell/src/notifications/connect.ts +++ b/app-shell/src/notifications/connect.ts @@ -2,6 +2,7 @@ import mqtt from 'mqtt' import { connectionStore } from './store' import { + sendDeserialized, sendDeserializedGenericError, deserializeExpectedMessages, } from './deserialize' @@ -135,15 +136,8 @@ function establishListeners({ hostname, topic, }) - try { - const browserWindow = connectionStore.getBrowserWindow() - browserWindow?.webContents.send( - 'notify', - hostname, - topic, - deserializedMessage - ) - } catch {} // Prevents shell erroring during app shutdown event. + + sendDeserialized({ hostname, topic, message: deserializedMessage }) }) .catch(error => notifyLog.debug(`${error.message}`)) } @@ -155,10 +149,7 @@ function establishListeners({ // handles transport layer errors only client.on('error', error => { notifyLog.warn(`Error - ${error.name}: ${error.message}`) - sendDeserializedGenericError({ - hostname, - topic: 'ALL_TOPICS', - }) + sendDeserializedGenericError(hostname, 'ALL_TOPICS') client.end() }) @@ -173,10 +164,7 @@ function establishListeners({ packet.reasonCode ?? 'undefined' }` ) - sendDeserializedGenericError({ - hostname, - topic: 'ALL_TOPICS', - }) + sendDeserializedGenericError(hostname, 'ALL_TOPICS') }) } diff --git a/app-shell/src/notifications/deserialize.ts b/app-shell/src/notifications/deserialize.ts index 135ec2938ca..41dae367409 100644 --- a/app-shell/src/notifications/deserialize.ts +++ b/app-shell/src/notifications/deserialize.ts @@ -33,10 +33,10 @@ export function sendDeserialized({ } catch {} // Prevents shell erroring during app shutdown event. } -export function sendDeserializedGenericError({ - hostname, - topic, -}: Omit): void { +export function sendDeserializedGenericError( + hostname: string, + topic: NotifyTopic +): void { sendDeserialized({ hostname, topic, diff --git a/app-shell/src/notifications/subscribe.ts b/app-shell/src/notifications/subscribe.ts index 5626854b4ad..a4ee0ad3315 100644 --- a/app-shell/src/notifications/subscribe.ts +++ b/app-shell/src/notifications/subscribe.ts @@ -53,29 +53,20 @@ export function subscribe({ void waitUntilActiveOrErrored('subscription').catch( (error: Error) => { notifyLog.debug(error.message) - sendDeserializedGenericError({ - hostname, - topic, - }) + sendDeserializedGenericError(hostname, topic) } ) } }) .catch((error: Error) => { notifyLog.debug(error.message) - sendDeserializedGenericError({ - hostname, - topic, - }) + sendDeserializedGenericError(hostname, topic) }) } function subscribeCb(error: Error, result: mqtt.ISubscriptionGrant[]): void { if (error != null) { - sendDeserializedGenericError({ - hostname, - topic, - }) + sendDeserializedGenericError(hostname, topic) } else { notifyLog.debug( `Successfully subscribed on ${hostname} to topic: ${topic}`