Commit e36251e6 authored by Tasso Evangelista's avatar Tasso Evangelista

Update code style of source code

parent 086393e6
import './branding/branding.js';
import { start } from './scripts/start';
import { remote } from 'electron';
const app = remote.app;
const { app } = remote;
Bugsnag.metaData = {
// platformId: app.process.platform,
// platformArch: app.process.arch,
// electronVersion: app.process.versions.electron,
version: app.getVersion()
version: app.getVersion(),
// platformVersion: cordova.platformVersion
// build: appInfo.build
};
......
......@@ -31,11 +31,11 @@ const unsetDefaultApplicationMenu = () => {
{
label: i18n.__('Quit_App', app.getName()),
accelerator: 'CommandOrControl+Q',
click () {
click() {
app.quit();
}
}
]
},
},
],
}];
Menu.setApplicationMenu(Menu.buildFromTemplate(emptyMenuTemplate));
};
......@@ -61,15 +61,15 @@ const migrateOlderVersionUserData = () => {
};
const parseProtocolUrls = (args) =>
args.filter(arg => /^rocketchat:\/\/./.test(arg))
.map(uri => url.parse(uri))
args.filter((arg) => /^rocketchat:\/\/./.test(arg))
.map((uri) => url.parse(uri))
.map(({ hostname, pathname, query }) => {
const { insecure } = querystring.parse(query);
return `${ insecure === 'true' ? 'http' : 'https' }://${ hostname }${ pathname || '' }`;
});
const addServers = (protocolUrls) => parseProtocolUrls(protocolUrls)
.forEach(serverUrl => addServer(serverUrl));
.forEach((serverUrl) => addServer(serverUrl));
const isSecondInstance = app.makeSingleInstance((argv) => {
addServers(argv.slice(2));
......@@ -82,7 +82,7 @@ if (isSecondInstance && !process.mas) {
// macOS only
app.on('open-url', (event, url) => {
event.preventDefault();
addServers([ url ]);
addServers([url]);
});
app.on('ready', () => {
......@@ -96,7 +96,7 @@ app.on('ready', () => {
createMainWindow();
getMainWindow().then(mainWindow => certificate.initWindow(mainWindow));
getMainWindow().then((mainWindow) => certificate.initWindow(mainWindow));
autoUpdate();
});
......
......@@ -39,20 +39,20 @@ const saveUpdateSettings = () => {
let checkForUpdatesEvent;
function updateDownloaded () {
function updateDownloaded() {
dialog.showMessageBox({
title: i18n.__('Update_ready'),
message: i18n.__('Update_ready_message'),
buttons: [
i18n.__('Update_Install_Later'),
i18n.__('Update_Install_Now')
i18n.__('Update_Install_Now'),
],
defaultId: 1
defaultId: 1,
}, (response) => {
if (response === 0) {
dialog.showMessageBox({
title: i18n.__('Update_installing_later'),
message: i18n.__('Update_installing_later_message')
message: i18n.__('Update_installing_later_message'),
});
} else {
autoUpdater.quitAndInstall();
......@@ -61,14 +61,14 @@ function updateDownloaded () {
});
}
function updateNotAvailable () {
function updateNotAvailable() {
if (checkForUpdatesEvent) {
checkForUpdatesEvent.sender.send('update-result', false);
checkForUpdatesEvent = null;
}
}
function updateAvailable ({version}) {
function updateAvailable({ version }) {
if (checkForUpdatesEvent) {
checkForUpdatesEvent.sender.send('update-result', true);
checkForUpdatesEvent = null;
......@@ -84,10 +84,10 @@ function updateAvailable ({version}) {
center: true,
resizable: false,
maximizable: false,
minimizable: false
minimizable: false,
});
window.loadURL(`file://${__dirname}/public/update.html`);
window.loadURL(`file://${ __dirname }/public/update.html`);
window.setMenuBarVisibility(false);
window.webContents.on('did-finish-load', () => {
......@@ -102,19 +102,19 @@ function updateAvailable ({version}) {
saveUpdateSettings();
dialog.showMessageBox({
title: i18n.__('Update_skip'),
message: i18n.__('Update_skip_message')
message: i18n.__('Update_skip_message'),
}, () => window.close());
break;
case 'remind':
dialog.showMessageBox({
title: i18n.__('Update_remind'),
message: i18n.__('Update_remind_message')
message: i18n.__('Update_remind_message'),
}, () => window.close());
break;
case 'update':
dialog.showMessageBox({
title: i18n.__('Update_downloading'),
message: i18n.__('Update_downloading_message')
message: i18n.__('Update_downloading_message'),
}, () => window.close());
autoUpdater.downloadUpdate();
break;
......
......@@ -4,7 +4,7 @@ import url from 'url';
import i18n from '../i18n/index.js';
class CertificateStore {
initWindow (win) {
initWindow(win) {
this.storeFileName = 'certificate.json';
this.userDataDir = jetpack.cwd(app.getPath('userData'));
......@@ -29,7 +29,7 @@ class CertificateStore {
this.queued[certificate.fingerprint] = [callback];
}
let detail = `URL: ${url}\nError: ${error}`;
let detail = `URL: ${ url }\nError: ${ error }`;
if (this.isExisting(url)) {
detail = i18n.__('Certificate_error_different', detail);
}
......@@ -37,13 +37,13 @@ class CertificateStore {
dialog.showMessageBox(this.window, {
title: i18n.__('Certificate_error'),
message: i18n.__('Certificate_error_message', certificate.issuerName),
detail: detail,
detail,
type: 'warning',
buttons: [
i18n.__('Yes'),
i18n.__('No')
i18n.__('No'),
],
cancelId: 1
cancelId: 1,
}, (response) => {
if (response === 0) {
this.add(url, certificate);
......@@ -52,14 +52,14 @@ class CertificateStore {
webContents.send('certificate-reload', url);
}
}
//Call all queued callbacks with result
this.queued[certificate.fingerprint].forEach(cb => cb(response === 0));
// Call all queued callbacks with result
this.queued[certificate.fingerprint].forEach((cb) => cb(response === 0));
delete this.queued[certificate.fingerprint];
});
});
}
load () {
load() {
try {
this.data = this.userDataDir.read(this.storeFileName, 'json');
} catch (e) {
......@@ -72,34 +72,34 @@ class CertificateStore {
}
}
clear () {
clear() {
this.data = {};
this.save();
}
save () {
save() {
this.userDataDir.write(this.storeFileName, this.data, { atomic: true });
}
parseCertificate (certificate) {
return certificate.issuerName + '\n' + certificate.data.toString();
parseCertificate(certificate) {
return `${ certificate.issuerName }\n${ certificate.data.toString() }`;
}
getHost (certUrl) {
getHost(certUrl) {
return url.parse(certUrl).host;
}
add (certUrl, certificate) {
add(certUrl, certificate) {
const host = this.getHost(certUrl);
this.data[host] = this.parseCertificate(certificate);
}
isExisting (certUrl) {
isExisting(certUrl) {
const host = this.getHost(certUrl);
return this.data.hasOwnProperty(host);
}
isTrusted (certUrl, certificate) {
isTrusted(certUrl, certificate) {
const host = this.getHost(certUrl);
if (!this.isExisting(certUrl)) {
return false;
......
......@@ -18,7 +18,7 @@ const mainWindowOptions = {
minWidth: 600,
minHeight: 400,
titleBarStyle: 'hidden',
show: false
show: false,
};
const attachWindowStateHandling = (mainWindow) => {
......@@ -41,7 +41,7 @@ const attachWindowStateHandling = (mainWindow) => {
mainWindowState.saveState(mainWindow);
});
mainWindow.on('close', function (event) {
mainWindow.on('close', function(event) {
if (!mainWindow) {
return;
}
......@@ -95,7 +95,7 @@ export const createMainWindow = (cb) => {
const appUrl = url.format({
pathname: path.join(__dirname, 'public', 'app.html'),
protocol: 'file:',
slashes: true
slashes: true,
});
mainWindow.loadURL(appUrl);
......
......@@ -7,12 +7,12 @@ ipcMain.on('screenshare', (event, sources) => {
width: 776,
height: 600,
show : false,
skipTaskbar: false
skipTaskbar: false,
});
mainWindow.loadURL('file://'+__dirname+'/../public/screenshare.html');
mainWindow.loadURL(`file://${ __dirname }/../public/screenshare.html`);
//window.openDevTools();
// window.openDevTools();
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('sources', sources);
mainWindow.show();
......
......@@ -3,16 +3,16 @@ import { app } from 'electron';
let servers = {};
export default {
loadServers (s) {
loadServers(s) {
servers = s;
},
getServers () {
getServers() {
return servers;
}
},
};
app.on('login', function (event, webContents, request, authInfo, callback) {
app.on('login', function(event, webContents, request, authInfo, callback) {
for (const url of Object.keys(servers)) {
const server = servers[url];
if (request.url.indexOf(url) === 0 && server.username) {
......
......@@ -6,15 +6,15 @@ import { app } from 'electron';
import jetpack from 'fs-jetpack';
import { debounce } from 'lodash';
export default function (name, defaults) {
export default function(name, defaults) {
let state = {
width: defaults.width,
height: defaults.height
height: defaults.height,
};
const userDataDir = jetpack.cwd(app.getPath('userData'));
const stateStoreFile = `window-state-${name}.json`;
const stateStoreFile = `window-state-${ name }.json`;
try {
state = userDataDir.read(stateStoreFile, 'json') || state;
......@@ -23,7 +23,7 @@ export default function (name, defaults) {
console.error(err);
}
const saveState = function (window) {
const saveState = function(window) {
if (window.isDestroyed()) {
return;
}
......@@ -33,14 +33,14 @@ export default function (name, defaults) {
state.isHidden = !window.isMinimized() && !window.isVisible();
if (!state.isMaximized && !state.isHidden) {
[ state.x, state.y ] = window.getPosition();
[ state.width, state.height ] = window.getSize();
[state.x, state.y] = window.getPosition();
[state.width, state.height] = window.getSize();
}
userDataDir.write(stateStoreFile, state, { atomic: true });
};
const loadState = function (window) {
const loadState = function(window) {
if (this.x !== undefined && this.y !== undefined) {
window.setPosition(this.x, this.y, false);
}
......@@ -55,14 +55,14 @@ export default function (name, defaults) {
};
return {
get x () { return state.x && Math.floor(state.x); },
get y () { return state.y && Math.floor(state.y); },
get width () { return state.width && Math.floor(state.width); },
get height () { return state.height && Math.floor(state.height); },
get isMaximized () { return state.isMaximized; },
get isMinimized () { return state.isMinimized; },
get isHidden () { return state.isHidden; },
get x() { return state.x && Math.floor(state.x); },
get y() { return state.y && Math.floor(state.y); },
get width() { return state.width && Math.floor(state.width); },
get height() { return state.height && Math.floor(state.height); },
get isMaximized() { return state.isMaximized; },
get isMinimized() { return state.isMinimized; },
get isHidden() { return state.isHidden; },
saveState: debounce(saveState, 1000), // see https://github.com/RocketChat/Rocket.Chat.Electron/issues/181
loadState
loadState,
};
}
......@@ -6,17 +6,17 @@
import { app, BrowserWindow, screen } from 'electron';
import jetpack from 'fs-jetpack';
export default function (name, options) {
export default function(name, options) {
const userDataDir = jetpack.cwd(app.getPath('userData'));
const stateStoreFile = 'window-state-' + name +'.json';
const stateStoreFile = `window-state-${ name }.json`;
const defaultSize = {
width: options.width,
height: options.height
height: options.height,
};
let state = {};
const win = new BrowserWindow(Object.assign({}, options, state));
const restore = function () {
const restore = function() {
let restoredState = {};
try {
restoredState = userDataDir.read(stateStoreFile, 'json');
......@@ -27,34 +27,34 @@ export default function (name, options) {
return Object.assign({}, defaultSize, restoredState);
};
const getCurrentPosition = function () {
const getCurrentPosition = function() {
const position = win.getPosition();
const size = win.getSize();
return {
x: Math.floor(position[0]),
y: Math.floor(position[1]),
width: Math.floor(size[0]),
height: Math.floor(size[1])
height: Math.floor(size[1]),
};
};
const windowWithinBounds = function (windowState, bounds) {
const windowWithinBounds = function(windowState, bounds) {
return windowState.x >= bounds.x &&
windowState.y >= bounds.y &&
windowState.x + windowState.width <= bounds.x + bounds.width &&
windowState.y + windowState.height <= bounds.y + bounds.height;
};
const resetToDefaults = function (/*windowState*/) {
const bounds = screen.getPrimaryDisplay().bounds;
const resetToDefaults = function(/* windowState*/) {
const { bounds } = screen.getPrimaryDisplay();
return Object.assign({}, defaultSize, {
x: (bounds.width - defaultSize.width) / 2,
y: (bounds.height - defaultSize.height) / 2
y: (bounds.height - defaultSize.height) / 2,
});
};
const ensureVisibleOnSomeDisplay = function (windowState) {
const visible = screen.getAllDisplays().some(function (display) {
const ensureVisibleOnSomeDisplay = function(windowState) {
const visible = screen.getAllDisplays().some(function(display) {
return windowWithinBounds(windowState, display.bounds);
});
if (!visible) {
......@@ -65,7 +65,7 @@ export default function (name, options) {
return windowState;
};
const saveState = function () {
const saveState = function() {
if (!win.isMinimized() && !win.isMaximized()) {
Object.assign(state, getCurrentPosition());
}
......
......@@ -13,15 +13,15 @@ let loadedLanguage = [];
* @param {number} chount Count to check for singular / plural (0-1,2-n)
* @returns {string} Translation in user language
*/
function loadTranslation (phrase = '', count) {
function loadTranslation(phrase = '', count) {
const loadedLanguageTranslation = loadedLanguage[phrase];
let translation = loadedLanguageTranslation;
if (loadedLanguageTranslation === undefined) {
translation = phrase;
} else if (loadedLanguageTranslation instanceof Object) {
translation = loadedLanguageTranslation['one'];
translation = loadedLanguageTranslation.one;
if (count > 1) {
translation = loadedLanguageTranslation['multi'];
translation = loadedLanguageTranslation.multi;
}
}
return translation;
......@@ -32,14 +32,14 @@ class I18n {
* Load users language if available, and fallback to english for any missing strings
* @constructor
*/
constructor () {
constructor() {
let dir = path.join(__dirname, '../i18n/lang');
if (!fs.existsSync(dir)) {
dir = path.join(__dirname, 'i18n/lang');
}
const defaultLocale = path.join(dir, 'en.i18n.json');
loadedLanguage = JSON.parse(fs.readFileSync(defaultLocale, 'utf8'));
const locale = path.join(dir, `${eApp.getLocale()}.i18n.json`);
const locale = path.join(dir, `${ eApp.getLocale() }.i18n.json`);
if (fs.existsSync(locale)) {
const lang = JSON.parse(fs.readFileSync(locale, 'utf8'));
loadedLanguage = Object.assign(loadedLanguage, lang);
......@@ -52,7 +52,7 @@ class I18n {
* @param {...string|number} replacements List of replacements in template strings
* @return {string} Translation in users language
*/
__ (phrase, ...replacements) {
__(phrase, ...replacements) {
const translation = loadTranslation(phrase, 0);
return util.format(translation, ...replacements);
}
......@@ -64,7 +64,7 @@ class I18n {
* @param {...string|number} replacements List of replacements in template strings
* @return {string} Translation in users language
*/
pluralize (phrase, count, ...replacements) {
pluralize(phrase, count, ...replacements) {
const translation = loadTranslation(phrase, count);
return util.format(translation, ...replacements);
}
......
......@@ -2,36 +2,35 @@
// in all input fields and textareas across your app.
const i18n = require('../../i18n');
(function () {
(function() {
'use strict';
const remote = require('electron').remote;
const Menu = remote.Menu;
const MenuItem = remote.MenuItem;
const { remote } = require('electron');
const { Menu, MenuItem } = remote;
const isAnyTextSelected = function () {
const isAnyTextSelected = function() {
return window.getSelection().toString() !== '';
};
const cut = new MenuItem({
label: i18n.__('Cut'),
click: function () {
document.execCommand("cut");
}
click() {
document.execCommand('cut');
},
});
const copy = new MenuItem({
label: i18n.__('Copy'),
click: function () {
document.execCommand("copy");
}
click() {
document.execCommand('copy');
},
});
const paste = new MenuItem({
label: i18n.__('Paste'),
click: function () {
document.execCommand("paste");
}
click() {
document.execCommand('paste');
},
});
const normalMenu = new Menu();
......@@ -42,7 +41,7 @@ const i18n = require('../../i18n');
textEditingMenu.append(copy);
textEditingMenu.append(paste);
document.addEventListener('contextmenu', function (e) {
document.addEventListener('contextmenu', function(e) {
switch (e.target.nodeName) {
case 'TEXTAREA':
case 'INPUT':
......
......@@ -21,7 +21,7 @@ selfBrowserWindow.webContents.once('dom-ready', () => {
* default electron will return images with height and width of
* 150px.
*/
obtainDesktopStreams (callback, errorCallback, options = {}) {
obtainDesktopStreams(callback, errorCallback, options = {}) {
electron.desktopCapturer.getSources(options,
(error, sources) => {
if (error) {
......@@ -31,6 +31,6 @@ selfBrowserWindow.webContents.once('dom-ready', () => {
callback(sources);
});
}
},
};
});
......@@ -3,33 +3,33 @@ const { ipcRenderer, remote } = require('electron');
if (process.platform === 'darwin') {
const NodeNotification = require('node-mac-notifier');
window.Notification = class Notification extends NodeNotification {
constructor (title, options) {
options.bundleId = `chat.rocket`;
constructor(title, options) {
options.bundleId = 'chat.rocket';
super(title, options);
this.addEventListener('click', (/*notification*/) => this.onclick());
this.addEventListener('click', (/* notification*/) => this.onclick());
}
static requestPermission () {
static requestPermission() {
return;
}
static get permission () {
static get permission() {
return 'granted';
}
};
}
class Notification extends window.Notification {
constructor (title, options) {
constructor(title, options) {
super(title, options);
ipcRenderer.send('notification-shim', title, options);
// Handle correct notification using unique tag
ipcRenderer.once(`clicked-${options.tag}`, () => this.onclick());
ipcRenderer.once(`clicked-${ options.tag }`, () => this.onclick());
}
get onclick () {
get onclick() {
return super.onclick;
}
......@@ -44,8 +44,8 @@ class Notification extends window.Notification {
}
*/
set onclick (fn) {
const result = super.onclick = () => {
set onclick(fn) {
const result = super.onclick = (...args) => {
const currentWindow = remote.getCurrentWindow();
if (process.platform === 'win32') {
if (currentWindow.isVisible()) {
......@@ -62,7 +62,7 @@ class Notification extends window.Notification {
}
ipcRenderer.sendToHost('focus');
fn.apply(this, arguments);
fn.apply(this, args);
};
return result;
}
......
......@@ -13,14 +13,16 @@ const isWindows = ['win32', 'win64'].indexOf(os.platform()) !== -1;
class SpellCheck {
get userLanguage () {
get userLanguage() {
const lang = localStorage.getItem('userLanguage');
if (lang) {
return lang.replace('-', '_');
}
return undefined;
}
get dictionaries () {
get dictionaries() {
const dictionaries = localStorage.getItem('spellcheckerDictionaries');
if (dictionaries) {
const result = JSON.parse(dictionaries);
......@@ -28,9 +30,11 @@ class SpellCheck {
return result;
}
}
return undefined;
}
constructor () {
constructor() {
this.enabledDictionaries = [];
this.contractions = this.getContractions();
this.loadAvailableDictionaries();
......@@ -59,10 +63,10 @@ class SpellCheck {
this.disable(dictionary);
}
this.saveEnabledDictionaries();
}
},
};
return menu;
})
}),
};
this.browseForLanguageMenu = new MenuItem({
......@@ -71,12 +75,12 @@ class SpellCheck {
dialog.showOpenDialog({
title: i18n.__('Open_Language_Dictionary'),
defaultPath: this.dictionariesPath,
filters: {name: 'Dictionaries', extensions: ['aff', 'dic']},
properties: ['openFile', 'multiSelections']
filters: { name: 'Dictionaries', extensions: ['aff', 'dic'] },
properties: ['openFile', 'multiSelections'],
},
(filePaths) => { this.installDictionariesFromPaths(filePaths); }
);
}