From 1c9e90c1619d56f199c119874d09263acd827b07 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Sun, 25 Feb 2018 13:31:00 +0000 Subject: Report connection errors. Add test connection functionality --- main.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'main.js') diff --git a/main.js b/main.js index 493d066..0b9495e 100644 --- a/main.js +++ b/main.js @@ -43,7 +43,7 @@ app.on("activate", () => { function createNewConnectionDialog() { newConnectionDialog = new BrowserWindow({ width: 400, - height: 540 + height: 600 }); newConnectionDialog.loadURL(url.format({ pathname: path.join(__dirname, "new-connection.html"), @@ -83,17 +83,32 @@ ipcMain.on("newConnection.createConnection", (event, payload) => { }); -ipcMain.on("queryExecutor.initialiseConnectionCallback", (event, executorId) => { - // TODO - handle connection initialisation errors +ipcMain.on("queryExecutor.initialiseConnectionCallback", (event, payload) => { + + if (payload.error !== undefined) { + queryExecutors.pop().close(); + newConnectionDialog.webContents.send("newConnection.initialisationFailed", payload.error); + } + else { + let connectionConfig = getQueryExecutorInstance().connectionConfig; + + if(connectionConfig.isTest) { + newConnectionDialog.webContents.send("newConnection.connectionTestOk"); + queryExecutors.pop().close(); + } + else{ + uiWindow.webContents.send("instanceManager.registerNewInstance", { assignedQueryExecutorId: payload.executorId, connectionName: connectionConfig.name }); + newConnectionDialog.close(); + } + } - // Bit of a hack, cant guarantee this was the executor which just got initalised.executor - // Should pass it back from the executor via the payload - let connectionName = queryExecutors[queryExecutors.length -1].connectionConfig.name; - - uiWindow.webContents.send("instanceManager.registerNewInstance", {assignedQueryExecutorId: executorId, connectionName: connectionName}); - newConnectionDialog.close(); }); +function getQueryExecutorInstance() { + // Bit of a hack, cant guarantee this was the executor which just got initalised + // Should pass it back from the executor via the payload + return queryExecutors[queryExecutors.length - 1]; +} const { webContents } = require('electron'); -- cgit v1.2.3