diff --git a/app/main/index.js b/app/main/index.js index cb598145..4fd5d8f0 100644 --- a/app/main/index.js +++ b/app/main/index.js @@ -1,27 +1,28 @@ 'use strict'; const path = require('path'); const electron = require('electron'); -const {app, shell} = require('electron'); +const {app} = require('electron'); const electronLocalshortcut = require('electron-localshortcut'); const ipc = require('electron').ipcMain; const Configstore = require('configstore'); const JsonDB = require('node-json-db'); +const SpellChecker = require('simple-spellchecker'); const tray = require('./tray'); const appMenu = require('./menu'); -const link = require ('./link_helper'); +const link = require('./link-helper'); + const {linkIsInternal} = link; -const db = new JsonDB("domain", true, true); -const data = db.getData("/"); +const db = new JsonDB('domain', true, true); +const data = db.getData('/'); // adds debug features like hotkeys for triggering dev tools and reload require('electron-debug')(); require('electron-context-menu')(); -const conf = new Configstore("Zulip-Desktop"); +const conf = new Configstore('Zulip-Desktop'); // spellchecker enabled -const SpellChecker = require('simple-spellchecker'); let myDictionary = null; // prevent window being garbage collected @@ -32,18 +33,16 @@ let targetLink; const targetUrl = 'file://' + path.join(__dirname, '../renderer', 'index.html'); function checkWindowURL() { - if (data["domain"] !== undefined) { - return data["domain"] + if (data.domain !== undefined) { + return data.domain; } - return targetLink + return targetLink; } const APP_ICON = path.join(__dirname, '../resources', 'Icon'); const iconPath = () => { - return process.platform === 'win32' - ? APP_ICON + '.ico' - : APP_ICON + '.png' + return APP_ICON + (process.platform === 'win32' ? '.ico' : '.png'); }; function onClosed() { @@ -53,7 +52,6 @@ function onClosed() { } function updateDockBadge(title) { - if (title.indexOf('Zulip') === -1) { return; } @@ -62,7 +60,7 @@ function updateDockBadge(title) { messageCount = messageCount ? Number(messageCount[1]) : 0; if (process.platform === 'darwin') { - app.setBadgeCount(messageCount) + app.setBadgeCount(messageCount); } } @@ -88,49 +86,49 @@ function createMainWindow() { // Let's save browser window position if (conf.get('x') || conf.get('y')) { - win.setPosition(conf.get('x'), conf.get('y')); + win.setPosition(conf.get('x'), conf.get('y')); } if (conf.get('maximize')) { - win.maximize(); + win.maximize(); } // Handle sizing events so we can persist them. - win.on('maximize', function (event) { - conf.set('maximize', true); + win.on('maximize', () => { + conf.set('maximize', true); }); - win.on('unmaximize', function (event) { - conf.set('maximize', false); + win.on('unmaximize', () => { + conf.set('maximize', false); }); - win.on('resize', function (event) { - var size = this.getSize(); - conf.set({ - width: size[0], - height: size[1] - }); + win.on('resize', () => { + const size = this.getSize(); + conf.set({ + width: size[0], + height: size[1] + }); }); // on osx it's 'moved' - win.on('move', function (event) { - var pos = this.getPosition(); - conf.set({ - x: pos[0], - y: pos[1] - }); + win.on('move', () => { + const pos = this.getPosition(); + conf.set({ + x: pos[0], + y: pos[1] + }); }); // stop page to update it's title - win.on('page-title-updated', (e,title) => { - e.preventDefault(); - updateDockBadge(title); + win.on('page-title-updated', (e, title) => { + e.preventDefault(); + updateDockBadge(title); }); return win; } -// TODO +// TODO: fix certificate errors app.commandLine.appendSwitch('ignore-certificate-errors', 'true'); app.on('window-all-closed', () => { @@ -153,59 +151,57 @@ app.on('ready', () => { const page = mainWindow.webContents; // Add spellcheck dictionary - SpellChecker.getDictionary("en-US", "./node_modules/simple-spellchecker/dict", function(err, result) { - if(!err) { - myDictionary = result; - } + SpellChecker.getDictionary('en-US', './node_modules/simple-spellchecker/dict', (err, result) => { + if (!err) { + myDictionary = result; + } }); // Define function for consult the dictionary. - ipc.on('checkspell', function(event, word) { - var res = null; - if(myDictionary != null && word != null) { - res = myDictionary.spellCheck(word); - } - event.returnValue = res; + ipc.on('checkspell', (event, word) => { + if (myDictionary !== null && word !== null) { + event.returnValue = myDictionary.spellCheck(word); + } }); // TODO - use global shortcut instead electronLocalshortcut.register(mainWindow, 'CommandOrControl+R', () => { - mainWindow.reload(); - }); + mainWindow.reload(); + }); electronLocalshortcut.register(mainWindow, 'Alt+Left', () => { if (page.canGoBack()) { page.goBack(); } - }); - - electronLocalshortcut.register(mainWindow, 'CommandOrControl+=', () => { - page.send('zoomIn'); }); - electronLocalshortcut.register(mainWindow, 'CommandOrControl+-', () => { - page.send('zoomOut'); - }); + electronLocalshortcut.register(mainWindow, 'CommandOrControl+=', () => { + page.send('zoomIn'); + }); - electronLocalshortcut.register(mainWindow, 'CommandOrControl+0', () => { + electronLocalshortcut.register(mainWindow, 'CommandOrControl+-', () => { + page.send('zoomOut'); + }); + + electronLocalshortcut.register(mainWindow, 'CommandOrControl+0', () => { page.send('zoomActualSize'); }); - page.on('new-window', (event, url) => { - if (mainWindow.useDefaultWindowBehaviour) { - mainWindow.useDefaultWindowBehaviour = false; - return; - } - if (linkIsInternal(checkWindowURL(), url)) { - event.preventDefault(); + page.on('new-window', (event, url) => { + if (mainWindow.useDefaultWindowBehaviour) { + mainWindow.useDefaultWindowBehaviour = false; + return; + } + if (linkIsInternal(checkWindowURL(), url)) { + event.preventDefault(); return mainWindow.loadURL(url); - } - event.preventDefault(); - electron.shell.openExternal(url); - }); + } + event.preventDefault(); + electron.shell.openExternal(url); + }); }); -ipc.on('new-domain', function (e, domain) { +ipc.on('new-domain', (e, domain) => { mainWindow.loadURL(domain); targetLink = domain; }); diff --git a/app/main/link_helper.js b/app/main/link-helper.js similarity index 55% rename from app/main/link_helper.js rename to app/main/link-helper.js index 658b22ea..43211cd8 100644 --- a/app/main/link_helper.js +++ b/app/main/link-helper.js @@ -2,9 +2,9 @@ const wurl = require('wurl'); // Check link if it's internal/external function linkIsInternal(currentUrl, newUrl) { - var currentDomain = wurl('domain', currentUrl); - var newDomain = wurl('domain', newUrl); - return currentDomain === newDomain; + const currentDomain = wurl('domain', currentUrl); + const newDomain = wurl('domain', newUrl); + return currentDomain === newDomain; } exports = module.exports = { diff --git a/app/main/menu.js b/app/main/menu.js index 61e8411f..9ca492b3 100644 --- a/app/main/menu.js +++ b/app/main/menu.js @@ -1,288 +1,304 @@ 'use strict'; const os = require('os'); -const path = require('path'); const electron = require('electron'); + const app = electron.app; const BrowserWindow = electron.BrowserWindow; const shell = electron.shell; const appName = app.getName(); -const { addDomain, About } = require('./windowmanager'); +const {addDomain, about} = require('./windowmanager'); function sendAction(action) { - const win = BrowserWindow.getAllWindows()[0]; + const win = BrowserWindow.getAllWindows()[0]; - if (process.platform === 'darwin') { - win.restore(); - } + if (process.platform === 'darwin') { + win.restore(); + } - win.webContents.send(action); + win.webContents.send(action); } const viewSubmenu = [ -{ - label: 'Reload', - accelerator: 'CmdOrCtrl+R', - click (item, focusedWindow) { - if (focusedWindow) focusedWindow.reload() - } -}, -{ - label: 'Toggle Developer Tools', - accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', - click (item, focusedWindow) { - if (focusedWindow) focusedWindow.webContents.toggleDevTools() - } -}, -{ - type: 'separator' -}, -{ - role: 'togglefullscreen' -} + { + label: 'Reload', + accelerator: 'CmdOrCtrl+R', + click(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.reload(); + } + } + }, + { + label: 'Toggle Developer Tools', + accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', + click(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.webContents.toggleDevTools(); + } + } + }, + { + type: 'separator' + }, + { + role: 'togglefullscreen' + } ]; const helpSubmenu = [ - { - label: `${appName} Website`, - click() { - shell.openExternal('https://zulip.org'); - } - }, - { - label: `${app.getName()} - ${app.getVersion()}`, - }, - { - label: 'Report an Issue...', - click() { - const body = ` + { + label: `${appName} Website`, + click() { + shell.openExternal('https://zulip.org'); + } + }, + { + label: `${app.getName()} - ${app.getVersion()}` + }, + { + label: 'Report an Issue...', + click() { + const body = ` - ${app.getName()} ${app.getVersion()} Electron ${process.versions.electron} ${process.platform} ${process.arch} ${os.release()}`; - shell.openExternal(`https://github.com/zulip/zulip-electron/issues/new?body=${encodeURIComponent(body)}`); - } - } + shell.openExternal(`https://github.com/zulip/zulip-electron/issues/new?body=${encodeURIComponent(body)}`); + } + } ]; const darwinTpl = [ - { - label: `${app.getName()}`, - submenu: [ - { - label: 'Zulip desktop', - click() { - About(); - } - }, - { - type: 'separator' - }, - { - label: 'Change Zulip Server', - accelerator: 'Cmd+,', - click(item, focusedWindow) { - if(focusedWindow) addDomain(); - } - }, - { - label: 'Keyboard shortcuts', - accelerator: 'Cmd+K', - click(item, focusedWindow) { - if(focusedWindow) sendAction('shortcut'); - } - }, - { - type: 'separator' - }, - { - label: 'Log Out', - click(item, focusedWindow) { - if(focusedWindow) sendAction('log-out'); - } - }, - { - type: 'separator' - }, - { - role: 'services', - submenu: [] - }, - { - type: 'separator' - }, - { - role: 'hide' - }, - { - role: 'hideothers' - }, - { - role: 'unhide' - }, - { - type: 'separator' - }, - { - role: 'quit' - } - ] - }, - { - label: 'Edit', - submenu: [ - { - role: 'undo' - }, - { - role: 'redo' - }, - { - type: 'separator' - }, - { - role: 'cut' - }, - { - role: 'copy' - }, - { - role: 'paste' - }, - { - role: 'pasteandmatchstyle' - }, - { - role: 'delete' - }, - { - role: 'selectall' - } - ] - }, - { - label: 'View', - submenu: viewSubmenu - }, - { - role: 'window', - submenu: [ - { - role: 'minimize' - }, - { - role: 'close' - }, - { - type: 'separator' - }, - { - role: 'front' - } - ] - }, - { - role: 'help', - submenu: helpSubmenu - } + { + label: `${app.getName()}`, + submenu: [ + { + label: 'Zulip desktop', + click() { + about(); + } + }, + { + type: 'separator' + }, + { + label: 'Change Zulip Server', + accelerator: 'Cmd+,', + click(item, focusedWindow) { + if (focusedWindow) { + addDomain(); + } + } + }, + { + label: 'Keyboard shortcuts', + accelerator: 'Cmd+K', + click(item, focusedWindow) { + if (focusedWindow) { + sendAction('shortcut'); + } + } + }, + { + type: 'separator' + }, + { + label: 'Log Out', + click(item, focusedWindow) { + if (focusedWindow) { + sendAction('log-out'); + } + } + }, + { + type: 'separator' + }, + { + role: 'services', + submenu: [] + }, + { + type: 'separator' + }, + { + role: 'hide' + }, + { + role: 'hideothers' + }, + { + role: 'unhide' + }, + { + type: 'separator' + }, + { + role: 'quit' + } + ] + }, + { + label: 'Edit', + submenu: [ + { + role: 'undo' + }, + { + role: 'redo' + }, + { + type: 'separator' + }, + { + role: 'cut' + }, + { + role: 'copy' + }, + { + role: 'paste' + }, + { + role: 'pasteandmatchstyle' + }, + { + role: 'delete' + }, + { + role: 'selectall' + } + ] + }, + { + label: 'View', + submenu: viewSubmenu + }, + { + role: 'window', + submenu: [ + { + role: 'minimize' + }, + { + role: 'close' + }, + { + type: 'separator' + }, + { + role: 'front' + } + ] + }, + { + role: 'help', + submenu: helpSubmenu + } ]; const otherTpl = [ - { - label: 'File', - submenu: [ - { - label: 'Zulip desktop', - click() { - About(); - } - }, - { - type: 'separator' - }, - { - label: 'Change Zulip Server', - accelerator: 'Ctrl+,', - click(item, focusedWindow) { - if(focusedWindow) addDomain(); - } - }, - { - type: 'separator' - }, - { - label: 'Keyboard shortcuts', - accelerator: 'Ctrl+K', - click(item, focusedWindow) { - if(focusedWindow) sendAction('shortcut'); - } - }, - { - type: 'separator' - }, - { - label: 'Log Out', - click(item, focusedWindow) { - if(focusedWindow) sendAction('log-out'); - } - }, - { - type: 'separator' - }, - { - role: 'quit' - } - ] - }, - { - label: 'Edit', - submenu: [ - { - role: 'undo' - }, - { - role: 'redo' - }, - { - type: 'separator' - }, - { - role: 'cut' - }, - { - role: 'copy' - }, - { - role: 'paste' - }, - { - role: 'pasteandmatchstyle' - }, - { - role: 'delete' - }, - { - type: 'separator' - }, - { - role: 'selectall' - } + { + label: 'File', + submenu: [ + { + label: 'Zulip desktop', + click() { + about(); + } + }, + { + type: 'separator' + }, + { + label: 'Change Zulip Server', + accelerator: 'Ctrl+,', + click(item, focusedWindow) { + if (focusedWindow) { + addDomain(); + } + } + }, + { + type: 'separator' + }, + { + label: 'Keyboard shortcuts', + accelerator: 'Ctrl+K', + click(item, focusedWindow) { + if (focusedWindow) { + sendAction('shortcut'); + } + } + }, + { + type: 'separator' + }, + { + label: 'Log Out', + click(item, focusedWindow) { + if (focusedWindow) { + sendAction('log-out'); + } + } + }, + { + type: 'separator' + }, + { + role: 'quit' + } + ] + }, + { + label: 'Edit', + submenu: [ + { + role: 'undo' + }, + { + role: 'redo' + }, + { + type: 'separator' + }, + { + role: 'cut' + }, + { + role: 'copy' + }, + { + role: 'paste' + }, + { + role: 'pasteandmatchstyle' + }, + { + role: 'delete' + }, + { + type: 'separator' + }, + { + role: 'selectall' + } - ] - }, - { - label: 'View', - submenu: viewSubmenu - }, - { - role: 'help', - submenu: helpSubmenu - } + ] + }, + { + label: 'View', + submenu: viewSubmenu + }, + { + role: 'help', + submenu: helpSubmenu + } ]; const tpl = process.platform === 'darwin' ? darwinTpl : otherTpl; -module.exports = electron.Menu.buildFromTemplate(tpl); \ No newline at end of file +module.exports = electron.Menu.buildFromTemplate(tpl); diff --git a/app/main/preload.js b/app/main/preload.js index b7f00f28..c87e994f 100644 --- a/app/main/preload.js +++ b/app/main/preload.js @@ -1,29 +1,28 @@ 'use strict'; -const electron = require('electron'); const ipcRenderer = require('electron').ipcRenderer; const webFrame = require('electron').webFrame; // Implement spellcheck using electron api -webFrame.setSpellCheckProvider("en-US", false, { - spellCheck: function(text) { - var res = ipcRenderer.sendSync('checkspell', text); - return res != null? res : true; - } +webFrame.setSpellCheckProvider('en-US', false, { + spellCheck: text => { + const res = ipcRenderer.sendSync('checkspell', text); + return res === null ? true : res; + } }); // Handle zooming functionality const zoomIn = () => { - webFrame.setZoomFactor(webFrame.getZoomFactor() + 0.1); + webFrame.setZoomFactor(webFrame.getZoomFactor() + 0.1); }; const zoomOut = () => { - webFrame.setZoomFactor(webFrame.getZoomFactor() - 0.1); + webFrame.setZoomFactor(webFrame.getZoomFactor() - 0.1); }; const zoomActualSize = () => { - webFrame.setZoomFactor(1); + webFrame.setZoomFactor(1); }; // Get zooming actions from main process @@ -53,4 +52,4 @@ ipcRenderer.on('shortcut', () => { const nodes = document.querySelectorAll('.dropdown-menu li:nth-child(4) a'); nodes[nodes.length - 1].click(); -}); \ No newline at end of file +}); diff --git a/app/main/tray.js b/app/main/tray.js index 1dad6c88..91011026 100644 --- a/app/main/tray.js +++ b/app/main/tray.js @@ -2,22 +2,17 @@ const path = require('path'); const electron = require('electron'); const app = require('electron').app; -const {shell} = require('electron'); -const { addDomain, About } = require('./windowmanager'); -const BrowserWindow = electron.BrowserWindow; +const {addDomain, about} = require('./windowmanager'); let tray = null; const APP_ICON = path.join(__dirname, '../resources', 'Icon'); const iconPath = () => { - return process.platform === 'win32' - ? APP_ICON + '.ico' - : APP_ICON + '.png' + return APP_ICON + (process.platform === 'win32' ? '.ico' : '.png'); }; -exports.create = win => { - +exports.create = () => { // Noone is using this feature. so let's hide it for now. // const toggleWin = () => { // if (win.isVisible()) { @@ -26,12 +21,11 @@ exports.create = win => { // win.show(); // } // }; - const contextMenu = electron.Menu.buildFromTemplate([ { label: 'About', click() { - About(); + about(); } }, { @@ -40,7 +34,9 @@ exports.create = win => { { label: 'Change Zulip server', click(item, focusedWindow) { - if(focusedWindow) addDomain(); + if (focusedWindow) { + addDomain(); + } } }, { @@ -48,8 +44,10 @@ exports.create = win => { }, { label: 'Reload', - click (item, focusedWindow) { - if (focusedWindow) focusedWindow.reload() + click(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.reload(); + } } }, { diff --git a/app/main/windowmanager.js b/app/main/windowmanager.js index 7402f288..fcf731f8 100644 --- a/app/main/windowmanager.js +++ b/app/main/windowmanager.js @@ -1,69 +1,69 @@ 'use strict'; -const electron = require('electron'); const path = require('path'); +const electron = require('electron'); let domainWindow; let aboutWindow; function onClosed() { - // dereference the window - domainWindow = null; - aboutWindow = null; + // dereference the window + domainWindow = null; + aboutWindow = null; } // Change Zulip server Window function createdomainWindow() { - const domainwin = new electron.BrowserWindow({ - frame: false, - height: 300, - resizable: false, - width: 400 - }) - const domainURL = 'file://' + path.join(__dirname, '../renderer', 'pref.html'); - domainwin.loadURL(domainURL); - domainwin.on('closed', onClosed); + const domainwin = new electron.BrowserWindow({ + frame: false, + height: 300, + resizable: false, + width: 400 + }); + const domainURL = 'file://' + path.join(__dirname, '../renderer', 'pref.html'); + domainwin.loadURL(domainURL); + domainwin.on('closed', onClosed); - return domainwin; + return domainwin; } // Call this window onClick addDomain in tray -function addDomain(){ - domainWindow = createdomainWindow(); - domainWindow.show(); -}; +function addDomain() { + domainWindow = createdomainWindow(); + domainWindow.show(); +} // About window function createAboutWindow() { - const aboutwin = new electron.BrowserWindow({ - width: 500, - height: 500, - title: 'About Zulip Desktop', - show: false, - center: true, - fullscreen: false, - fullscreenable: false, - resizable: false - }) - const aboutURL = 'file://' + path.join(__dirname, '../renderer', 'about.html'); - aboutwin.loadURL(aboutURL); - aboutwin.on('closed', onClosed); + const aboutwin = new electron.BrowserWindow({ + width: 500, + height: 500, + title: 'About Zulip Desktop', + show: false, + center: true, + fullscreen: false, + fullscreenable: false, + resizable: false + }); + const aboutURL = 'file://' + path.join(__dirname, '../renderer', 'about.html'); + aboutwin.loadURL(aboutURL); + aboutwin.on('closed', onClosed); - // stop page to update it's title - aboutwin.on('page-title-updated', (e) => { - e.preventDefault(); - }); + // stop page to update it's title + aboutwin.on('page-title-updated', e => { + e.preventDefault(); + }); - aboutwin.on('closed', onClosed); + aboutwin.on('closed', onClosed); - return aboutwin; + return aboutwin; } // Call this onClick About in tray -function About() { - aboutWindow = createAboutWindow(); - aboutWindow.show(); -}; +function about() { + aboutWindow = createAboutWindow(); + aboutWindow.show(); +} exports = module.exports = { - addDomain,About -}; \ No newline at end of file + addDomain, about +}; diff --git a/app/renderer/js/main.js b/app/renderer/js/main.js index 625dc716..2fb7f0bc 100644 --- a/app/renderer/js/main.js +++ b/app/renderer/js/main.js @@ -2,36 +2,33 @@ window.onload = function getURL() { const request = require('request'); const JsonDB = require('node-json-db'); const ipcRenderer = require('electron').ipcRenderer; - const dialogs = require('dialogs')() - const db = new JsonDB("domain", true, true); - const data = db.getData("/"); + const dialogs = require('dialogs')(); - if (data["domain"] !== undefined) { - window.location.href = data["domain"]; - } else { + const db = new JsonDB('domain', true, true); + const data = db.getData('/'); - dialogs.prompt('Enter the URL for your Zulip server', function(url) { + if (data.domain) { + window.location.href = data.domain; + } else { + dialogs.prompt('Enter the URL for your Zulip server', url => { + const newurl = 'https://' + url.replace(/^https?:\/\//, ''); + const checkURL = newurl + '/static/audio/zulip.ogg'; - let newurl = 'https://' + url.replace(/^https?:\/\//,'') - let checkURL = newurl + '/static/audio/zulip.ogg'; + request(checkURL, (error, response) => { + if (!error && response.statusCode !== 404) { + db.push('/domain', newurl); + ipcRenderer.send('new-domain', newurl); + window.location.href = newurl; + } else { + dialogs.alert('Not valid url'); + console.log('Not valid url'); + } + }); + }); + } - request(checkURL, function (error, response, body) { - if (!error && response.statusCode !== 404) { - db.push("/domain", newurl); - ipcRenderer.send('new-domain', newurl); - window.location.href = newurl ; - } - else { - dialogs.alert('Not valid url'); - console.log("Not valid url"); - } - }) - }) - } + const getInput = document.getElementsByTagName('input')[0]; -const getInput = document.getElementsByTagName('input')[0]; - -getInput.setAttribute('placeholder', 'zulip.example.com'); // add placeholder -getInput.setAttribute('spellcheck', 'false'); // no spellcheck for form - -} \ No newline at end of file + getInput.setAttribute('placeholder', 'zulip.example.com'); // add placeholder + getInput.setAttribute('spellcheck', 'false'); // no spellcheck for form +}; diff --git a/app/renderer/js/pref.js b/app/renderer/js/pref.js index 3b4911bf..27efdec1 100644 --- a/app/renderer/js/pref.js +++ b/app/renderer/js/pref.js @@ -1,40 +1,40 @@ 'use strict'; const {remote} = require('electron'); -document.getElementById('close-button').addEventListener('click', function (e) { - let window = remote.getCurrentWindow(); - window.close(); +document.getElementById('close-bu on').addEventListener('click', () => { + const window = remote.getCurrentWindow(); + window.close(); }); // document.getElementById('pic').style.display ='block'; +// eslint-disable-next-line no-unused-vars function addDomain() { + const request = require('request'); + const ipcRenderer = require('electron').ipcRenderer; + const JsonDB = require('node-json-db'); - const request = require('request'); - const ipcRenderer = require('electron').ipcRenderer; - const JsonDB = require('node-json-db'); - const db = new JsonDB('domain', true, true); - document.getElementById('main').innerHTML = 'checking...' - document.getElementById('pic').style.display ='block'; + const db = new JsonDB('domain', true, true); + document.getElementById('main').innerHTML = 'checking...'; + document.getElementById('pic').style.display = 'block'; - let newDomain = document.getElementById('url').value; - newDomain = newDomain.replace(/^https?:\/\//,'') + let newDomain = document.getElementById('url').value; + newDomain = newDomain.replace(/^https?:\/\//, ''); - const domain = 'https://' + newDomain; - const checkDomain = domain + '/static/audio/zulip.ogg'; + const domain = 'https://' + newDomain; + const checkDomain = domain + '/static/audio/zulip.ogg'; - request(checkDomain, function (error, response, body) { - if (!error && response.statusCode !== 404) { - document.getElementById('pic').style.display ='none'; - document.getElementById('main').innerHTML = 'Add' - document.getElementById('urladded').innerHTML = newDomain + ' Added'; - db.push('/domain', domain); - ipcRenderer.send('new-domain', domain); - } - else { - document.getElementById('pic').style.display ='none'; - document.getElementById('main').innerHTML = 'Add' - document.getElementById('urladded').innerHTML = "Not a vaild Zulip server"; - } - }) + request(checkDomain, (error, response) => { + if (!error && response.statusCode !== 404) { + document.getElementById('pic').style.display = 'none'; + document.getElementById('main').innerHTML = 'Add'; + document.getElementById('urladded').innerHTML = newDomain + ' Added'; + db.push('/domain', domain); + ipcRenderer.send('new-domain', domain); + } else { + document.getElementById('pic').style.display = 'none'; + document.getElementById('main').innerHTML = 'Add'; + document.getElementById('urladded').innerHTML = 'Not a vaild Zulip server'; + } + }); } diff --git a/package.json b/package.json index 1b8e23c7..62a73865 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dependencies": { "configstore": "^2.0.0", "dialogs": "1.1.14", + "electron": "^1.3.3", "electron-context-menu": "0.4.0", "electron-debug": "^1.0.0", "electron-dl": "^0.2.0",