Skip to content

Commit

Permalink
testConnection ipc module renamed to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
APixelVisuals committed Mar 23, 2020
1 parent 435fd7d commit dc13ca9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
19 changes: 15 additions & 4 deletions ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ module.exports = () => {

//Modules
const { ipcMain: ipc } = require("electron-better-ipc");
const testConnection = require("./ipc/testConnection");
const keytar = require("./ipc/keytar");
const connect = require("./ipc/connect");

//Define client
let client;

//Is Dev
ipc.answerRenderer("isDev", () => process.env.DEV === "true");

//Test Connection
ipc.answerRenderer("testConnection", async data => await testConnection(data));

//Keytar
ipc.answerRenderer("keytar", async data => await keytar(data));

//Connect
ipc.answerRenderer("connect", async data => {

const result = await connect(data);

if (!data.testConnection) client = result.client;

delete result.client;
return result;
});
};
5 changes: 3 additions & 2 deletions ipc/testConnection.js → ipc/connect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = async ({ hostname, port, srv, authenticationEnabled, username, password, authenticationDatabase }) => {
module.exports = async ({ hostname, port, srv, authenticationEnabled, username, password, authenticationDatabase, testConnection }) => {

//Modules
const { MongoClient } = require("mongodb");
Expand All @@ -11,10 +11,11 @@ module.exports = async ({ hostname, port, srv, authenticationEnabled, username,
await client.connect().catch(err => connectionError = err);

//Close connection
client.close();
if (testConnection) client.close();

//Return
return {
client,
success: !connectionError,
error: connectionError && connectionError.toString()
};
Expand Down
5 changes: 3 additions & 2 deletions src/pages/edit-connection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ export default class EditConnection extends React.Component {
await this.setState({ testingConnection: true, testingConnectionID });

//Test connection
const result = await ipc.callMain("testConnection", {
const result = await ipc.callMain("connect", {
hostname: this.state.hostname,
port: this.state.port,
srv: this.state.srv,
authenticationEnabled: this.state.authenticationEnabled,
username: this.state.username,
password: this.state.password,
authenticationDatabase: this.state.authenticationDatabase
authenticationDatabase: this.state.authenticationDatabase,
testConnection: true
});

//Set testing connection result
Expand Down
5 changes: 3 additions & 2 deletions src/pages/new-connection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ export default class NewConnection extends React.Component {
await this.setState({ testingConnection: true, testingConnectionID });

//Test connection
const result = await ipc.callMain("testConnection", {
const result = await ipc.callMain("connect", {
hostname: this.state.hostname,
port: this.state.port,
srv: this.state.srv,
authenticationEnabled: this.state.authenticationEnabled,
username: this.state.username,
password: this.state.password,
authenticationDatabase: this.state.authenticationDatabase
authenticationDatabase: this.state.authenticationDatabase,
testConnection: true
});

//Set testing connection result
Expand Down

0 comments on commit dc13ca9

Please sign in to comment.