diff --git a/GUI/server/odrive_server.py b/GUI/server/odrive_server.py index 9f8b15d1..a650f11b 100644 --- a/GUI/server/odrive_server.py +++ b/GUI/server/odrive_server.py @@ -154,6 +154,8 @@ def postVal(odrives, keyList, value, argType): RO.set_value(value == "true") else: pass # dont support that type yet + except fibre.protocol.ChannelBrokenException: + handle_disconnect() except: print("exception in postVal") @@ -167,6 +169,8 @@ def getVal(odrives, keyList): return dictFromRO(RO) else: return RO.get_value() + except fibre.protocol.ChannelBrokenException: + handle_disconnect() except: print("exception in getVal") return 0 @@ -189,6 +193,8 @@ def callFunc(odrives, keyList): RO = RO._remote_attributes[key] if isinstance(RO, fibre.remote_object.RemoteFunction): RO.__call__() + except fibre.protocol.ChannelBrokenException: + handle_disconnect() except: print("fcn call failed") diff --git a/GUI/src/App.vue b/GUI/src/App.vue index 3e5eaf3f..c58286a6 100644 --- a/GUI/src/App.vue +++ b/GUI/src/App.vue @@ -46,8 +46,6 @@ style="display: none" /> - - @@ -261,13 +259,6 @@ export default { data: {}, }); }, - killServer() { - window.ipcRenderer.send('kill-server'); - }, - startServer() { - window.ipcRenderer.send('start-server'); - this.$store.dispatch("setServerAddress", "http://127.0.0.1:5000"); - } }, created() { // on app creation, set the address to the default diff --git a/GUI/src/background.js b/GUI/src/background.js index 368b01ef..c21e39a4 100644 --- a/GUI/src/background.js +++ b/GUI/src/background.js @@ -11,7 +11,10 @@ const path = require('path'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. -let win +let win; + +// var for python server +let server; // Scheme must be registered before the app is ready protocol.registerSchemesAsPrivileged([ @@ -119,21 +122,28 @@ app.on('ready', async () => { effectiveCommand.push(arg); } } - var python; // launch python server on event from renderer process (gui) and pipe stdout/stderr to it ipcMain.on('start-server', () => { - python = spawn(getPyCmd(), effectiveCommand); - python.stdout.on('data',function(data) { + server = spawn(getPyCmd(), effectiveCommand); + server.stdout.on('data',function(data) { console.log(data.toString('utf8')); - win.webContents.send('server-stdout', String(data.toString('utf8'))); + try { + win.webContents.send('server-stdout', String(data.toString('utf8'))); + } catch (error) { + console.log(error); + } }); - python.stderr.on('data',function(data) { + server.stderr.on('data',function(data) { console.log(data.toString('utf8')); - win.webContents.send('server-stderr', String(data.toString('utf8'))); + try { + win.webContents.send('server-stderr', String(data.toString('utf8'))); + } catch (error) { + console.log(error); + } }); }) ipcMain.on('kill-server', () => { - python.kill('SIGINT'); + server.kill('SIGINT'); }) }) @@ -142,11 +152,13 @@ if (isDevelopment) { if (process.platform === 'win32') { process.on('message', (data) => { if (data === 'graceful-exit') { + server.kill('SIGINT'); app.quit() } }) } else { process.on('SIGTERM', () => { + server.kill('SIGINT'); app.quit() }) }