xo: Enable padding-line-between-statements.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-04-25 15:04:48 -07:00
committed by Anders Kaseorg
parent cfdc08a038
commit 5ae2a717fa
31 changed files with 92 additions and 1 deletions

View File

@@ -98,6 +98,7 @@ function createMainWindow(): Electron.BrowserWindow {
if (ConfigUtil.getConfigItem('quitOnClose')) {
app.quit();
}
if (!isQuitting) {
event.preventDefault();
@@ -334,6 +335,7 @@ app.on('ready', () => {
item.cancel();
return;
}
setFilePath = result.filePath;
shortFileName = path.basename(setFilePath);
} else {
@@ -366,18 +368,22 @@ app.on('ready', () => {
item.cancel();
break;
}
case 'progressing': {
if (item.isPaused()) {
item.cancel();
}
// This event can also be used to show progress in percentage in future.
break;
}
default: {
console.info('Unknown updated state of download item');
}
}
};
item.on('updated', updatedListener);
item.once('done', (_event: Event, state) => {
if (state === 'completed') {
@@ -386,6 +392,7 @@ app.on('ready', () => {
console.log('Download failed state:', state);
page.send('downloadFileFailed');
}
// To stop item for listening to updated events of this file
item.removeListener('updated', updatedListener);
});

View File

@@ -30,6 +30,7 @@ export function linuxUpdateNotification(): void {
logger.error(error);
return;
}
if (response.statusCode < 400) {
const data = JSON.parse(body);
const latestVersion = ConfigUtil.getConfigItem('betaUpdate') ? data[0].tag_name : data.tag_name;

View File

@@ -567,6 +567,7 @@ function getNextServer(tabs: any[], activeTabIndex: number): number {
activeTabIndex = (activeTabIndex + 1) % tabs.length;
}
while (tabs[activeTabIndex].props.role !== 'server');
return activeTabIndex;
}
@@ -575,6 +576,7 @@ function getPreviousServer(tabs: any[], activeTabIndex: number): number {
activeTabIndex = (activeTabIndex - 1 + tabs.length) % tabs.length;
}
while (tabs[activeTabIndex].props.role !== 'server');
return activeTabIndex;
}

View File

@@ -48,6 +48,7 @@ export default function handleExternalLink(this: WebView, event: Electron.NewWin
} else {
this.$el.downloadURL(url.href);
}
ipcRenderer.removeAllListeners('downloadFileCompleted');
});
} else {

View File

@@ -97,6 +97,7 @@ export default class WebView extends BaseComponent {
if (isSettingPage) {
return;
}
this.canGoBackButton();
});
@@ -123,6 +124,7 @@ export default class WebView extends BaseComponent {
if (this.props.role === 'server') {
this.$el.classList.add('onload');
}
this.loading = false;
this.props.switchLoading(false, this.props.url);
this.show();

View File

@@ -73,6 +73,7 @@
if (!(symbol in this)) {
this.addEventListener(type, listener);
}
(this as any)[symbol] = value;
} else if (symbol in this) {
this.removeEventListener(type, listener);
@@ -107,6 +108,7 @@
if (callback) {
callback(await Promise.resolve(NativeNotification.permission));
}
return NativeNotification.permission;
}
}

View File

