Lint error fixed #126[WIP]

This commit is contained in:
Lplenka
2017-04-17 14:22:30 +05:30
parent bd2f17deec
commit 2dd44852fa
3 changed files with 61 additions and 73 deletions

View File

@@ -3,9 +3,9 @@ const path = require('path');
const fs = require('fs');
const os = require('os');
const electron = require('electron');
const { app } = require('electron');
const {app} = require('electron');
const ipc = require('electron').ipcMain;
const { dialog } = require('electron');
const {dialog} = require('electron');
const https = require('https');
const http = require('http');
const electronLocalshortcut = require('electron-localshortcut');
@@ -13,8 +13,8 @@ const Configstore = require('electron-config');
const JsonDB = require('node-json-db');
const isDev = require('electron-is-dev');
const appMenu = require('./menu');
const { linkIsInternal, skipImages } = require('./link-helper');
const { appUpdater } = require('./autoupdater');
const {linkIsInternal, skipImages} = require('./link-helper');
const {appUpdater} = require('./autoupdater');
const db = new JsonDB(app.getPath('userData') + '/domain.json', true, true);
const data = db.getData('/');
@@ -67,14 +67,13 @@ function serverError(targetURL) {
}
});
req.on('error', e => {
if (e.toString().indexOf('Error: self signed certificate') >= 0) {
var url = targetURL.replace(/^https?:\/\//, '');
console.log('Server StatusCode:', 200);
console.log('You are connected to:', url);
} else {
console.error(e);
}
if (e.toString().indexOf('Error: self signed certificate') >= 0) {
const url = targetURL.replace(/^https?:\/\//, '');
console.log('Server StatusCode:', 200);
console.log('You are connected to:', url);
} else {
console.error(e);
}
});
req.end();
} else if (data.domain) {
@@ -256,30 +255,29 @@ function createMainWindow() {
// For self-signed certificate
ipc.on('certificate-err', (e, domain) => {
var detail = `URL: ${domain} \n Error: Self-Signed Certificate`;
dialog.showMessageBox( mainWindow, {
title: 'Certificate error',
message: `Do you trust certificate from ${domain}?`,
detail: detail,
type: 'warning',
buttons: [
'Yes',
'No'
],
cancelId: 1
}, (response) => {
if (response === 0) {
db.push("/certifiedURL", [{domain:domain}], false);
db.push('/domain', domain);
mainWindow.loadURL(domain);
}
});
const detail = `URL: ${domain} \n Error: Self-Signed Certificate`;
dialog.showMessageBox(mainWindow, {
title: 'Certificate error',
message: `Do you trust certificate from ${domain}?`,
// eslint-disable-next-line object-shorthand
detail: detail,
type: 'warning',
buttons: ['Yes', 'No'],
cancelId: 1
// eslint-disable-next-line object-shorthand
}, response => {
if (response === 0) {
// eslint-disable-next-line object-shorthand
db.push('/certifiedURL', [{domain: domain}], false);
db.push('/domain', domain);
mainWindow.loadURL(domain);
}
});
});
// eslint-disable-next-line max-params
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
event.preventDefault();
callback(true);
event.preventDefault();
callback(true);
});
app.on('window-all-closed', () => {

View File

@@ -6,26 +6,22 @@ const request = require('request');
const db = new JsonDB(app.getPath('userData') + '/domain.json', true, true);
const data = db.getData('/');
if(!data.certifiedURL) {
db.push("/certifiedURL",[]);
if (!data.certifiedURL) {
db.push('/certifiedURL', []);
}
let URL_List = db.getData('/certifiedURL');
let URL_Length = URL_List.length;
const UrlList = db.getData('/certifiedURL');
const UrlLength = UrlList.length;
const checkURL = domain => {
for ( var i = 0; i < URL_Length; i++) {
if (URL_List[i].domain === domain);
return true;
break;
for (let i = 0; i < UrlLength; i++) {
if (UrlList[i].domain === domain) {
return true;
}
}
return false;
};
window.addDomain = function () {
const el = sel => {
return document.querySelector(sel);
@@ -81,14 +77,14 @@ window.addDomain = function () {
db.push('/domain', domain);
ipcRenderer.send('new-domain', domain);
} else if (error.toString().indexOf('Error: self signed certificate') >= 0) {
if(checkURL(domain)) {
$el.main.innerHTML = 'Connect';
db.push('/domain', domain);
ipcRenderer.send('new-domain', domain);
} else {
$el.main.innerHTML = 'Connect';
ipcRenderer.send('certificate-err', domain);
}
if (checkURL(domain)) {
$el.main.innerHTML = 'Connect';
db.push('/domain', domain);
ipcRenderer.send('new-domain', domain);
} else {
$el.main.innerHTML = 'Connect';
ipcRenderer.send('certificate-err', domain);
}
} else {
$el.main.innerHTML = 'Connect';
displayError('Not a valid Zulip server');

View File

@@ -20,25 +20,21 @@ window.prefDomain = function () {
const ipcRenderer = require('electron').ipcRenderer;
const JsonDB = require('node-json-db');
// eslint-disable-next-line import/no-extraneous-dependencies
const {
app
} = require('electron').remote;
const {app} = require('electron').remote;
const db = new JsonDB(app.getPath('userData') + '/domain.json', true, true);
let URL_List = db.getData('/certifiedURL');
const UrlList = db.getData('/certifiedURL');
let URL_Length = URL_List.length;
const UrlLength = UrlList.length;
const checkURL = domain => {
for ( var i = 0; i < URL_Length; i++) {
if (URL_List[i].domain === domain);
return true;
break;
for (let i = 0; i < UrlLength; i++) {
if (UrlList[i].domain === domain) {
return true;
}
}
return false;
};
let newDomain = document.getElementById('url').value;
@@ -73,18 +69,16 @@ window.prefDomain = function () {
db.push('/domain', domain);
ipcRenderer.send('new-domain', domain);
} else if (error.toString().indexOf('Error: self signed certificate') >= 0) {
if(checkURL(domain)) {
if (checkURL(domain)) {
document.getElementById('main').innerHTML = 'Switch';
document.getElementById('urladded').innerHTML = 'Switched to ' + newDomain;
db.push('/domain', domain);
ipcRenderer.send('new-domain', domain);
} else {
document.getElementById('main').innerHTML = 'Switch';
ipcRenderer.send('certificate-err', domain);
}
}
else {
} else {
document.getElementById('main').innerHTML = 'Switch';
ipcRenderer.send('certificate-err', domain);
}
} else {
document.getElementById('main').innerHTML = 'Switch';
document.getElementById('urladded').innerHTML = 'Not a valid Zulip Server.';
}