@@ -4,6 +4,7 @@ const SOCKET_URL =
44 process . env . NODE_ENV === 'development' ? DEV_SOCKET_URL : PROD_SOCKET_URL ;
55let client , reconnect , messageListener , socketConnection ;
66const reconnectDelay = 2000 ;
7+ const mailboxWindow = require ( './windows/mailbox' ) ;
78const globalManager = require ( './globalManager' ) ;
89const NETWORK_STATUS = {
910 ONLINE : 'online' ,
@@ -78,13 +79,20 @@ const handleError = (error, errorMessage) => {
7879} ;
7980
8081const setConnectionStatus = networkStatus => {
82+ const prevNetworkStatus = globalManager . internetConnection . getStatus ( ) ;
8183 switch ( networkStatus ) {
8284 case NETWORK_STATUS . ONLINE : {
83- globalManager . internetConnection . setStatus ( true ) ;
85+ if ( prevNetworkStatus !== true ) {
86+ globalManager . internetConnection . setStatus ( true ) ;
87+ mailboxWindow . send ( 'network-connection-established' , null ) ;
88+ }
8489 break ;
8590 }
8691 case NETWORK_STATUS . OFFLINE : {
87- globalManager . internetConnection . setStatus ( false ) ;
92+ if ( prevNetworkStatus !== false ) {
93+ globalManager . internetConnection . setStatus ( false ) ;
94+ mailboxWindow . send ( 'lost-network-connection' , null ) ;
95+ }
8896 break ;
8997 }
9098 default :
@@ -100,6 +108,7 @@ const initPingParams = () => {
100108const checkAlive = ( ) => {
101109 if ( shouldSendPing === undefined || shouldSendPing === '1' ) {
102110 shouldSendPing = 0 ;
111+ setConnectionStatus ( NETWORK_STATUS . ONLINE ) ;
103112 } else {
104113 setConnectionStatus ( NETWORK_STATUS . OFFLINE ) ;
105114 log ( 'Error: Lost Connection. Check internet' ) ;
0 commit comments