@@ -144,6 +144,7 @@ class ServerManagerView {
if (EnterpriseUtil.configFile) {
await this.initPresetOrgs();
}
await this.initTabs();
this.initActions();
this.registerIpcs();
@@ -157,6 +158,7 @@ class ServerManagerView {
if (proxyEnableOldState) {
ConfigUtil.setConfigItem('useManualProxy', true);
}
ConfigUtil.removeConfigItem('useProxy');
}
@@ -272,8 +274,10 @@ class ServerManagerView {
if (DomainUtil.duplicateDomain(url)) {
continue;
}
domainPromises.push(this.queueDomain(url));
}
const domainsAdded = await Promise.all(domainPromises);
if (domainsAdded.includes(true)) {
// at least one domain was resolved
@@ -299,8 +303,10 @@ class ServerManagerView {
if (DomainUtil.duplicateDomain(org)) {
continue;
}
failedDomains.push(org);
}
const { title, content } = Messages.enterpriseOrgError(domainsAdded.length, failedDomains);
dialog.showErrorBox(title, content);
if (DomainUtil.getDomains().length === 0) {
@@ -316,11 +322,13 @@ class ServerManagerView {
for (const [i, server] of servers.entries()) {
this.initServer(server, i);
}
// Open last active tab
let lastActiveTab = ConfigUtil.getConfigItem('lastActiveTab');
if (lastActiveTab >= servers.length) {
lastActiveTab = 0;
}
// checkDomain() and webview.load() for lastActiveTab before the others
await DomainUtil.updateSavedServer(servers[lastActiveTab].url, lastActiveTab);
this.activateTab(lastActiveTab);
@@ -330,6 +338,7 @@ class ServerManagerView {
if (i === lastActiveTab) {
return;
}
await DomainUtil.updateSavedServer(server.url, i);
this.tabs[i].webview.load();
}));
@@ -373,6 +382,7 @@ class ServerManagerView {
} else if (loading && !this.loading[url]) {
this.loading[url] = true;
}
this.showLoading(this.loading[this.tabs[this.activeTabIndex].webview.props.url]);
},
onNetworkError: (index: number) => this.openNetworkTroubleshooting(index),
@@ -397,6 +407,7 @@ class ServerManagerView {
if ($serverImg.src.includes('img/icon.png')) {
this.displayInitialCharLogo($serverImg, index);
}
$serverImg.addEventListener('error', () => {
this.displayInitialCharLogo($serverImg, index);
});
@@ -539,6 +550,7 @@ class ServerManagerView {
} else if (loading && !this.loading[url]) {
this.loading[url] = true;
}
this.showLoading(this.loading[this.tabs[this.activeTabIndex].webview.props.url]);
},
onNetworkError: (index: number) => this.openNetworkTroubleshooting(index),
@@ -619,6 +631,7 @@ class ServerManagerView {
if (this.tabs[this.activeTabIndex].props.role === 'function' && this.tabs[this.activeTabIndex].props.name === 'Settings') {
this.$settingsButton.classList.remove('active');
}
this.tabs[this.activeTabIndex].deactivate();
}
}
@@ -908,6 +921,7 @@ class ServerManagerView {
});
return;
}
this.updateGeneralSettings('toggle-menubar-setting', autoHideMenubar);
});
@@ -1001,8 +1015,10 @@ class ServerManagerView {
ctx.font = '85px Helvetica';
ctx.fillText(String(Math.min(99, messageCount)), 64, 90);
}
return canvas;
}
ipcRenderer.send('update-taskbar-icon', createOverlayIcon(messageCount).toDataURL(), String(messageCount));
});

View File

@@ -73,6 +73,7 @@ const webContentsId = webContents.id;
export function focusCurrentServer(): void {
currentWindow.webContents.send('focus-webview-with-id', webContentsId);
}
// this function parses the reply from to notification
// making it easier to reply from notification eg
// @username in reply will be converted to @**username**

View File

