Skip to content

Commit

Permalink
Allow to cancel loader window when connecting to server #105
Browse files Browse the repository at this point in the history
  • Loading branch information
Paxa committed Oct 17, 2020
1 parent bc53845 commit c27da86
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 124 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### Version 0.9.0

* Fix ssl connection & heroku connection (Thanks to [https://github.com/egallup02360](@egallup02360) #95)
* Postgres 12 support
* Update to electron 10.1.2
* Fix "Snippets" and "See History" on windows (Thanks to [https://github.com/mastazi](@mastazi) #118)
* Allow to cancel loader window when connecting to server

### Version 0.8.4 (20-nov-2019)

* Fix `electron.systemPreferences.subscribeNotification` is not a function
Expand Down
28 changes: 22 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,19 @@ global.App = {
},

openConnection: function (options, connectionName, callback) {
this.startLoading("Connecting...");
var showConnectionError = true;
var runCallback = true;

this.startLoading("Connecting...", 500, {
cancel() {
App.stopRunningQuery();
App.stopLoading();
showConnectionError = false
if (callback) callback(false);
runCallback = false
}
});
//this.startLoading("Connecting...");

if (typeof options == 'string') {
options = Connection.parseConnectionString(options);
Expand All @@ -321,13 +333,17 @@ global.App = {
if (status) {
var tab = this.addDbScreen(conn, connectionName, options);
tab.activate();
if (callback) callback(tab);
if (callback && runCallback) callback(tab);
} else {
$u.alertError("Connection error", {
detail: this.humanErrorMessage(error)
});
if (showConnectionError) {
$u.alertError("Connection error", {
detail: this.humanErrorMessage(error)
});
} else {
console.error(error)
}
//window.alertify.alert(this.humanErrorMessage(message));
if (callback) callback(false);
if (callback && runCallback) callback(false);
}
});
},
Expand Down
1 change: 1 addition & 0 deletions app/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class Connection {
_initConnection(connectString) /*: pg.ClientExt */ {
// @ts-ignore
var clientConfig = Connection.parseConnectionString(connectString) /*:: as pg.ClientConfig */;
// clientConfig.connectionTimeoutMillis = 10000; // 10 sec
return new pg.Client(clientConfig) /*:: as pg.ClientExt */;
}

Expand Down
18 changes: 16 additions & 2 deletions app/login_components/login_postgres_url_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ class LoginPostgresUrlForm {
}

testConnection () {
App.startLoading("Connecting...");
var showConnectionError = true;
App.startLoading("Connecting...", 500, {
cancel() {
App.stopRunningQuery();
App.stopLoading();
showConnectionError = false;
}
});

var options = this.getFormData();
var conn = new Connection();
Expand All @@ -90,7 +97,14 @@ class LoginPostgresUrlForm {
window.alertify.alert("Successfully connected!");
conn.close();
} else {
window.alertify.alert(App.humanErrorMessage(error));
if (showConnectionError) {
$u.alertError("Connection Error", {
detail: App.humanErrorMessage(error)
});
} else {
console.error(error)
}
//window.alertify.alert(App.humanErrorMessage(error));
}
});
}
Expand Down
15 changes: 11 additions & 4 deletions app/login_components/login_standard_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ class LoginStandardForm {
}

testConnection () {
App.startLoading("Connecting...", 100, {
var showConnectionError = true;
App.startLoading("Connecting...", 500, {
cancel() {
App.stopRunningQuery();
App.stopLoading();
showConnectionError = false;
}
});

Expand All @@ -113,9 +116,13 @@ class LoginStandardForm {
window.alertify.alert("Successfully connected!");
conn.close();
} else {
$u.alertError("Connection Error", {
detail: App.humanErrorMessage(error)
});
if (showConnectionError) {
$u.alertError("Connection Error", {
detail: App.humanErrorMessage(error)
});
} else {
console.error(error)
}
//window.alertify.alert(App.humanErrorMessage(message));
}
});
Expand Down
4 changes: 2 additions & 2 deletions app/login_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LoginScreen {
if (this.connections.find('li:first').length) {
this.connections.find('li:first').click();
} else {
this.fillForm({user: process.env.USER});
this.fillForm({user: process.env.USER || 'user'});
}

this.initEvents(this.content);
Expand Down Expand Up @@ -262,7 +262,7 @@ class LoginScreen {
if (autoConnect) {
var connection = this.savedConnections[autoConnect];
console.log("Connecting to auto-connect saved connection: " + autoConnect, connection);
App.startLoading("Connecting...", 50, {
App.startLoading("Connecting...", 500, {
cancel() {
App.stopRunningQuery();
App.stopLoading();
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/pg": "^7.14.5",
"@types/semver": "~7.3.4",
"electron": "10.1.3",
"electron-builder": "^22.8.1",
"electron-builder": "^22.9.1",
"electron-mocha": "^9.2.0",
"electron-rebuild": "2.2.0",
"eslint": "^7.11.0",
Expand All @@ -39,7 +39,7 @@
},
"dependencies": {
"colors": "^1.4.0",
"connection-string": "4.2.0",
"connection-string": "4.2.1",
"cross-env": "^7.0.2",
"csv-stringify": "^5.5.1",
"electron-window-state": "5.0.3",
Expand All @@ -48,7 +48,7 @@
"moment": "^2.29.1",
"needle": "2.5.2",
"open-ssh-tunnel": "^0.3.1",
"pg": "8.3.3",
"pg": "8.4.1",
"pg-escape": "^0.2.0",
"pug": "3.0.0",
"raven": "2.6.4",
Expand Down
Loading

0 comments on commit c27da86

Please sign in to comment.