Browse Source

enhance robustness

MaysWind 3 years ago
parent
commit
494f26c7a1
2 changed files with 64 additions and 24 deletions
  1. 34 18
      main/ipc/main-process.js
  2. 30 6
      main/ipc/render-proecss.js

+ 34 - 18
main/ipc/main-process.js

@@ -152,22 +152,34 @@ ipcMain.handle('render-request-http', (event, requestContext) => {
 ipcMain.on('render-connect-websocket', (event, rpcUrl, options) => {
     websocket.connect(rpcUrl, options,
         function onOpen(context) {
-            core.mainWindow.webContents.send('on-main-websocket-open', {
-                url: context.url
-            });
+            try {
+                core.mainWindow.webContents.send('on-main-websocket-open', {
+                    url: context.url
+                });
+            } catch (ex) {
+                // Do Nothing
+            }
         },
         function onClose(context) {
-            core.mainWindow.webContents.send('on-main-websocket-close', {
-                url: context.url,
-                autoReconnect: context.autoReconnect
-            });
+            try {
+                core.mainWindow.webContents.send('on-main-websocket-close', {
+                    url: context.url,
+                    autoReconnect: context.autoReconnect
+                });
+            } catch (ex) {
+                // Do Nothing
+            }
         },
         function onMessage(context) {
-            core.mainWindow.webContents.send('on-main-websocket-message', {
-                success: context.success,
-                url: context.url,
-                data: context.message
-            });
+            try {
+                core.mainWindow.webContents.send('on-main-websocket-message', {
+                    success: context.success,
+                    url: context.url,
+                    data: context.message
+                });
+            } catch (ex) {
+                // Do Nothing
+            }
         }
     );
 });
@@ -179,12 +191,16 @@ ipcMain.on('render-reconnect-websocket', (event, rpcUrl, options) => {
 ipcMain.on('render-send-websocket-message', (event, requestContext) => {
     websocket.send(requestContext)
         .catch(function () {
-            core.mainWindow.webContents.send('on-main-websocket-message', {
-                success: false,
-                url: requestContext.url,
-                request: requestContext.data,
-                data: null
-            });
+            try {
+                core.mainWindow.webContents.send('on-main-websocket-message', {
+                    success: false,
+                    url: requestContext.url,
+                    request: requestContext.data,
+                    data: null
+                });
+            } catch (ex) {
+                // Do Nothing
+            }
         });
 });
 

+ 30 - 6
main/ipc/render-proecss.js

@@ -10,27 +10,51 @@ const constants = require('../config/constants');
 const ipcMain = electron.ipcMain;
 
 let notifyRenderProcessLogDebug = function (msg, object) {
-    core.mainWindow.webContents.send('on-main-log-debug', msg, object);
+    try {
+        core.mainWindow.webContents.send('on-main-log-debug', msg, object);
+    } catch (ex) {
+        // Do Nothing
+    }
 };
 
 let notifyRenderProcessLogInfo = function (msg, object) {
-    core.mainWindow.webContents.send('on-main-log-info', msg, object);
+    try {
+        core.mainWindow.webContents.send('on-main-log-info', msg, object);
+    } catch (ex) {
+        // Do Nothing
+    }
 };
 
 let notifyRenderProcessLogWarn = function (msg, object) {
-    core.mainWindow.webContents.send('on-main-log-warn', msg, object);
+    try {
+        core.mainWindow.webContents.send('on-main-log-warn', msg, object);
+    } catch (ex) {
+        // Do Nothing
+    }
 };
 
 let notifyRenderProcessLogError = function (msg, object) {
-    core.mainWindow.webContents.send('on-main-log-error', msg, object);
+    try {
+        core.mainWindow.webContents.send('on-main-log-error', msg, object);
+    } catch (ex) {
+        // Do Nothing
+    }
 };
 
 let notifyRenderProcessWindowMaximized = function (maximized) {
-    core.mainWindow.webContents.send('on-main-window-maximized', maximized);
+    try {
+        core.mainWindow.webContents.send('on-main-window-maximized', maximized);
+    } catch (ex) {
+        // Do Nothing
+    }
 };
 
 let notifyRenderProcessWindowUnmaximized = function (maximized) {
-    core.mainWindow.webContents.send('on-main-window-unmaximized', maximized);
+    try {
+        core.mainWindow.webContents.send('on-main-window-unmaximized', maximized);
+    } catch (ex) {
+        // Do Nothing
+    }
 };
 
 let notifyRenderProcessShowErrorMessage = function (message) {