@@ -47,6 +47,7 @@ export function newNotification(
}
});
}
return {
close: () => notification.close(),
title: notification.title,

View File

@@ -59,6 +59,7 @@ export default class AddCertificate extends BaseComponent {
if (!copy) {
return;
}
CertificateUtil.setCertificate(server, fileName);
this.serverUrl.value = '';
await dialog.showMessageBox({

View File

@@ -30,6 +30,7 @@ function updateOverlayIcon(messageCount: number, mainWindow: electron.BrowserWin
if (!mainWindow.isFocused()) {
mainWindow.flashFrame(ConfigUtil.getConfigItem('flashTaskbarOnMessage'));
}
if (messageCount === 0) {
mainWindow.setOverlayIcon(null, '');
} else {

View File

@@ -44,9 +44,11 @@ export default class FindAccounts extends BaseComponent {
if (!url) {
return;
}
if (!url.startsWith('http')) {
url = 'https://' + url;
}
await LinkUtil.openBrowser(new URL('/accounts/find', url));
}

View File

@@ -178,6 +178,7 @@ export default class GeneralSection extends BaseSection {
if (process.platform === 'win32') {
this.updateFlashTaskbar();
}
// Dock bounce on macOS
if (process.platform === 'darwin') {
this.updateDockBouncing();
@@ -264,6 +265,7 @@ export default class GeneralSection extends BaseSection {
ConfigUtil.setConfigItem('betaUpdate', false);
this.betaUpdateOption();
}
this.autoUpdateOption();
}
});

View File

@@ -105,11 +105,13 @@ export default class NetworkSection extends BaseSection {
ConfigUtil.setConfigItem('useManualProxy', !manualProxyValue);
this.toggleManualProxySettings(!manualProxyValue);
}
if (!newValue) {
// Remove proxy system proxy settings
ConfigUtil.setConfigItem('proxyRules', '');
ipcRenderer.send('forward-message', 'reload-proxy', false);
}
ConfigUtil.setConfigItem('useSystemProxy', newValue);
this.updateProxyOption();
}
@@ -124,6 +126,7 @@ export default class NetworkSection extends BaseSection {
if (systemProxyValue && newValue) {
ConfigUtil.setConfigItem('useSystemProxy', !systemProxyValue);
}
ConfigUtil.setConfigItem('proxyRules', '');
ConfigUtil.setConfigItem('useManualProxy', newValue);
// Reload app only when turning manual proxy off, hence !newValue

View File

@@ -71,6 +71,7 @@ export default class NewServerForm extends BaseComponent {
alert(error);
return;
}
await DomainUtil.addDomain(serverConf);
this.props.onChange();
}

View File

@@ -37,6 +37,7 @@ export default class PreferenceView extends BaseComponent {
if (hasTag) {
nav = hasTag.slice(1);
}
this.handleNavigation(nav);
}
@@ -49,32 +50,38 @@ export default class PreferenceView extends BaseComponent {
});
break;
}
case 'General': {
this.section = new GeneralSection({
$root: this.$settingsContainer
});
break;
}
case 'Organizations': {
this.section = new ConnectedOrgSection({
$root: this.$settingsContainer
});
break;
}
case 'Network': {
this.section = new NetworkSection({
$root: this.$settingsContainer
});
break;
}
case 'Shortcuts': {
this.section = new ShortcutsSection({
$root: this.$settingsContainer
});
break;
}
default: break;
}
this.section.init();
window.location.hash = `#${navItem}`;
}

View File

