Skip to content

Commit

Permalink
Merge pull request #130 from Lplenka/master
Browse files Browse the repository at this point in the history
Check if zulip server is down Fixes Issue #124
  • Loading branch information
akashnimare committed Mar 20, 2017
2 parents 5eba4b8 + 531afcb commit 7736953
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 33 deletions.
4 changes: 1 addition & 3 deletions app/main/domain.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const {
app
} = require('electron').remote;
const {app} = require('electron').remote;
const ipcRenderer = require('electron').ipcRenderer;
const JsonDB = require('node-json-db');
const request = require('request');
Expand Down
38 changes: 34 additions & 4 deletions app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const electron = require('electron');
const {app} = require('electron');
const ipc = require('electron').ipcMain;
const {dialog} = require('electron');
const https = require('https');
const http = require('http');
const electronLocalshortcut = require('electron-localshortcut');
const Configstore = require('configstore');
const JsonDB = require('node-json-db');
Expand Down Expand Up @@ -56,6 +58,31 @@ const targetURL = function () {
return data.domain;
};

function serverError(targetURL) {
if (targetURL.indexOf('localhost:') < 0 && data.domain) {
const req = https.request(targetURL + '/static/audio/zulip.ogg', res => {
console.log('Server StatusCode:', res.statusCode);
console.log('You are connected to:', res.req._headers.host);
if (res.statusCode >= 500 && res.statusCode <= 599) {
return dialog.showErrorBox('SERVER IS DOWN!', 'We are getting a ' + res.statusCode + ' error status from the server ' + res.req._headers.host + '. Please try again after some time or you may switch server.');
}
});
req.on('error', e => {
console.error(e);
});
req.end();
} else if (data.domain) {
const req = http.request(targetURL + '/static/audio/zulip.ogg', res => {
console.log('Server StatusCode:', res.statusCode);
console.log('You are connected to:', res.req._headers.host);
});
req.on('error', e => {
console.error(e);
});
req.end();
}
}

function checkConnectivity() {
return dialog.showMessageBox({
title: 'Internet connection problem',
Expand Down Expand Up @@ -154,10 +181,12 @@ function createMainWindow() {
win.once('ready-to-show', () => {
win.show();
});
win.loadURL(targetURL(),
{
userAgent: isUserAgent + ' ' + win.webContents.getUserAgent()
});

serverError(targetURL());

win.loadURL(targetURL(), {
userAgent: isUserAgent + ' ' + win.webContents.getUserAgent()
});

win.on('closed', onClosed);
win.setTitle('Zulip');
Expand Down Expand Up @@ -286,6 +315,7 @@ ipc.on('new-domain', (e, domain) => {
mainWindow.show();
} else {
mainWindow.loadURL(domain);
serverError(domain);
}
targetLink = domain;
});
7 changes: 7 additions & 0 deletions app/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ const ipcRenderer = require('electron').ipcRenderer;
const {webFrame} = require('electron');
const {spellChecker} = require('./spellchecker');

const _setImmediate = setImmediate;
const _clearImmediate = clearImmediate;
process.once('loaded', () => {
global.setImmediate = _setImmediate;
global.clearImmediate = _clearImmediate;
});

// enable swipe back/forward navigation on macOS
require('./macos-swipe-navigation.js').register();

Expand Down
5 changes: 1 addition & 4 deletions app/main/windowmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,4 @@ function about() {
});
}

exports = module.exports = {
addDomain,
about
};
exports = module.exports = {addDomain, about};
11 changes: 6 additions & 5 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.5.8",
"description": "Zulip Desktop App",
"license": "Apache-2.0",
"email":"<svnitakash@gmail.com>",
"email": "<svnitakash@gmail.com>",
"copyright": "©2017 Kandra Labs, Inc.",
"author": {
"name": "Akash Nimare",
Expand All @@ -27,15 +27,16 @@
"InstantMessaging"
],
"dependencies": {
"electron-is-dev": "0.1.2",
"electron-updater": "1.7.1",
"electron-log": "1.3.0",
"configstore": "2.1.0",
"electron-debug": "1.1.0",
"electron-is-dev": "0.1.2",
"electron-localshortcut": "1.0.0",
"electron-log": "1.3.0",
"electron-spellchecker": "1.0.4",
"electron-updater": "1.7.1",
"https": "^1.0.0",
"node-json-db": "0.7.3",
"request": "2.79.0",
"electron-spellchecker": "1.0.4",
"wurl": "2.1.0"
}
}
4 changes: 1 addition & 3 deletions app/renderer/js/pref.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';
// eslint-disable-next-line import/no-extraneous-dependencies
const {
remote
} = require('electron');
const {remote} = require('electron');

const prefWindow = remote.getCurrentWindow();

Expand Down
2 changes: 1 addition & 1 deletion app/renderer/pref.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="form">
<form onsubmit="prefDomain(); return false">
<input id="url" type="text" placeholder="Server URL">
<button type="submit" id="main" value="Submit" onclick="prefDomain();">
<button type="submit" id="main" value="Submit">
Switch</button>
</form>
<p id="urladded"><p>
Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "./app/main",
"description": "Zulip Desktop App",
"license": "Apache-2.0",
"email":"<svnitakash@gmail.com>",
"copyright": "©2016 Kandra Labs, Inc.",
"email": "<svnitakash@gmail.com>",
"copyright": "©2017 Kandra Labs, Inc.",
"author": {
"name": "Akash Nimare",
"email": "svnitakash@gmail.com"
Expand Down Expand Up @@ -39,14 +39,17 @@
"mac": {
"category": "public.app-category.productivity"
},
"linux" : {
"linux": {
"synopsis": "Zulip Desktop App",
"category": "",
"packageCategory": "GNOME;GTK;Network;InstantMessaging",
"description": "Zulip Desktop Client for Linux",
"target" : ["deb", "AppImage"],
"version" : "0.5.8",
"title" : "Zulip",
"target": [
"deb",
"AppImage"
],
"version": "0.5.8",
"title": "Zulip",
"license": "Apache-2.0",
"maintainer": "Akash Nimare <svnitakash@gmail.com>"
},
Expand Down Expand Up @@ -79,12 +82,12 @@
}
},
"keywords": [
"Zulip",
"Group Chat app",
"electron-app",
"electron",
"Desktop app",
"InstantMessaging"
"Zulip",
"Group Chat app",
"electron-app",
"electron",
"Desktop app",
"InstantMessaging"
],
"devDependencies": {
"assert": "^1.4.1",
Expand All @@ -110,7 +113,7 @@
"no-warning-comments": 0,
"no-else-return": 0,
"import/no-unresolved": 0,
"import/no-extraneous-dependencies":0
"import/no-extraneous-dependencies": 0
}
}
],
Expand Down

0 comments on commit 7736953

Please sign in to comment.