diff options
| author | James Barnett <james.barnett@fivium.co.uk> | 2018-02-21 21:42:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-21 21:42:55 +0000 |
| commit | 11e98009906651acb110cd3b1625a771b1e2f472 (patch) | |
| tree | de0a90c201f1949e701c969b2a3a94d7015f4006 /main.js | |
| parent | 6e21916395fac6861783c2b930b47242ac0f4c09 (diff) | |
| parent | 703f78867653ed9c53a745f9808eb96ae8a89dc7 (diff) | |
| download | sql-plus-plus-11e98009906651acb110cd3b1625a771b1e2f472.tar.xz sql-plus-plus-11e98009906651acb110cd3b1625a771b1e2f472.zip | |
Merge branch tabbed-interface into master
Support multiple, configurable connections
Each connection is displayed in its own tab in the main UI, and gets its own query executor.
New connections can be added dynamically through the new connection dialog.
Diffstat (limited to 'main.js')
| -rw-r--r-- | main.js | 106 |
1 files changed, 83 insertions, 23 deletions
@@ -4,7 +4,8 @@ const path = require("path"); const url = require("url"); let uiWindow; -let queryExecutorProcess; +let newConnectionDialog; +let queryExecutors = []; function createMainWindow() { uiWindow = new BrowserWindow({ @@ -23,26 +24,8 @@ function createMainWindow() { }); } -function createQueryExecutorProcess() { - queryExecutorProcess = new BrowserWindow({ - show: false - }); - - queryExecutorProcess.loadURL(url.format({ - pathname: path.join(__dirname, "./query-executor-wrapper.html"), - protocol: "file:", - slashes: true - })); - - queryExecutorProcess.on("closed", () => { - queryExecutorProcess = null; - }); - -} - app.on("ready", () => { createMainWindow(); - createQueryExecutorProcess(); }); app.on("window-all-closed", () => { @@ -57,8 +40,85 @@ app.on("activate", () => { } }); -ipcMain.on("queryExecutor.runQueryComplete", (event, payload) => uiWindow.webContents.send("queryExecutor.runQueryComplete", payload)); -ipcMain.on("queryExecutor.runQuery", (event, payload) => queryExecutorProcess.webContents.send("queryExecutor.runQuery", payload)); +function createNewConnectionDialog() { + newConnectionDialog = new BrowserWindow({ + width: 400, + height: 540 + }); + newConnectionDialog.loadURL(url.format({ + pathname: path.join(__dirname, "new-connection.html"), + protocol: "file:", + slashes: true + })); + + newConnectionDialog.on("closed", () => { + newConnectionDialog = null; + }); +} + +ipcMain.on("instanceManager.openNewConnectionDialog", (event, payload) => { + createNewConnectionDialog(); +}); + +function createQueryExecutor(payload) { + let executor = new BrowserWindow({ + show: false, + }); + + executor.connectionConfig = payload; + + executor.loadURL(url.format({ + pathname: path.join(__dirname, "./query-executor-wrapper.html"), + protocol: "file:", + slashes: true + })); + + queryExecutors.push(executor); + + return executor; +} + +ipcMain.on("newConnection.createConnection", (event, payload) => { + createQueryExecutor(payload); +}); + + +ipcMain.on("queryExecutor.initialiseConnectionCallback", (event, executorId) => { + // TODO - handle connection initialisation errors + + // 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(); +}); + + +const { webContents } = require('electron'); + +// TODO - only send messages to instance manager which will route request to correct webView, rather than +// sending to all webViews +ipcMain.on("queryExecutor.runQueryComplete", (event, payload) => { + webContents.getAllWebContents().forEach((w) => { + w.send("queryExecutor.runQueryComplete", payload); + }) +}); -ipcMain.on("queryExecutor.queryTableMetadataComplete", (event, payload) => uiWindow.webContents.send("queryExecutor.queryTableMetadataComplete", payload)); -ipcMain.on("queryExecutor.queryTableMetadata", (event, payload) => queryExecutorProcess.webContents.send("queryExecutor.queryTableMetadata", payload));
\ No newline at end of file +ipcMain.on("queryExecutor.runQuery", (event, payload) => { + queryExecutors.forEach((executor) => { + executor.webContents.send("queryExecutor.runQuery", payload); + }); +}); + +ipcMain.on("queryExecutor.queryTableMetadataComplete", (event, payload) => { + webContents.getAllWebContents().forEach((w) => { + w.send("queryExecutor.queryTableMetadataComplete", payload); + }) +}); +; +ipcMain.on("queryExecutor.queryTableMetadata", (event, payload) => { + queryExecutors.forEach((executor) => { + executor.webContents.send("queryExecutor.queryTableMetadata", payload); + }); +});
\ No newline at end of file |