aboutsummaryrefslogtreecommitdiff
path: root/main.js
blob: 493d066eb314f8ae88d39ac67d1a4c34f0d42772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const { app, BrowserWindow, ipcMain } = require('electron');

const path = require("path");
const url = require("url");

let uiWindow;
let newConnectionDialog;
let queryExecutors = [];

function createMainWindow() {
  uiWindow = new BrowserWindow({
    width: 800,
    height: 600
  });
  uiWindow.loadURL(url.format({
    pathname: path.join(__dirname, "index.html"),
    protocol: "file:",
    slashes: true
  }));

  uiWindow.on("closed", () => {
    uiWindow = null;
    app.quit();
  });
}

app.on("ready", () => {
  createMainWindow();
});

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

app.on("activate", () => {
  if (uiWindow === null) {
    createWindow();
  }
});

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.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);
  });
});