@@ -60,6 +60,7 @@ electron_bridge.once('zulip-loaded', ({ serverLanguage }) => {
// Init spellchecker
SetupSpellChecker.init(serverLanguage);
}
// redirect users to network troubleshooting page
const getRestartButton = document.querySelector('.restart_get_events_button');
if (getRestartButton) {
@@ -79,6 +80,7 @@ window.addEventListener('load', (event: any): void => {
if (!event.target.URL.includes('app/renderer/network.html')) {
return;
}
const $reconnectButton = document.querySelector('#reconnect');
const $settingsButton = document.querySelector('#settings');
NetworkError.init($reconnectButton, $settingsButton);
@@ -105,6 +107,7 @@ ipcRenderer.on('set-active', () => {
if (isDev) {
console.log('active');
}
electron_bridge.idle_on_system = false;
electron_bridge.last_active_on_system = Date.now();
});
@@ -114,6 +117,7 @@ ipcRenderer.on('set-idle', () => {
if (isDev) {
console.log('idle');
}
electron_bridge.idle_on_system = true;
});

View File

@@ -23,6 +23,7 @@ export function init(serverLanguage: string): void {
if (ConfigUtil.getConfigItem('enableSpellchecker')) {
enableSpellChecker();
}
enableContextMenu(serverLanguage);
}
@@ -53,6 +54,7 @@ export function unsubscribeSpellChecker(): void {
if (spellCheckHandler) {
spellCheckHandler.unsubscribe();
}
if (contextMenuListener) {
contextMenuListener.unsubscribe();
}

View File

@@ -20,6 +20,7 @@ const iconPath = (): string => {
if (process.platform === 'linux') {
return APP_ICON + 'linux.png';
}
return APP_ICON + (process.platform === 'win32' ? 'win.ico' : 'osx.png');
};
@@ -92,6 +93,7 @@ const renderCanvas = function (arg: number): HTMLCanvasElement {
return canvas;
};
/**
* Renders the tray icon as a native image
* @param arg: Unread count
@@ -168,6 +170,7 @@ ipcRenderer.on('tray', (_event: Event, arg: number): void => {
if (!tray) {
return;
}
// We don't want to create tray from unread messages on macOS since it already has dock badges.
if (process.platform === 'linux' || process.platform === 'win32') {
if (arg === 0) {
@@ -191,6 +194,7 @@ function toggleTray(): void {
if (tray.isDestroyed()) {
tray = null;
}
ConfigUtil.setConfigItem('trayIcon', false);
} else {
state = true;
@@ -200,8 +204,10 @@ function toggleTray(): void {
tray.setImage(image);
tray.setToolTip(unread + ' unread messages');
}
ConfigUtil.setConfigItem('trayIcon', true);
}
const selector = 'webview:not([class*=disabled])';
const webview: WebviewTag = document.querySelector(selector);
const webContents = webview.getWebContents();

View File

@@ -46,6 +46,7 @@ export function copyCertificate(_server: string, location: string, fileName: str
logger.error('Error while copying the certificate to certificates folder.');
logger.error(error);
}
return copied;
}
@@ -76,5 +77,6 @@ function reloadDB(): void {
logger.error(error);
}
}
db = new JsonDB(settingsJsonPath, true, true);
}

View File

@@ -35,6 +35,7 @@ export function getConfigItem(key: string, defaultValue: any = null): any {
logger.error('Error while reloading settings.json: ');
logger.error(error);
}
const value = db.getData('/')[key];
if (value === undefined) {
setConfigItem(key, defaultValue);
@@ -52,6 +53,7 @@ export function isConfigItemExists(key: string): boolean {
logger.error('Error while reloading settings.json: ');
logger.error(error);
}
const value = db.getData('/')[key];
return (value !== undefined);
}
@@ -61,6 +63,7 @@ export function setConfigItem(key: string, value: any, override? : boolean): voi
// if item is in global config and we're not trying to override
return;
}
db.push(`/${key}`, value, true);
db.save();
}
@@ -87,5 +90,6 @@ function reloadDB(): void {
logger.reportSentry(error);
}
}
db = new JsonDB(settingsJsonPath, true, true);
}

View File

@@ -62,6 +62,7 @@ export function shouldIgnoreCerts(url: string): boolean {
return domain.ignoreCerts;
}
}
return null;
}
@@ -93,6 +94,7 @@ export function removeDomain(index: number): boolean {
if (EnterpriseUtil.isPresetOrg(getDomain(index).url)) {
return false;
}
db.delete(`/domains[${index}]`);
reloadDB();
return true;
@@ -131,6 +133,7 @@ async function checkCertError(domain: string, serverConf: ServerConf, error: str
if (error === Messages.noOrgsError(domain)) {
throw new Error(error);
}
return serverConf;
}
} else {
@@ -278,6 +281,7 @@ export function reloadDB(): void {
logger.reportSentry(error);
}
}
db = new JsonDB(domainJsonPath, true, true);
}
@@ -304,8 +308,10 @@ export function formatUrl(domain: string): string {
if (domain.startsWith('http://') || domain.startsWith('https://')) {
return domain;
}
if (domain.startsWith('localhost:')) {
return `http://${domain}`;
}
return `https://${domain}`;
}

View File

@@ -40,9 +40,11 @@ export function getConfigItem(key: string, defaultValue?: any): any {
if (!configFile) {
return defaultValue;
}
if (defaultValue === undefined) {
defaultValue = null;
}
return configItemExists(key) ? enterpriseSettings[key] : defaultValue;
}
@@ -51,6 +53,7 @@ export function configItemExists(key: string): boolean {
if (!configFile) {
return false;
}
return (enterpriseSettings[key] !== undefined);
}
@@ -58,11 +61,13 @@ export function isPresetOrg(url: string): boolean {
if (!configFile || !configItemExists('presetOrganizations')) {
return false;
}
const presetOrgs = enterpriseSettings.presetOrganizations;
for (const org of presetOrgs) {
if (url.includes(org)) {
return true;
}
}
return false;
}

View File

@@ -57,5 +57,6 @@ function reloadDB(): void {
logger.error(error);
}
}
db = new JsonDB(linuxUpdateJsonPath, true, true);
}

View File

@@ -138,6 +138,7 @@ export default class Logger {
if (err) {
throw err;
}
const MAX_LOG_FILE_LINES = 500;
const logs = data.split(os.EOL);
const logLength = logs.length - 1;

View File

@@ -61,6 +61,7 @@ export async function resolveSystemProxy(mainWindow: Electron.BrowserWindow): Pr
httpString = 'http=' + proxy.split('PROXY')[1] + ';';
}
}
return httpString;
})();
// Check HTTPS Proxy
@@ -74,6 +75,7 @@ export async function resolveSystemProxy(mainWindow: Electron.BrowserWindow): Pr
httpsString += 'https=' + proxy.split('PROXY')[1] + ';';
}
}
return httpsString;
})();
@@ -86,6 +88,7 @@ export async function resolveSystemProxy(mainWindow: Electron.BrowserWindow): Pr
ftpString += 'ftp=' + proxy.split('PROXY')[1] + ';';
}
}
return ftpString;
})();
@@ -102,6 +105,7 @@ export async function resolveSystemProxy(mainWindow: Electron.BrowserWindow): Pr
socksString += 'socks=' + proxy.split('PROXY')[1] + ';';
}
}
return socksString;
})();

View File

@@ -39,6 +39,7 @@ export default class ReconnectUtil {
if (ignoreCerts === null) {
return;
}
request(
{
url: `${this.url}/static/favicon.ico`,
@@ -71,11 +72,13 @@ export default class ReconnectUtil {
if (this.alreadyReloaded) {
return true;
}
if (await this.isOnline()) {
ipcRenderer.send('forward-message', 'reload-viewer');
logger.log('You\'re back online.');
return true;
}
logger.log('There is no internet connection, try checking network cables, modem and router.');
const errorMessageHolder = document.querySelector('#description');
if (errorMessageHolder) {
@@ -83,6 +86,7 @@ export default class ReconnectUtil {
<div>Your internet connection doesn't seem to work properly!</div>
<div>Verify that it works and then click try again.</div>`;
}
return false;
}
}

View File

@@ -48,6 +48,7 @@ export function requestOptions(domain: string, ignoreCerts: boolean): RequestUti
logger.warn(`Error while trying to get certificate: ${error}`);
}
}
const proxyEnabled = ConfigUtil.getConfigItem('useManualProxy') || ConfigUtil.getConfigItem('useSystemProxy');
// If certificate for the domain exists add it as a ca key in the request's parameter else consider only domain as the parameter for request
// Add proxy as a parameter if it is being used.

View File

@@ -29,6 +29,7 @@ export function getOS(): string {
return '';
}
}
export function getUserAgent(): string {
return userAgent;
}

View File

@@ -34,6 +34,7 @@ export function enterpriseOrgError(length: number, domains: string[]): DialogBox
for (const domain of domains) {
domainList += `${domain}\n`;
}
return {
title: `Could not add the following ${length === 1 ? 'organization' : 'organizations'}`,
content: `${domainList}\nPlease contact your system administrator.`

View File

@@ -223,7 +223,6 @@
"no-else-return": "off",
"no-warning-comments": "off",
"object-curly-spacing": "off",
"padding-line-between-statements": "off",
"strict": "error",
"unicorn/string-content": "off"
},