lint: use rules from .eslintrc

This commit is contained in:
George Lima 2018-11-26 17:19:12 -03:00
parent c84fe27386
commit 67313a95ba
2 changed files with 67 additions and 64 deletions

View File

@ -1,47 +1,50 @@
// @flow
import path from 'path'
import path from 'path';
import { app, BrowserWindow, powerMonitor, Tray } from 'electron'
import { autoUpdater } from 'electron-updater'
import log from 'electron-log'
import Positioner from 'electron-positioner'
import isDev from 'electron-is-dev'
/* eslint-disable import/no-extraneous-dependencies */
import {
app, BrowserWindow, powerMonitor, Tray,
} from 'electron';
import { autoUpdater } from 'electron-updater';
import Positioner from 'electron-positioner';
import isDev from 'electron-is-dev';
/* eslint-enable import/no-extraneous-dependencies */
import { registerDebugShortcut } from '../utils/debugShortcut'
import type { BrowserWindow as BrowserWindowType, Tray as TrayType } from 'electron';
import type { BrowserWindow as BrowserWindowType, Tray as TrayType } from 'electron'
import { registerDebugShortcut } from '../utils/debugShortcut';
let mainWindow: BrowserWindowType
let tray: TrayType
let updateAvailable = false
let mainWindow: BrowserWindowType;
let tray: TrayType;
let updateAvailable = false;
const showStatus = text => {
if (text === 'Update downloaded') updateAvailable = true
const showStatus = (text) => {
if (text === 'Update downloaded') updateAvailable = true;
mainWindow.webContents.send('update', {
updateAvailable,
updateInfo: text,
})
}
});
};
function createWindow() {
autoUpdater.checkForUpdatesAndNotify()
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on('checking-for-update', () => showStatus('Checking for update'))
autoUpdater.on('update-available', () => showStatus('Update available'))
autoUpdater.on('update-not-available', () => showStatus('No updates available'))
autoUpdater.on('error', err => showStatus(`Error while updating: ${err}`))
autoUpdater.on('download-progress', progress =>
showStatus(`
Download speed: ${progress.bytesPerSecond} - Downloaded ${progress.percent}% (${progress.transferred}/${
autoUpdater.on('checking-for-update', () => showStatus('Checking for update'));
autoUpdater.on('update-available', () => showStatus('Update available'));
autoUpdater.on('update-not-available', () => showStatus('No updates available'));
autoUpdater.on('error', err => showStatus(`Error while updating: ${err}`));
autoUpdater.on('download-progress', progress => showStatus(
/* eslint-disable-next-line max-len */
`Download speed: ${progress.bytesPerSecond} - Downloaded ${progress.percent}% (${progress.transferred}/${
progress.total
})
`),
)
})`,
));
autoUpdater.on('update-downloaded', () => {
updateAvailable = true
showStatus('Update downloaded')
})
updateAvailable = true;
showStatus('Update downloaded');
});
mainWindow = new BrowserWindow({
width: 800,
@ -53,52 +56,52 @@ function createWindow() {
devTools: true,
webSecurity: false,
},
})
});
mainWindow.setVisibleOnAllWorkspaces(true)
mainWindow.setVisibleOnAllWorkspaces(true);
// TODO: Update to right icon location
tray = new Tray(path.join(__dirname, '../public/images', 'zcash-icon.png'))
tray = new Tray(path.join(__dirname, '../public/images', 'zcash-icon.png'));
registerDebugShortcut(app, mainWindow)
registerDebugShortcut(app, mainWindow);
tray.setToolTip('ZCash')
mainWindow.loadURL(isDev ? 'http://0.0.0.0:8080/' : `file://${path.join(__dirname, '../dist/index.html')}`)
tray.setToolTip('ZCash');
mainWindow.loadURL(isDev ? 'http://0.0.0.0:8080/' : `file://${path.join(__dirname, '../dist/index.html')}`);
const positioner = new Positioner(mainWindow)
let bounds = tray.getBounds()
positioner.move('trayCenter', bounds)
const positioner = new Positioner(mainWindow);
let bounds = tray.getBounds();
positioner.move('trayCenter', bounds);
powerMonitor.on('suspend', () => mainWindow.webContents.send('suspend', 'suspended'))
powerMonitor.on('resume', () => mainWindow.webContents.send('resume', 'resumed'))
powerMonitor.on('suspend', () => mainWindow.webContents.send('suspend', 'suspended'));
powerMonitor.on('resume', () => mainWindow.webContents.send('resume', 'resumed'));
mainWindow.once('ready-to-show', () => mainWindow.show())
mainWindow.on('blur', () => mainWindow.hide())
mainWindow.on('show', () => tray.setHighlightMode('always'))
mainWindow.on('hide', () => tray.setHighlightMode('never'))
mainWindow.once('ready-to-show', () => mainWindow.show());
mainWindow.on('blur', () => mainWindow.hide());
mainWindow.on('show', () => tray.setHighlightMode('always'));
mainWindow.on('hide', () => tray.setHighlightMode('never'));
mainWindow.on('closed', () => {
mainWindow = null
})
mainWindow = null;
});
tray.on('click', () => {
bounds = tray.getBounds()
positioner.move('trayCenter', bounds)
bounds = tray.getBounds();
positioner.move('trayCenter', bounds);
if (mainWindow.isVisible()) {
mainWindow.hide()
mainWindow.hide();
} else {
mainWindow.show()
mainWindow.show();
}
})
});
exports.app = app
exports.tray = tray
exports.app = app;
exports.tray = tray;
}
app.on('ready', createWindow)
app.on('ready', createWindow);
app.on('activate', () => {
if (mainWindow === null) createWindow()
})
if (mainWindow === null) createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
if (process.platform !== 'darwin') app.quit();
});

View File

@ -1,9 +1,9 @@
// @flow
import { globalShortcut } from 'electron'
/* eslint-disable import/no-extraneous-dependencies */
import { globalShortcut } from 'electron';
export const registerDebugShortcut = (app: Object, mainWindow: Object) =>
globalShortcut.register('CommandOrControl+Option+B', () => {
app.dock.show()
mainWindow.webContents.openDevTools()
})
export const registerDebugShortcut = (app: Object, mainWindow: Object) => globalShortcut.register('CommandOrControl+Option+B', () => {
app.dock.show();
mainWindow.webContents.openDevTools();
});