[WIP] Use XO instead of Standard (#723)

* Bump `eslint-plugin-react`

* Add `eslint-config-xo-react`

* Add XO

* Remove eslint-related dependencies, add XO config and use XO as the linter

* Code style: Standard => XO 

* Use xo property to ignore files

* Fix remaining errors
This commit is contained in:
Matheus Fernandes 2016-09-21 11:27:11 -03:00 committed by Leo Lamprecht
parent 32a665d7c0
commit 1866104d03
49 changed files with 910 additions and 784 deletions

View file

@ -1,12 +0,0 @@
# build output
dist
build
app/dist
# dependencies
node_modules
app/node_modules
# other
app/static
assets

View file

@ -1,13 +1,14 @@
const {autoUpdater} = require('electron'); const {autoUpdater} = require('electron');
const { version } = require('./package');
const notify = require('./notify'); // eslint-disable-line no-unused-vars
const ms = require('ms'); const ms = require('ms');
const notify = require('./notify'); // eslint-disable-line no-unused-vars
const {version} = require('./package');
// accepted values: `osx`, `win32` // accepted values: `osx`, `win32`
// https://nuts.gitbook.com/update-windows.html // https://nuts.gitbook.com/update-windows.html
const platform = 'darwin' === process.platform const platform = process.platform === 'darwin' ?
? 'osx' 'osx' :
: process.platform; process.platform;
const FEED_URL = `https://hyperterm-updates.now.sh/update/${platform}`; const FEED_URL = `https://hyperterm-updates.now.sh/update/${platform}`;
let isInit = false; let isInit = false;
@ -30,7 +31,9 @@ function init () {
} }
module.exports = function (win) { module.exports = function (win) {
if (!isInit) init(); if (!isInit) {
init();
}
const {rpc} = win; const {rpc} = win;

View file

@ -1,9 +1,10 @@
const { dialog } = require('electron');
const {homedir} = require('os'); const {homedir} = require('os');
const { resolve } = require('path');
const {readFileSync, writeFileSync} = require('fs'); const {readFileSync, writeFileSync} = require('fs');
const gaze = require('gaze'); const {resolve} = require('path');
const vm = require('vm'); const vm = require('vm');
const {dialog} = require('electron');
const gaze = require('gaze');
const notify = require('./notify'); const notify = require('./notify');
const path = resolve(homedir(), '.hyperterm.js'); const path = resolve(homedir(), '.hyperterm.js');
@ -13,12 +14,14 @@ let cfg = {};
function watch() { function watch() {
gaze(path, function (err) { gaze(path, function (err) {
if (err) throw err; if (err) {
throw err;
}
this.on('changed', () => { this.on('changed', () => {
try { try {
if (exec(readFileSync(path, 'utf8'))) { if (exec(readFileSync(path, 'utf8'))) {
notify('HyperTerm configuration reloaded!'); notify('HyperTerm configuration reloaded!');
watchers.forEach((fn) => fn()); watchers.forEach(fn => fn());
} }
} catch (err) { } catch (err) {
dialog.showMessageBox({ dialog.showMessageBox({
@ -32,7 +35,9 @@ function watch () {
let _str; // last script let _str; // last script
function exec(str) { function exec(str) {
if (str === _str) return false; if (str === _str) {
return false;
}
_str = str; _str = str;
const script = new vm.Script(str); const script = new vm.Script(str);
const module = {}; const module = {};

View file

@ -1,21 +1,28 @@
const { app, BrowserWindow, shell, Menu } = require('electron'); // Native
const createRPC = require('./rpc');
const createMenu = require('./menu');
const uuid = require('uuid');
const {resolve} = require('path'); const {resolve} = require('path');
// Packages
const {parse: parseUrl} = require('url'); const {parse: parseUrl} = require('url');
const {gitDescribe} = require('git-describe');
const {app, BrowserWindow, shell, Menu} = require('electron');
const uuid = require('uuid');
const fileUriToPath = require('file-uri-to-path'); const fileUriToPath = require('file-uri-to-path');
const isDev = require('electron-is-dev'); const isDev = require('electron-is-dev');
// Ours
const AutoUpdater = require('./auto-updater'); const AutoUpdater = require('./auto-updater');
const toElectronBackgroundColor = require('./utils/to-electron-background-color'); const toElectronBackgroundColor = require('./utils/to-electron-background-color');
const createMenu = require('./menu');
const createRPC = require('./rpc');
const notify = require('./notify'); const notify = require('./notify');
const { gitDescribe } = require('git-describe');
app.commandLine.appendSwitch('js-flags', '--harmony'); app.commandLine.appendSwitch('js-flags', '--harmony');
// set up config // set up config
const config = require('./config'); const config = require('./config');
config.init(); config.init();
const plugins = require('./plugins'); const plugins = require('./plugins');
const Session = require('./session'); const Session = require('./session');
@ -29,7 +36,9 @@ app.getWindows = () => new Set([...windowSet]); // return a clone
// function to retrive the last focused window in windowSet; // function to retrive the last focused window in windowSet;
// added to app object in order to expose it to plugins. // added to app object in order to expose it to plugins.
app.getLastFocusedWindow = () => { app.getLastFocusedWindow = () => {
if (!windowSet.size) return null; if (!windowSet.size) {
return null;
}
return Array.from(windowSet).reduce((lastWindow, win) => { return Array.from(windowSet).reduce((lastWindow, win) => {
return win.focusTime > lastWindow.focusTime ? win : lastWindow; return win.focusTime > lastWindow.focusTime ? win : lastWindow;
}); });
@ -40,7 +49,9 @@ if (isDev) {
// Overide default appVersion which is set from package.json // Overide default appVersion which is set from package.json
gitDescribe({customArguments: ['--tags']}, (error, gitInfo) => { gitDescribe({customArguments: ['--tags']}, (error, gitInfo) => {
if (!error) app.setVersion(gitInfo.raw); if (!error) {
app.setVersion(gitInfo.raw);
}
}); });
} else { } else {
console.log('running in prod mode'); console.log('running in prod mode');
@ -138,7 +149,9 @@ app.on('ready', () => {
// If no callback is passed to createWindow, // If no callback is passed to createWindow,
// a new session will be created by default. // a new session will be created by default.
if (!fn) fn = (win) => win.rpc.emit('session add req'); if (!fn) {
fn = win => win.rpc.emit('session add req');
}
// app.windowCallback is the createWindow callback // app.windowCallback is the createWindow callback
// that can be setted before the 'ready' app event // that can be setted before the 'ready' app event
@ -167,11 +180,11 @@ app.on('ready', () => {
pid: session.pty.pid pid: session.pty.pid
}); });
session.on('data', (data) => { session.on('data', data => {
rpc.emit('session data', {uid, data}); rpc.emit('session data', {uid, data});
}); });
session.on('title', (title) => { session.on('title', title => {
win.setTitle(title); win.setTitle(title);
rpc.emit('session title', {uid, title}); rpc.emit('session title', {uid, title});
}); });
@ -226,7 +239,7 @@ app.on('ready', () => {
}); });
rpc.on('resize', ({cols, rows}) => { rpc.on('resize', ({cols, rows}) => {
sessions.forEach((session) => { sessions.forEach(session => {
session.resize({cols, rows}); session.resize({cols, rows});
}); });
}); });
@ -263,10 +276,10 @@ app.on('ready', () => {
// If file is dropped onto the terminal window, navigate event is prevented // If file is dropped onto the terminal window, navigate event is prevented
// and his path is added to active session. // and his path is added to active session.
win.webContents.on('will-navigate', (event, url) => { win.webContents.on('will-navigate', (event, url) => {
var protocol = typeof url === 'string' && parseUrl(url).protocol; const protocol = typeof url === 'string' && parseUrl(url).protocol;
if (protocol === 'file:') { if (protocol === 'file:') {
event.preventDefault(); event.preventDefault();
let path = fileUriToPath(url).replace(/ /g, '\\ '); const path = fileUriToPath(url).replace(/ /g, '\\ ');
rpc.emit('session data send', {data: path}); rpc.emit('session data send', {data: path});
} }
}); });
@ -282,7 +295,7 @@ app.on('ready', () => {
// load plugins // load plugins
load(); load();
const pluginsUnsubscribe = plugins.subscribe((err) => { const pluginsUnsubscribe = plugins.subscribe(err => {
if (!err) { if (!err) {
load(); load();
win.webContents.send('plugins change'); win.webContents.send('plugins change');
@ -343,10 +356,12 @@ app.on('ready', () => {
// If we're on Mac make a Dock Menu // If we're on Mac make a Dock Menu
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
const { app, Menu } = require('electron'); const dockMenu = Menu.buildFromTemplate([{
const dockMenu = Menu.buildFromTemplate([ label: 'New Window',
{label: 'New Window', click () { createWindow(); }} click() {
]); createWindow();
}
}]);
app.dock.setMenu(dockMenu); app.dock.setMenu(dockMenu);
} }
@ -371,7 +386,7 @@ app.on('open-file', (event, path) => {
const callback = win => win.rpc.emit('open file', {path}); const callback = win => win.rpc.emit('open file', {path});
if (lastWindow) { if (lastWindow) {
callback(lastWindow); callback(lastWindow);
} else if (!lastWindow && app.hasOwnProperty('createWindow')) { } else if (!lastWindow && {}.hasOwnProperty.call(app, 'createWindow')) {
app.createWindow(callback); app.createWindow(callback);
} else { } else {
// if createWindow not exists yet ('ready' event was not fired), // if createWindow not exists yet ('ready' event was not fired),

View file

@ -1,6 +1,7 @@
const os = require('os'); const os = require('os');
const path = require('path'); const path = require('path');
const {app, shell, dialog} = require('electron'); const {app, shell, dialog} = require('electron');
const appName = app.getName(); const appName = app.getName();
// based on and inspired by // based on and inspired by
@ -61,7 +62,7 @@ module.exports = function createMenu ({ createWindow, updatePlugins }) {
{ {
label: 'New Window', label: 'New Window',
accelerator: 'CmdOrCtrl+N', accelerator: 'CmdOrCtrl+N',
click (item, focusedWindow) { click() {
createWindow(); createWindow();
} }
}, },
@ -273,8 +274,9 @@ ${process.platform} ${process.arch} ${os.release()}`;
} }
}, },
...( ...(
'darwin' !== process.platform process.platform === 'darwin' ?
? [ [] :
[
{type: 'separator'}, {type: 'separator'},
{ {
role: 'about', role: 'about',
@ -289,7 +291,6 @@ ${process.platform} ${process.arch} ${os.release()}`;
} }
} }
] ]
: []
) )
] ]
} }

View file

@ -1,6 +1,7 @@
const {resolve} = require('path');
const {app, BrowserWindow} = require('electron'); const {app, BrowserWindow} = require('electron');
const isDev = require('electron-is-dev'); const isDev = require('electron-is-dev');
const { resolve } = require('path');
let win; let win;

View file

@ -1,15 +1,17 @@
const { app, dialog } = require('electron'); const {exec} = require('child_process');
const {homedir} = require('os'); const {homedir} = require('os');
const {resolve, basename} = require('path'); const {resolve, basename} = require('path');
const {writeFileSync} = require('fs'); const {writeFileSync} = require('fs');
const config = require('./config');
const {app, dialog} = require('electron');
const {sync: mkdirpSync} = require('mkdirp'); const {sync: mkdirpSync} = require('mkdirp');
const { exec } = require('child_process');
const Config = require('electron-config'); const Config = require('electron-config');
const ms = require('ms'); const ms = require('ms');
const notify = require('./notify');
const shellEnv = require('shell-env'); const shellEnv = require('shell-env');
const config = require('./config');
const notify = require('./notify');
// local storage // local storage
const cache = new Config(); const cache = new Config();
@ -57,11 +59,13 @@ config.subscribe(() => {
let updating = false; let updating = false;
function updatePlugins({force = false} = {}) { function updatePlugins({force = false} = {}) {
if (updating) return notify('Plugin update in progress'); if (updating) {
return notify('Plugin update in progress');
}
updating = true; updating = true;
syncPackageJSON(); syncPackageJSON();
const id_ = id; const id_ = id;
install((err) => { install(err => {
updating = false; updating = false;
if (err) { if (err) {
@ -109,7 +113,7 @@ function updatePlugins ({ force = false } = {}) {
'No changes!' 'No changes!'
); );
} }
watchers.forEach((fn) => fn(err, { force })); watchers.forEach(fn => fn(err, {force}));
} }
} }
}); });
@ -117,7 +121,7 @@ function updatePlugins ({ force = false } = {}) {
function getPluginVersions() { function getPluginVersions() {
const paths_ = paths.plugins.concat(paths.localPlugins); const paths_ = paths.plugins.concat(paths.localPlugins);
return paths_.map((path) => { return paths_.map(path => {
let version = null; let version = null;
try { try {
version = require(resolve(path, 'package.json')).version; version = require(resolve(path, 'package.json')).version;
@ -129,10 +133,12 @@ function getPluginVersions () {
}); });
} }
function clearCache (mod) { function clearCache() {
// trigger unload hooks // trigger unload hooks
modules.forEach((mod) => { modules.forEach(mod => {
if (mod.onUnload) mod.onUnload(app); if (mod.onUnload) {
mod.onUnload(app);
}
}); });
// clear require cache // clear require cache
@ -189,7 +195,7 @@ function alert (message) {
function toDependencies(plugins) { function toDependencies(plugins) {
const obj = {}; const obj = {};
plugins.plugins.forEach((plugin) => { plugins.plugins.forEach(plugin => {
const regex = /.(@|#)/; const regex = /.(@|#)/;
const match = regex.exec(plugin); const match = regex.exec(plugin);
@ -212,17 +218,23 @@ function install (fn) {
const shell = cfgShell && cfgShell !== '' ? cfgShell : undefined; const shell = cfgShell && cfgShell !== '' ? cfgShell : undefined;
shellEnv(shell).then((env) => { shellEnv(shell).then(env => {
if (npmRegistry) env.NPM_CONFIG_REGISTRY = npmRegistry; if (npmRegistry) {
env.NPM_CONFIG_REGISTRY = npmRegistry;
}
/* eslint-disable camelcase */
env.npm_config_runtime = 'electron'; env.npm_config_runtime = 'electron';
env.npm_config_target = '1.3.0'; env.npm_config_target = '1.3.0';
env.npm_config_disturl = 'https://atom.io/download/atom-shell'; env.npm_config_disturl = 'https://atom.io/download/atom-shell';
/* eslint-enable camelcase */
exec('npm prune; npm install --production', { exec('npm prune; npm install --production', {
cwd: path, cwd: path,
env, env,
shell shell
}, (err, stdout, stderr) => { }, err => {
if (err) return fn(err); if (err) {
return fn(err);
}
fn(null); fn(null);
}); });
}).catch(fn); }).catch(fn);
@ -237,10 +249,10 @@ exports.subscribe = function (fn) {
function getPaths() { function getPaths() {
return { return {
plugins: plugins.plugins.map((name) => { plugins: plugins.plugins.map(name => {
return resolve(path, 'node_modules', name.split('#')[0]); return resolve(path, 'node_modules', name.split('#')[0]);
}), }),
localPlugins: plugins.localPlugins.map((name) => { localPlugins: plugins.localPlugins.map(name => {
return resolve(localPath, name); return resolve(localPath, name);
}) })
}; };
@ -257,7 +269,7 @@ exports.getBasePaths = function () {
function requirePlugins() { function requirePlugins() {
const {plugins, localPlugins} = paths; const {plugins, localPlugins} = paths;
const load = (path) => { const load = path => {
let mod; let mod;
try { try {
mod = require(path); mod = require(path);
@ -279,11 +291,11 @@ function requirePlugins () {
return plugins.map(load) return plugins.map(load)
.concat(localPlugins.map(load)) .concat(localPlugins.map(load))
.filter(v => !!v); .filter(v => Boolean(v));
} }
exports.onApp = function (app) { exports.onApp = function (app) {
modules.forEach((plugin) => { modules.forEach(plugin => {
if (plugin.onApp) { if (plugin.onApp) {
plugin.onApp(app); plugin.onApp(app);
} }
@ -291,7 +303,7 @@ exports.onApp = function (app) {
}; };
exports.onWindow = function (win) { exports.onWindow = function (win) {
modules.forEach((plugin) => { modules.forEach(plugin => {
if (plugin.onWindow) { if (plugin.onWindow) {
plugin.onWindow(win); plugin.onWindow(win);
} }
@ -302,10 +314,10 @@ exports.onWindow = function (win) {
// for all the available plugins // for all the available plugins
function decorateObject(base, key) { function decorateObject(base, key) {
let decorated = base; let decorated = base;
modules.forEach((plugin) => { modules.forEach(plugin => {
if (plugin[key]) { if (plugin[key]) {
const res = plugin[key](decorated); const res = plugin[key](decorated);
if (res && 'object' === typeof res) { if (res && typeof res === 'object') {
decorated = res; decorated = res;
} else { } else {
notify('Plugin error!', `"${plugin._name}": invalid return type for \`${key}\``); notify('Plugin error!', `"${plugin._name}": invalid return type for \`${key}\``);

View file

@ -9,7 +9,9 @@ class Server extends EventEmitter {
this.win = win; this.win = win;
this.ipcListener = this.ipcListener.bind(this); this.ipcListener = this.ipcListener.bind(this);
if (this.destroyed) return; if (this.destroyed) {
return;
}
const uid = uuid.v4(); const uid = uuid.v4();
this.id = uid; this.id = uid;

View file

@ -1,7 +1,9 @@
const { app } = require('electron');
const { EventEmitter } = require('events');
const {exec} = require('child_process'); const {exec} = require('child_process');
const {EventEmitter} = require('events');
const {app} = require('electron');
const defaultShell = require('default-shell'); const defaultShell = require('default-shell');
const {getDecoratedEnv} = require('./plugins'); const {getDecoratedEnv} = require('./plugins');
const {productName, version} = require('./package'); const {productName, version} = require('./package');
const config = require('./config'); const config = require('./config');
@ -42,7 +44,7 @@ module.exports = class Session extends EventEmitter {
env: getDecoratedEnv(baseEnv) env: getDecoratedEnv(baseEnv)
}); });
this.pty.stdout.on('data', (data) => { this.pty.stdout.on('data', data => {
if (this.ended) { if (this.ended) {
return; return;
} }
@ -71,8 +73,13 @@ module.exports = class Session extends EventEmitter {
} }
getTitle() { getTitle() {
if ('win32' === process.platform) return; if (process.platform === 'win32') {
if (this.fetching) return; return;
}
if (this.fetching) {
return;
}
this.fetching = true; this.fetching = true;
let tty = this.pty.stdout.ttyname; let tty = this.pty.stdout.ttyname;
@ -86,8 +93,12 @@ module.exports = class Session extends EventEmitter {
// TODO: only tested on mac // TODO: only tested on mac
exec(`ps uxac | grep ${tty} | head -n 1`, (err, out) => { exec(`ps uxac | grep ${tty} | head -n 1`, (err, out) => {
this.fetching = false; this.fetching = false;
if (this.ended) return; if (this.ended) {
if (err) return; return;
}
if (err) {
return;
}
let title = out.split(' ').pop(); let title = out.split(' ').pop();
if (title) { if (title) {
title = title.replace(/^\(/, ''); title = title.replace(/^\(/, '');

View file

@ -5,10 +5,9 @@ const Color = require('color');
// input can be any css value (rgb, hsl, string…) // input can be any css value (rgb, hsl, string…)
module.exports = function toElectronBackgroundColor(bgColor) { module.exports = function toElectronBackgroundColor(bgColor) {
const color = Color(bgColor); const color = Color(bgColor);
if (1 !== color.alpha()) { if (color.alpha() === 1) {
// (╯°□°)╯︵ ┻━┻
return '#' + Math.floor(color.alpha() * 100) + color.hexString().substr(1);
} else {
return color.hexString(); return color.hexString();
} }
// (╯°□°)╯︵ ┻━┻
return '#' + Math.floor(color.alpha() * 100) + color.hexString().substr(1);
}; };

View file

@ -1,10 +1,11 @@
import {CLOSE_TAB, CHANGE_TAB} from '../constants/tabs'; import {CLOSE_TAB, CHANGE_TAB} from '../constants/tabs';
import {UI_WINDOW_MAXIMIZE, UI_WINDOW_UNMAXIMIZE} from '../constants/ui'; import {UI_WINDOW_MAXIMIZE, UI_WINDOW_UNMAXIMIZE} from '../constants/ui';
import { userExitSession, setActiveSession } from './sessions';
import rpc from '../rpc'; import rpc from '../rpc';
import {userExitSession, setActiveSession} from './sessions';
export function closeTab(uid) { export function closeTab(uid) {
return (dispatch, getState) => { return dispatch => {
dispatch({ dispatch({
type: CLOSE_TAB, type: CLOSE_TAB,
uid, uid,
@ -16,7 +17,7 @@ export function closeTab (uid) {
} }
export function changeTab(uid) { export function changeTab(uid) {
return (dispatch, getState) => { return dispatch => {
dispatch({ dispatch({
type: CHANGE_TAB, type: CHANGE_TAB,
uid, uid,
@ -28,7 +29,7 @@ export function changeTab (uid) {
} }
export function maximize() { export function maximize() {
return (dispatch, getState) => { return dispatch => {
dispatch({ dispatch({
type: UI_WINDOW_MAXIMIZE, type: UI_WINDOW_MAXIMIZE,
effect() { effect() {
@ -39,7 +40,7 @@ export function maximize () {
} }
export function unmaximize() { export function unmaximize() {
return (dispatch, getState) => { return dispatch => {
dispatch({ dispatch({
type: UI_WINDOW_UNMAXIMIZE, type: UI_WINDOW_UNMAXIMIZE,
effect() { effect() {

View file

@ -20,7 +20,7 @@ import {
} from '../constants/sessions'; } from '../constants/sessions';
export function addSession(uid, shell, pid) { export function addSession(uid, shell, pid) {
return (dispatch, getState) => { return dispatch => {
dispatch({ dispatch({
type: SESSION_ADD, type: SESSION_ADD,
uid, uid,
@ -30,7 +30,7 @@ export function addSession (uid, shell, pid) {
}; };
} }
export function requestSession (uid) { export function requestSession() {
return (dispatch, getState) => { return (dispatch, getState) => {
const {ui} = getState(); const {ui} = getState();
const {cols, rows, cwd} = ui; const {cols, rows, cwd} = ui;
@ -131,7 +131,9 @@ export function setActiveSession (uid) {
// TODO: this goes away when we are able to poll // TODO: this goes away when we are able to poll
// for the title ourseleves, instead of relying // for the title ourseleves, instead of relying
// on Session and focus/blur to subscribe // on Session and focus/blur to subscribe
if (prevUid) rpc.emit('blur', { uid: prevUid }); if (prevUid) {
rpc.emit('blur', {uid: prevUid});
}
rpc.emit('focus', {uid}); rpc.emit('focus', {uid});
} }
}); });

View file

@ -1,5 +1,5 @@
import * as shellEscape from 'php-escape-shell'; import * as shellEscape from 'php-escape-shell';
import { setActiveSession } from './sessions';
import {keys} from '../utils/object'; import {keys} from '../utils/object';
import {last} from '../utils/array'; import {last} from '../utils/array';
import {isExecutable} from '../utils/file'; import {isExecutable} from '../utils/file';
@ -23,6 +23,8 @@ import {
UI_OPEN_FILE UI_OPEN_FILE
} from '../constants/ui'; } from '../constants/ui';
import {setActiveSession} from './sessions';
const {stat} = window.require('fs'); const {stat} = window.require('fs');
export function increaseFontSize() { export function increaseFontSize() {
@ -66,12 +68,12 @@ export function resetFontSize () {
} }
export function setFontSmoothing() { export function setFontSmoothing() {
return (dispatch) => { return dispatch => {
setTimeout(() => { setTimeout(() => {
const devicePixelRatio = window.devicePixelRatio; const devicePixelRatio = window.devicePixelRatio;
const fontSmoothing = devicePixelRatio < 2 const fontSmoothing = devicePixelRatio < 2 ?
? 'subpixel-antialiased' 'subpixel-antialiased' :
: 'antialiased'; 'antialiased';
dispatch({ dispatch({
type: UI_FONT_SMOOTHING_SET, type: UI_FONT_SMOOTHING_SET,
@ -132,10 +134,10 @@ export function moveTo (i) {
const sessionUids = keys(sessions.sessions); const sessionUids = keys(sessions.sessions);
if (uid === sessionUids[i]) { if (uid === sessionUids[i]) {
console.log('ignoring same uid'); console.log('ignoring same uid');
} else if (null != sessionUids[i]) { } else if (sessionUids[i] === null) {
dispatch(setActiveSession(sessionUids[i]));
} else {
console.log('ignoring inexistent index', i); console.log('ignoring inexistent index', i);
} else {
dispatch(setActiveSession(sessionUids[i]));
} }
} }
}); });
@ -144,7 +146,7 @@ export function moveTo (i) {
export function showPreferences() { export function showPreferences() {
const editorFallback = process.platform === 'win32' ? 'notepad' : 'nano'; const editorFallback = process.platform === 'win32' ? 'notepad' : 'nano';
return (dispatch, getState) => { return dispatch => {
dispatch({ dispatch({
type: UI_SHOW_PREFERENCES, type: UI_SHOW_PREFERENCES,
effect() { effect() {
@ -169,7 +171,7 @@ export function showPreferences () {
} }
export function windowMove() { export function windowMove() {
return (dispatch) => { return dispatch => {
dispatch({ dispatch({
type: UI_WINDOW_MOVE, type: UI_WINDOW_MOVE,
effect() { effect() {
@ -180,7 +182,7 @@ export function windowMove () {
} }
export function openFile(path) { export function openFile(path) {
return (dispatch, getState) => { return dispatch => {
dispatch({ dispatch({
type: UI_OPEN_FILE, type: UI_OPEN_FILE,
effect() { effect() {

View file

@ -20,7 +20,7 @@ export default class Component extends React.Component {
const styles = this.styles(); const styles = this.styles();
if ('object' !== typeof styles) { if (typeof styles !== 'object') {
throw new TypeError('Component `styles` returns a non-object'); throw new TypeError('Component `styles` returns a non-object');
} }
@ -36,7 +36,7 @@ export default class Component extends React.Component {
// and `style`, and we make that whole ordeal easier // and `style`, and we make that whole ordeal easier
cssHelper(...args) { cssHelper(...args) {
const classes = args const classes = args
.map((c) => { .map(c => {
if (c) { if (c) {
// we compute the global name from the given // we compute the global name from the given
// css class and we prepend the component name // css class and we prepend the component name
@ -48,9 +48,10 @@ export default class Component extends React.Component {
const globalName = `${component}_${c}`; const globalName = `${component}_${c}`;
return [globalName, css(this.styles_[c])]; return [globalName, css(this.styles_[c])];
} }
return null;
}) })
// skip nulls // skip nulls
.filter((v) => !!v) .filter(v => Boolean(v))
// flatten // flatten
.reduce((a, b) => a.concat(b)); .reduce((a, b) => a.concat(b));
return classes.length ? classes.join(' ') : null; return classes.length ? classes.join(' ') : null;
@ -60,7 +61,7 @@ export default class Component extends React.Component {
// convert static objects from `babel-plugin-transform-jsx` // convert static objects from `babel-plugin-transform-jsx`
// to `React.Element`. // to `React.Element`.
if (!this.template) { if (!this.template) {
throw new TypeError("Component doesn't define `template`"); throw new TypeError('Component doesn\'t define `template`');
} }
// invoke the template creator passing our css helper // invoke the template creator passing our css helper

View file

@ -1,8 +1,10 @@
import React from 'react'; import React from 'react';
import Tabs_ from './tabs';
import Component from '../component'; import Component from '../component';
import {decorate, getTabsProps} from '../utils/plugins'; import {decorate, getTabsProps} from '../utils/plugins';
import Tabs_ from './tabs';
const Tabs = decorate(Tabs_, 'Tabs'); const Tabs = decorate(Tabs_, 'Tabs');
export default class Header extends Component { export default class Header extends Component {
@ -10,8 +12,8 @@ export default class Header extends Component {
constructor() { constructor() {
super(); super();
this.onChangeIntent = this.onChangeIntent.bind(this); this.onChangeIntent = this.onChangeIntent.bind(this);
this.onHeaderClick = this.onHeaderClick.bind(this); this.handleHeaderClick = this.handleHeaderClick.bind(this);
this.onHeaderMouseDown = this.onHeaderMouseDown.bind(this); this.handleHeaderMouseDown = this.handleHeaderMouseDown.bind(this);
} }
onChangeIntent(active) { onChangeIntent(active) {
@ -25,12 +27,12 @@ export default class Header extends Component {
this.props.onChangeTab(active); this.props.onChangeTab(active);
} }
onHeaderMouseDown () { handleHeaderMouseDown() {
this.headerMouseDownWindowX = window.screenX; this.headerMouseDownWindowX = window.screenX;
this.headerMouseDownWindowY = window.screenY; this.headerMouseDownWindowY = window.screenY;
} }
onHeaderClick (event) { handleHeaderClick(event) {
this.clicks = this.clicks || 0; this.clicks = this.clicks || 0;
// Reset clicks if mouse moved between clicks // Reset clicks if mouse moved between clicks
@ -72,14 +74,15 @@ export default class Header extends Component {
onClose: this.props.onCloseTab, onClose: this.props.onCloseTab,
onChange: this.onChangeIntent onChange: this.onChangeIntent
}); });
return <header return (<header
className={css('header', isMac && 'headerRounded')} className={css('header', isMac && 'headerRounded')}
onClick={ this.onHeaderClick } onClick={this.handleHeaderClick}
onMouseDown={ this.onHeaderMouseDown }> onMouseDown={this.handleHeaderMouseDown}
>
{ this.props.customChildrenBefore } { this.props.customChildrenBefore }
<Tabs {...props}/> <Tabs {...props}/>
{ this.props.customChildren } { this.props.customChildren }
</header>; </header>);
} }
styles() { styles() {

View file

@ -8,7 +8,7 @@ export default class Notification extends Component {
this.state = { this.state = {
dismissing: false dismissing: false
}; };
this.dismiss = this.dismiss.bind(this); this.handleDismiss = this.handleDismiss.bind(this);
this.onElement = this.onElement.bind(this); this.onElement = this.onElement.bind(this);
} }
@ -31,7 +31,7 @@ export default class Notification extends Component {
} }
} }
dismiss () { handleDismiss() {
this.setState({dismissing: true}); this.setState({dismissing: true});
} }
@ -53,13 +53,13 @@ export default class Notification extends Component {
} }
} }
setDismissTimer (after) { setDismissTimer() {
this.dismissTimer = setTimeout(() => { this.dismissTimer = setTimeout(() => {
this.dismiss(); this.handleDismiss();
}, this.props.dismissAfter); }, this.props.dismissAfter);
} }
resetDismissTimer (after) { resetDismissTimer() {
clearTimeout(this.dismissTimer); clearTimeout(this.dismissTimer);
this.setDismissTimer(); this.setDismissTimer();
} }
@ -71,21 +71,23 @@ export default class Notification extends Component {
template(css) { template(css) {
const {backgroundColor} = this.props; const {backgroundColor} = this.props;
const opacity = this.state.dismissing ? 0 : 1; const opacity = this.state.dismissing ? 0 : 1;
return <div return (<div
style={{opacity, backgroundColor}} style={{opacity, backgroundColor}}
ref={this.onElement} ref={this.onElement}
className={ css('indicator') }> className={css('indicator')}
>
{ this.props.customChildrenBefore } { this.props.customChildrenBefore }
{ this.props.children || this.props.text } { this.props.children || this.props.text }
{ {
this.props.userDismissable this.props.userDismissable ?
? <a <a
className={css('dismissLink')} className={css('dismissLink')}
onClick={ this.dismiss }>[x]</a> onClick={this.handleDismiss}
: null >[x]</a> :
null
} }
{ this.props.customChildren } { this.props.customChildren }
</div>; </div>);
} }
styles() { styles() {

View file

@ -1,65 +1,77 @@
import React from 'react'; import React from 'react';
import Component from '../component'; import Component from '../component';
import Notification_ from './notification';
import {decorate} from '../utils/plugins'; import {decorate} from '../utils/plugins';
import Notification_ from './notification';
const Notification = decorate(Notification_); const Notification = decorate(Notification_);
export default class Notifications extends Component { export default class Notifications extends Component {
template(css) { template(css) {
return <div className={ css('view') }> return (<div className={css('view')}>
{ this.props.customChildrenBefore } { this.props.customChildrenBefore }
{ {
this.props.fontShowing && this.props.fontShowing &&
<Notification <Notification
key='font' key="font"
backgroundColor='rgba(255, 255, 255, .2)' backgroundColor="rgba(255, 255, 255, .2)"
text={`${this.props.fontSize}px`} text={`${this.props.fontSize}px`}
userDismissable={false} userDismissable={false}
onDismiss={this.props.onDismissFont} onDismiss={this.props.onDismissFont}
dismissAfter={ 1000 } /> dismissAfter={1000}
/>
} }
{ {
this.props.resizeShowing && this.props.resizeShowing &&
<Notification <Notification
key='resize' key="resize"
backgroundColor='rgba(255, 255, 255, .2)' backgroundColor="rgba(255, 255, 255, .2)"
text={`${this.props.cols}x${this.props.rows}`} text={`${this.props.cols}x${this.props.rows}`}
userDismissable={false} userDismissable={false}
onDismiss={this.props.onDismissResize} onDismiss={this.props.onDismissResize}
dismissAfter={ 1000 } /> dismissAfter={1000}
/>
} }
{ {
this.props.updateShowing && this.props.updateShowing &&
<Notification <Notification
key='update' key="update"
backgroundColor='#7ED321' backgroundColor="#7ED321"
text={`Version ${this.props.updateVersion} ready`} text={`Version ${this.props.updateVersion} ready`}
onDismiss={this.props.onDismissUpdate} onDismiss={this.props.onDismissUpdate}
userDismissable={ true }> userDismissable
>
Version <b>{ this.props.updateVersion}</b> ready. Version <b>{ this.props.updateVersion}</b> ready.
{ this.props.updateNote && ` ${this.props.updateNote.trim().replace(/\.$/, '')}` } { this.props.updateNote && ` ${this.props.updateNote.trim().replace(/\.$/, '')}` }
{ ' ' } { ' ' }
(<a (<a
style={{color: '#fff'}} style={{color: '#fff'}}
onClick={ (ev) => { window.require('electron').shell.openExternal(ev.target.href); ev.preventDefault(); } } onClick={ev => {
href={`https://github.com/zeit/hyperterm/releases/tag/${this.props.updateVersion}`}>notes</a>). window.require('electron').shell.openExternal(ev.target.href);
ev.preventDefault();
}}
href={`https://github.com/zeit/hyperterm/releases/tag/${this.props.updateVersion}`}
>notes</a>).
{ ' ' } { ' ' }
<a style={{ <a
style={{
cursor: 'pointer', cursor: 'pointer',
textDecoration: 'underline', textDecoration: 'underline',
fontWeight: 'bold' }} fontWeight: 'bold'
onClick={ this.props.onUpdateInstall }> }}
onClick={this.props.onUpdateInstall}
>
Restart Restart
</a>. </a>.
{ ' ' } { ' ' }
</Notification> </Notification>
} }
{ this.props.customChildren } { this.props.customChildren }
</div>; </div>);
} }
styles() { styles() {

View file

@ -4,20 +4,30 @@ import Component from '../component';
export default class Tab extends Component { export default class Tab extends Component {
constructor() { constructor() {
super(); super();
this.hover = this.hover.bind(this);
this.blur = this.blur.bind(this); this.handleHover = this.handleHover.bind(this);
this.handleBlur = this.handleBlur.bind(this);
this.handleClick = this.handleClick.bind(this); this.handleClick = this.handleClick.bind(this);
this.state = { this.state = {
hovered: false hovered: false
}; };
} }
hover () { shouldComponentUpdate() {
this.setState({ hovered: true }); return true;
} }
blur () { handleHover() {
this.setState({ hovered: false }); this.setState({
hovered: true
});
}
handleBlur() {
this.setState({
hovered: false
});
} }
handleClick(event) { handleClick(event) {
@ -25,7 +35,9 @@ export default class Tab extends Component {
const isMiddleClick = event.nativeEvent.which === 2; const isMiddleClick = event.nativeEvent.which === 2;
if (isLeftClick) { if (isLeftClick) {
this.props.isActive ? null : this.props.onSelect(); if (this.props.isActive === null) {
this.props.onSelect();
}
} else if (isMiddleClick) { } else if (isMiddleClick) {
this.props.onClose(); this.props.onClose();
} }
@ -35,9 +47,9 @@ export default class Tab extends Component {
const {isActive, isFirst, isLast, borderColor, hasActivity} = this.props; const {isActive, isFirst, isLast, borderColor, hasActivity} = this.props;
const {hovered} = this.state; const {hovered} = this.state;
return <li return (<li
onMouseEnter={ this.hover } onMouseEnter={this.handleHover}
onMouseLeave={ this.blur } onMouseLeave={this.handleBlur}
onClick={this.props.onClick} onClick={this.props.onClick}
style={{borderColor}} style={{borderColor}}
className={css( className={css(
@ -46,7 +58,8 @@ export default class Tab extends Component {
isActive && 'active', isActive && 'active',
isFirst && isActive && 'firstActive', isFirst && isActive && 'firstActive',
hasActivity && 'hasActivity' hasActivity && 'hasActivity'
) }> )}
>
{ this.props.customChildrenBefore } { this.props.customChildrenBefore }
<span <span
className={css( className={css(
@ -54,7 +67,8 @@ export default class Tab extends Component {
isLast && 'textLast', isLast && 'textLast',
isActive && 'textActive' isActive && 'textActive'
)} )}
onClick={ this.handleClick }> onClick={this.handleClick}
>
<span className={css('textInner')}> <span className={css('textInner')}>
{ this.props.text } { this.props.text }
</span> </span>
@ -64,13 +78,14 @@ export default class Tab extends Component {
'icon', 'icon',
hovered && 'iconHovered' hovered && 'iconHovered'
)} )}
onClick={ this.props.onClose }> onClick={this.props.onClose}
>
<svg className={css('shape')}> <svg className={css('shape')}>
<use xlinkHref='./dist/assets/icons.svg#close'></use> <use xlinkHref="./dist/assets/icons.svg#close"/>
</svg> </svg>
</i> </i>
{ this.props.customChildren } { this.props.customChildren }
</li>; </li>);
} }
styles() { styles() {

View file

@ -1,8 +1,10 @@
import Tab_ from './tab';
import React from 'react'; import React from 'react';
import Component from '../component'; import Component from '../component';
import {decorate, getTabProps} from '../utils/plugins'; import {decorate, getTabProps} from '../utils/plugins';
import Tab_ from './tab';
const Tab = decorate(Tab_, 'Tab'); const Tab = decorate(Tab_, 'Tab');
const isMac = /Mac/.test(navigator.userAgent); const isMac = /Mac/.test(navigator.userAgent);
@ -16,23 +18,24 @@ export default class Tabs extends Component {
onClose onClose
} = this.props; } = this.props;
return <nav className={ css('nav') }> return (<nav className={css('nav')}>
{ this.props.customChildrenBefore } { this.props.customChildrenBefore }
{ {
tabs.length tabs.length ?
? 1 === tabs.length tabs.length === 1 ?
? <div className={ css('title') }>{ tabs[0].title }</div> <div className={css('title')}>{tabs[0].title}</div> :
: [ [
<ul <ul
className={ css('list') }> className={css('list')}
>
{ {
tabs.map((tab, i) => { tabs.map((tab, i) => {
const {uid, title, isActive, hasActivity} = tab; const {uid, title, isActive, hasActivity} = tab;
const props = getTabProps(tab, this.props, { const props = getTabProps(tab, this.props, {
text: '' === title ? 'Shell' : title, text: title === '' ? 'Shell' : title,
isFirst: 0 === i, isFirst: i === 0,
isLast: tabs.length - 1 === i, isLast: tabs.length - 1 === i,
borderColor: borderColor, borderColor,
isActive, isActive,
hasActivity, hasActivity,
onSelect: onChange.bind(null, uid), onSelect: onChange.bind(null, uid),
@ -44,12 +47,13 @@ export default class Tabs extends Component {
</ul>, </ul>,
isMac && <div isMac && <div
style={{borderColor}} style={{borderColor}}
className={ css('borderShim') }></div> className={css('borderShim')}
] />
: null ] :
null
} }
{ this.props.customChildren } { this.props.customChildren }
</nav>; </nav>);
} }
styles() { styles() {

View file

@ -11,8 +11,8 @@ export default class Term extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.onWheel = this.onWheel.bind(this); this.onWheel = this.onWheel.bind(this);
this.onScrollEnter = this.onScrollEnter.bind(this); this.handleScrollEnter = this.handleScrollEnter.bind(this);
this.onScrollLeave = this.onScrollLeave.bind(this); this.handleScrollLeave = this.handleScrollLeave.bind(this);
props.ref_(this); props.ref_(this);
} }
@ -66,7 +66,9 @@ export default class Term extends Component {
}; };
this.term.decorate(this.refs.term); this.term.decorate(this.refs.term);
this.term.installKeyboard(); this.term.installKeyboard();
if (this.props.onTerminal) this.props.onTerminal(this.term); if (this.props.onTerminal) {
this.props.onTerminal(this.term);
}
const iframeWindow = this.getTermDocument().defaultView; const iframeWindow = this.getTermDocument().defaultView;
iframeWindow.addEventListener('wheel', this.onWheel); iframeWindow.addEventListener('wheel', this.onWheel);
@ -85,13 +87,13 @@ export default class Term extends Component {
} }
} }
onScrollEnter () { handleScrollEnter() {
clearTimeout(this.scrollbarsHideTimer); clearTimeout(this.scrollbarsHideTimer);
this.term.prefs_.set('scrollbar-visible', true); this.term.prefs_.set('scrollbar-visible', true);
this.scrollMouseEnter = true; this.scrollMouseEnter = true;
} }
onScrollLeave () { handleScrollLeave() {
this.term.prefs_.set('scrollbar-visible', false); this.term.prefs_.set('scrollbar-visible', false);
this.scrollMouseEnter = false; this.scrollMouseEnter = false;
} }
@ -180,8 +182,8 @@ export default class Term extends Component {
// with the <webview> // with the <webview>
if (nextProps.url) { if (nextProps.url) {
const io = this.term.io.push(); const io = this.term.io.push();
io.onVTKeystroke = io.sendString = (str) => { io.onVTKeystroke = io.sendString = str => {
if (1 === str.length && 3 === str.charCodeAt(0) /* Ctrl + C */) { if (str.length === 1 && str.charCodeAt(0) === 3 /* Ctrl + C */) {
this.props.onURLAbort(); this.props.onURLAbort();
} }
}; };
@ -245,11 +247,11 @@ export default class Term extends Component {
} }
template(css) { template(css) {
return <div className={ css('fit') }> return (<div className={css('fit')}>
{ this.props.customChildrenBefore } { this.props.customChildrenBefore }
<div ref='term' className={ css('fit', 'term') } /> <div ref="term" className={css('fit', 'term')}/>
{ this.props.url { this.props.url ?
? <webview <webview
src={this.props.url} src={this.props.url}
style={{ style={{
background: '#000', background: '#000',
@ -259,14 +261,16 @@ export default class Term extends Component {
display: 'inline-flex', display: 'inline-flex',
width: '100%', width: '100%',
height: '100%' height: '100%'
}}></webview> }}
: <div /> :
<div
className={css('scrollbarShim')} className={css('scrollbarShim')}
onMouseEnter={ this.onScrollEnter } onMouseEnter={this.handleScrollEnter}
onMouseLeave={ this.onScrollLeave } /> onMouseLeave={this.handleScrollLeave}
/>
} }
{ this.props.customChildren } { this.props.customChildren }
</div>; </div>);
} }
styles() { styles() {

View file

@ -1,9 +1,11 @@
import React from 'react'; import React from 'react';
import Term_ from './term';
import Component from '../component'; import Component from '../component';
import {last} from '../utils/array'; import {last} from '../utils/array';
import {decorate, getTermProps} from '../utils/plugins'; import {decorate, getTermProps} from '../utils/plugins';
import Term_ from './term';
const Term = decorate(Term_, 'Term'); const Term = decorate(Term_, 'Term');
export default class Terms extends Component { export default class Terms extends Component {
@ -42,7 +44,7 @@ export default class Terms extends Component {
const curActive = this.props.activeSession; const curActive = this.props.activeSession;
// if we closed an item that wasn't focused, nothing changes // if we closed an item that wasn't focused, nothing changes
if (~newUids.indexOf(curActive)) { if (newUids.indexOf(curActive) !== -1) {
return; return;
} }
@ -60,13 +62,17 @@ export default class Terms extends Component {
shouldComponentUpdate(nextProps) { shouldComponentUpdate(nextProps) {
for (const i in nextProps) { for (const i in nextProps) {
if ('write' === i) continue; if (i === 'write') {
continue;
}
if (this.props[i] !== nextProps[i]) { if (this.props[i] !== nextProps[i]) {
return true; return true;
} }
} }
for (const i in this.props) { for (const i in this.props) {
if ('write' === i) continue; if (i === 'write') {
continue;
}
if (this.props[i] !== nextProps[i]) { if (this.props[i] !== nextProps[i]) {
return true; return true;
} }
@ -118,12 +124,13 @@ export default class Terms extends Component {
} }
template(css) { template(css) {
return <div return (<div
style={{padding: this.props.padding}} style={{padding: this.props.padding}}
className={ css('terms') }> className={css('terms')}
>
{ this.props.customChildrenBefore } { this.props.customChildrenBefore }
{ {
this.props.sessions.map((session) => { this.props.sessions.map(session => {
const uid = session.uid; const uid = session.uid;
const isActive = uid === this.props.activeSession; const isActive = uid === this.props.activeSession;
const props = getTermProps(uid, this.props, { const props = getTermProps(uid, this.props, {
@ -147,18 +154,20 @@ export default class Terms extends Component {
bellSoundURL: this.props.bellSoundURL, bellSoundURL: this.props.bellSoundURL,
copyOnSelect: this.props.copyOnSelect copyOnSelect: this.props.copyOnSelect
}); });
return <div return (<div
key={`d${uid}`} key={`d${uid}`}
className={css('term', isActive && 'termActive')}> className={css('term', isActive && 'termActive')}
>
<Term <Term
key={uid} key={uid}
ref_={this.bind(this.onRef, this, uid)} ref_={this.bind(this.onRef, this, uid)}
{...props} /> {...props}
</div>; />
</div>);
}) })
} }
{ this.props.customChildren } { this.props.customChildren }
</div>; </div>);
} }
styles() { styles() {
@ -190,7 +199,7 @@ export default class Terms extends Component {
// little memoized helper to compute a map of uids // little memoized helper to compute a map of uids
function uids(sessions) { function uids(sessions) {
if (!sessions._uids) { if (!sessions._uids) {
sessions._uids = sessions.map((s) => s.uid); sessions._uids = sessions.map(s => s.uid);
} }
return sessions._uids; return sessions._uids;
} }

View file

@ -1,17 +1,18 @@
import {createSelector} from 'reselect';
import Header from '../components/header'; import Header from '../components/header';
import {closeTab, changeTab, maximize, unmaximize} from '../actions/header'; import {closeTab, changeTab, maximize, unmaximize} from '../actions/header';
import {values} from '../utils/object'; import {values} from '../utils/object';
import { createSelector } from 'reselect';
import {connect} from '../utils/plugins'; import {connect} from '../utils/plugins';
const isMac = /Mac/.test(navigator.userAgent); const isMac = /Mac/.test(navigator.userAgent);
const getSessions = (sessions) => sessions.sessions; const getSessions = sessions => sessions.sessions;
const getActiveUid = (sessions) => sessions.activeUid; const getActiveUid = sessions => sessions.activeUid;
const getActivityMarkers = (sessions, ui) => ui.activityMarkers; const getActivityMarkers = (sessions, ui) => ui.activityMarkers;
const getTabs = createSelector( const getTabs = createSelector(
[getSessions, getActiveUid, getActivityMarkers], [getSessions, getActiveUid, getActivityMarkers],
(sessions, activeUid, activityMarkers) => values(sessions).map((s) => { (sessions, activeUid, activityMarkers) => values(sessions).map(s => {
return { return {
uid: s.uid, uid: s.uid,
title: s.title, title: s.title,
@ -22,7 +23,7 @@ const getTabs = createSelector(
); );
const HeaderContainer = connect( const HeaderContainer = connect(
(state) => { state => {
return { return {
// active is an index // active is an index
isMac, isMac,
@ -33,13 +34,13 @@ const HeaderContainer = connect(
maximized: state.ui.maximized maximized: state.ui.maximized
}; };
}, },
(dispatch) => { dispatch => {
return { return {
onCloseTab: (i) => { onCloseTab: i => {
dispatch(closeTab(i)); dispatch(closeTab(i));
}, },
onChangeTab: (i) => { onChangeTab: i => {
dispatch(changeTab(i)); dispatch(changeTab(i));
}, },

View file

@ -1,18 +1,20 @@
import Mousetrap from 'mousetrap';
import React from 'react'; import React from 'react';
import Component from '../component';
import {connect} from '../utils/plugins';
import * as uiActions from '../actions/ui';
import HeaderContainer from './header'; import HeaderContainer from './header';
import TermsContainer from './terms'; import TermsContainer from './terms';
import NotificationsContainer from './notifications'; import NotificationsContainer from './notifications';
import Component from '../component';
import Mousetrap from 'mousetrap';
import * as uiActions from '../actions/ui';
import { connect } from '../utils/plugins';
const isMac = /Mac/.test(navigator.userAgent); const isMac = /Mac/.test(navigator.userAgent);
class HyperTerm extends Component { class HyperTerm extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.focusActive = this.focusActive.bind(this); this.handleFocusActive = this.handleFocusActive.bind(this);
this.onTermsRef = this.onTermsRef.bind(this); this.onTermsRef = this.onTermsRef.bind(this);
} }
@ -24,15 +26,19 @@ class HyperTerm extends Component {
} }
} }
focusActive () { handleFocusActive() {
const term = this.terms.getActiveTerm(); const term = this.terms.getActiveTerm();
if (term) term.focus(); if (term) {
term.focus();
}
} }
attachKeyListeners() { attachKeyListeners() {
const {moveTo, moveLeft, moveRight} = this.props; const {moveTo, moveLeft, moveRight} = this.props;
const term = this.terms.getActiveTerm(); const term = this.terms.getActiveTerm();
if (!term) return; if (!term) {
return;
}
const lastIndex = this.terms.getLastTermIndex(); const lastIndex = this.terms.getLastTermIndex();
const document = term.getTermDocument(); const document = term.getTermDocument();
const keys = new Mousetrap(document); const keys = new Mousetrap(document);
@ -55,7 +61,7 @@ class HyperTerm extends Component {
keys.bind('ctrl+shift+tab', moveLeft); keys.bind('ctrl+shift+tab', moveLeft);
keys.bind('ctrl+tab', moveRight); keys.bind('ctrl+tab', moveRight);
const bound = method => { return term[method].bind(term); }; const bound = method => term[method].bind(term);
keys.bind('alt+left', bound('moveWordLeft')); keys.bind('alt+left', bound('moveWordLeft'));
keys.bind('alt+right', bound('moveWordRight')); keys.bind('alt+right', bound('moveWordRight'));
keys.bind('alt+backspace', bound('deleteWordLeft')); keys.bind('alt+backspace', bound('deleteWordLeft'));
@ -73,23 +79,28 @@ class HyperTerm extends Component {
componentDidUpdate(prev) { componentDidUpdate(prev) {
if (prev.activeSession !== this.props.activeSession) { if (prev.activeSession !== this.props.activeSession) {
if (this.keys) this.keys.reset(); if (this.keys) {
this.focusActive(); this.keys.reset();
}
this.handleFocusActive();
this.attachKeyListeners(); this.attachKeyListeners();
} }
} }
componentWillUnmount() { componentWillUnmount() {
if (this.keys) this.keys.reset(); if (this.keys) {
this.keys.reset();
}
document.body.style.backgroundColor = 'inherit'; document.body.style.backgroundColor = 'inherit';
} }
template(css) { template(css) {
const {isMac, customCSS, borderColor} = this.props; const {isMac, customCSS, borderColor} = this.props;
return <div onClick={ this.focusActive }> return (<div onClick={this.handleFocusActive}>
<div <div
style={{borderColor}} style={{borderColor}}
className={ css('main', isMac && 'mainRounded') }> className={css('main', isMac && 'mainRounded')}
>
<HeaderContainer/> <HeaderContainer/>
<TermsContainer ref_={this.onTermsRef}/> <TermsContainer ref_={this.onTermsRef}/>
</div> </div>
@ -97,7 +108,7 @@ class HyperTerm extends Component {
<NotificationsContainer/> <NotificationsContainer/>
<style dangerouslySetInnerHTML={{__html: customCSS}}/> <style dangerouslySetInnerHTML={{__html: customCSS}}/>
{ this.props.customChildren } { this.props.customChildren }
</div>; </div>);
} }
styles() { styles() {
@ -120,7 +131,7 @@ class HyperTerm extends Component {
} }
const HyperTermContainer = connect( const HyperTermContainer = connect(
(state) => { state => {
return { return {
isMac, isMac,
customCSS: state.ui.css, customCSS: state.ui.css,
@ -129,9 +140,9 @@ const HyperTermContainer = connect(
backgroundColor: state.ui.backgroundColor backgroundColor: state.ui.backgroundColor
}; };
}, },
(dispatch) => { dispatch => {
return { return {
moveTo: (i) => { moveTo: i => {
dispatch(uiActions.moveTo(i)); dispatch(uiActions.moveTo(i));
}, },

View file

@ -4,7 +4,7 @@ import { connect } from '../utils/plugins';
import {dismissNotification} from '../actions/notifications'; import {dismissNotification} from '../actions/notifications';
const NotificationsContainer = connect( const NotificationsContainer = connect(
(state) => { state => {
const {ui} = state; const {ui} = state;
const {notifications} = ui; const {notifications} = ui;
const state_ = {}; const state_ = {};
@ -40,7 +40,7 @@ const NotificationsContainer = connect(
return state_; return state_;
}, },
(dispatch) => { dispatch => {
return { return {
onDismissFont: () => { onDismissFont: () => {
dispatch(dismissNotification('font')); dispatch(dismissNotification('font'));

View file

@ -10,7 +10,7 @@ import {
} from '../actions/sessions'; } from '../actions/sessions';
const TermsContainer = connect( const TermsContainer = connect(
(state) => { state => {
const sessions = state.sessions.sessions; const sessions = state.sessions.sessions;
return { return {
cols: state.ui.cols, cols: state.ui.cols,
@ -19,9 +19,9 @@ const TermsContainer = connect(
activeSession: state.sessions.activeUid, activeSession: state.sessions.activeUid,
customCSS: state.ui.termCSS, customCSS: state.ui.termCSS,
write: state.sessions.write, write: state.sessions.write,
fontSize: state.ui.fontSizeOverride fontSize: state.ui.fontSizeOverride ?
? state.ui.fontSizeOverride state.ui.fontSizeOverride :
: state.ui.fontSize, state.ui.fontSize,
fontFamily: state.ui.fontFamily, fontFamily: state.ui.fontFamily,
fontSmoothing: state.ui.fontSmoothingOverride, fontSmoothing: state.ui.fontSmoothingOverride,
padding: state.ui.padding, padding: state.ui.padding,
@ -36,7 +36,7 @@ const TermsContainer = connect(
copyOnSelect: state.ui.copyOnSelect copyOnSelect: state.ui.copyOnSelect
}; };
}, },
(dispatch) => { dispatch => {
return { return {
onData(uid, data) { onData(uid, data) {
dispatch(sendSessionData(uid, data)); dispatch(sendSessionData(uid, data));

View file

@ -1,4 +1,5 @@
import {hterm, lib} from 'hterm-umdjs'; import {hterm, lib} from 'hterm-umdjs';
const selection = require('./utils/selection'); const selection = require('./utils/selection');
hterm.defaultStorage = new lib.Storage.Memory(); hterm.defaultStorage = new lib.Storage.Memory();
@ -13,7 +14,7 @@ hterm.Terminal.prototype.selectAll = function () {
// override double click behavior to copy // override double click behavior to copy
const oldMouse = hterm.Terminal.prototype.onMouse_; const oldMouse = hterm.Terminal.prototype.onMouse_;
hterm.Terminal.prototype.onMouse_ = function (e) { hterm.Terminal.prototype.onMouse_ = function (e) {
if ('dblclick' === e.type) { if (e.type === 'dblclick') {
selection.extend(this); selection.extend(this);
console.log('[hyperterm+hterm] ignore double click'); console.log('[hyperterm+hterm] ignore double click');
return; return;
@ -28,8 +29,8 @@ hterm.Terminal.prototype.overlaySize = function () {};
// a non-collapsed selection whose text is '', and results // a non-collapsed selection whose text is '', and results
// in an infinite copy loop // in an infinite copy loop
hterm.Terminal.prototype.copySelectionToClipboard = function () { hterm.Terminal.prototype.copySelectionToClipboard = function () {
var text = this.getSelectionText(); const text = this.getSelectionText();
if (text != null && text !== '') { if (text !== null && text !== '') {
this.copyStringToClipboard(text); this.copyStringToClipboard(text);
} }
}; };
@ -45,7 +46,7 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) {
*/ */
if (e.key === 'Dead') { if (e.key === 'Dead') {
if (e.code === 'Quote' && e.shiftKey === false) { if (e.code === 'Quote' && e.shiftKey === false) {
this.terminal.onVTKeystroke("'"); this.terminal.onVTKeystroke('\'');
return; return;
} }
if (e.code === 'Quote' && e.shiftKey === true) { if (e.code === 'Quote' && e.shiftKey === true) {
@ -103,11 +104,10 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) {
if (e.metaKey || e.altKey || (e.ctrlKey && e.code === 'Tab')) { if (e.metaKey || e.altKey || (e.ctrlKey && e.code === 'Tab')) {
return; return;
} else {
// Test for valid keys in order to clear the terminal selection
if ((!e.ctrlKey || e.code !== 'ControlLeft') && !e.shiftKey && e.code !== 'CapsLock') {
selection.clear(this.terminal);
} }
if ((!e.ctrlKey || e.code !== 'ControlLeft') && !e.shiftKey && e.code !== 'CapsLock') {
// Test for valid keys in order to clear the terminal selection
selection.clear(this.terminal);
} }
return oldKeyDown.call(this, e); return oldKeyDown.call(this, e);
}; };
@ -116,9 +116,8 @@ const oldKeyPress = hterm.Keyboard.prototype.onKeyPress_;
hterm.Keyboard.prototype.onKeyPress_ = function (e) { hterm.Keyboard.prototype.onKeyPress_ = function (e) {
if (e.metaKey) { if (e.metaKey) {
return; return;
} else {
selection.clear(this.terminal);
} }
selection.clear(this.terminal);
return oldKeyPress.call(this, e); return oldKeyPress.call(this, e);
}; };
@ -130,7 +129,7 @@ hterm.Terminal.prototype.clearPreserveCursorRow = function () {
this.scrollbackRows_.length = 0; this.scrollbackRows_.length = 0;
this.scrollPort_.resetCache(); this.scrollPort_.resetCache();
[this.primaryScreen_, this.alternateScreen_].forEach((screen) => { [this.primaryScreen_, this.alternateScreen_].forEach(screen => {
const bottom = screen.getHeight(); const bottom = screen.getHeight();
if (bottom > 0) { if (bottom > 0) {
this.renumberRows_(0, bottom); this.renumberRows_(0, bottom);
@ -168,17 +167,19 @@ hterm.Terminal.prototype.clearPreserveCursorRow = function () {
// fixes a bug in hterm, where the shorthand hex // fixes a bug in hterm, where the shorthand hex
// is not properly converted to rgb // is not properly converted to rgb
lib.colors.hexToRGB = function (arg) { lib.colors.hexToRGB = function (arg) {
var hex16 = lib.colors.re_.hex16; const hex16 = lib.colors.re_.hex16;
var hex24 = lib.colors.re_.hex24; const hex24 = lib.colors.re_.hex24;
function convert(hex) { function convert(hex) {
if (hex.length === 4) { if (hex.length === 4) {
hex = hex.replace(hex16, function (h, r, g, b) { hex = hex.replace(hex16, (h, r, g, b) => {
return '#' + r + r + g + g + b + b; return '#' + r + r + g + g + b + b;
}); });
} }
var ary = hex.match(hex24); const ary = hex.match(hex24);
if (!ary) return null; if (!ary) {
return null;
}
return 'rgb(' + return 'rgb(' +
parseInt(ary[1], 16) + ', ' + parseInt(ary[1], 16) + ', ' +
@ -188,7 +189,7 @@ lib.colors.hexToRGB = function (arg) {
} }
if (arg instanceof Array) { if (arg instanceof Array) {
for (var i = 0; i < arg.length; i++) { for (let i = 0; i < arg.length; i++) {
arg[i] = convert(arg[i]); arg[i] = convert(arg[i]);
} }
} else { } else {

View file

@ -1,21 +1,22 @@
import rpc from './rpc'; import {createStore, applyMiddleware} from 'redux';
import forceUpdate from 'react-deep-force-update';
import {Provider} from 'react-redux';
import React from 'react'; import React from 'react';
import {render} from 'react-dom'; import {render} from 'react-dom';
import thunk from 'redux-thunk'; import thunk from 'redux-thunk';
import { Provider } from 'react-redux'; import {webFrame} from 'electron';
import rpc from './rpc';
import {init} from './actions/index'; import {init} from './actions/index';
import effects from './utils/effects'; import effects from './utils/effects';
import * as config from './utils/config'; import * as config from './utils/config';
import rootReducer from './reducers/index'; import rootReducer from './reducers/index';
import * as plugins from './utils/plugins'; import * as plugins from './utils/plugins';
import * as uiActions from './actions/ui'; import * as uiActions from './actions/ui';
import forceUpdate from 'react-deep-force-update';
import * as updaterActions from './actions/updater'; import * as updaterActions from './actions/updater';
import * as sessionActions from './actions/sessions'; import * as sessionActions from './actions/sessions';
import { createStore, applyMiddleware } from 'redux';
import HyperTermContainer from './containers/hyperterm'; import HyperTermContainer from './containers/hyperterm';
import {loadConfig, reloadConfig} from './actions/config'; import {loadConfig, reloadConfig} from './actions/config';
import { webFrame } from 'electron';
// Disable pinch zoom // Disable pinch zoom
webFrame.setZoomLevelLimits(1, 1); webFrame.setZoomLevelLimits(1, 1);

View file

@ -79,10 +79,9 @@ const reducer = (state = initialState, action) => {
case SESSION_PTY_EXIT: case SESSION_PTY_EXIT:
if (state.sessions[action.uid]) { if (state.sessions[action.uid]) {
return deleteSession(state, action.uid); return deleteSession(state, action.uid);
} else { }
console.log('ignore pty exit: session removed by user'); console.log('ignore pty exit: session removed by user');
return state; return state;
}
case SESSION_USER_EXIT: case SESSION_USER_EXIT:
return deleteSession(state, action.uid); return deleteSession(state, action.uid);
@ -99,7 +98,7 @@ const reducer = (state = initialState, action) => {
export default decorateSessionsReducer(reducer); export default decorateSessionsReducer(reducer);
function deleteSession(state, uid) { function deleteSession(state, uid) {
return state.updateIn(['sessions'], (sessions) => { return state.updateIn(['sessions'], sessions => {
const sessions_ = sessions.asMutable(); const sessions_ = sessions.asMutable();
delete sessions_[uid]; delete sessions_[uid];
return sessions_; return sessions_;

View file

@ -77,9 +77,9 @@ const initial = Immutable({
const reducer = (state = initial, action) => { const reducer = (state = initial, action) => {
let state_ = state; let state_ = state;
switch (action.type) { switch (action.type) { // eslint-disable-line default-case
case CONFIG_LOAD: case CONFIG_LOAD:
case CONFIG_RELOAD: case CONFIG_RELOAD: // eslint-disable-line no-case-declarations
const {config} = action; const {config} = action;
state_ = state state_ = state
// we unset the user font size override if the // we unset the user font size override if the
@ -91,15 +91,15 @@ const reducer = (state = initial, action) => {
ret.fontSizeOverride = null; ret.fontSizeOverride = null;
} }
if (null != config.fontSize) { if (config.fontSize !== null) {
ret.fontSize = config.fontSize; ret.fontSize = config.fontSize;
} }
if (null != config.fontFamily) { if (config.fontFamily !== null) {
ret.fontFamily = config.fontFamily; ret.fontFamily = config.fontFamily;
} }
if (null != config.cursorColor) { if (config.cursorColor !== null) {
ret.cursorColor = config.cursorColor; ret.cursorColor = config.cursorColor;
} }
@ -107,27 +107,27 @@ const reducer = (state = initial, action) => {
ret.cursorShape = config.cursorShape; ret.cursorShape = config.cursorShape;
} }
if (null != config.borderColor) { if (config.borderColor !== null) {
ret.borderColor = config.borderColor; ret.borderColor = config.borderColor;
} }
if (null != config.padding) { if (config.padding !== null) {
ret.padding = config.padding; ret.padding = config.padding;
} }
if (null != config.foregroundColor) { if (config.foregroundColor !== null) {
ret.foregroundColor = config.foregroundColor; ret.foregroundColor = config.foregroundColor;
} }
if (null != config.backgroundColor) { if (config.backgroundColor !== null) {
ret.backgroundColor = config.backgroundColor; ret.backgroundColor = config.backgroundColor;
} }
if (null != config.css) { if (config.css !== null) {
ret.css = config.css; ret.css = config.css;
} }
if (null != config.termCSS) { if (config.termCSS !== null) {
ret.termCSS = config.termCSS; ret.termCSS = config.termCSS;
} }
@ -135,29 +135,27 @@ const reducer = (state = initial, action) => {
ret.bell = config.bell; ret.bell = config.bell;
} }
if (null !== config.bellSoundURL) { if (config.bellSoundURL !== null) {
ret.bellSoundURL = config.bellSoundURL || initial.bellSoundURL; ret.bellSoundURL = config.bellSoundURL || initial.bellSoundURL;
} }
if (null !== config.copyOnSelect) { if (config.copyOnSelect !== null) {
ret.copyOnSelect = config.copyOnSelect; ret.copyOnSelect = config.copyOnSelect;
} }
if (null != config.colors) { if (config.colors !== null) {
if (Array.isArray(config.colors)) { if (Array.isArray(config.colors)) {
const stateColors = Array.isArray(state.colors) const stateColors = Array.isArray(state.colors) ?
? state.colors state.colors :
: values(state.colors); values(state.colors);
if (stateColors.toString() !== config.colors.toString()) { if (stateColors.toString() !== config.colors.toString()) {
ret.colors = config.colors; ret.colors = config.colors;
} }
} else { } else if (JSON.stringify(state.colors) !== JSON.stringify(config.colors)) {
if (JSON.stringify(state.colors) !== JSON.stringify(config.colors)) {
ret.colors = config.colors; ret.colors = config.colors;
} }
} }
}
return ret; return ret;
})()); })());
@ -181,12 +179,12 @@ const reducer = (state = initial, action) => {
case SESSION_PTY_EXIT: case SESSION_PTY_EXIT:
state_ = state state_ = state
.updateIn(['openAt'], (times) => { .updateIn(['openAt'], times => {
const times_ = times.asMutable(); const times_ = times.asMutable();
delete times_[action.uid]; delete times_[action.uid];
return times_; return times_;
}) })
.updateIn(['activityMarkers'], (markers) => { .updateIn(['activityMarkers'], markers => {
const markers_ = markers.asMutable(); const markers_ = markers.asMutable();
delete markers_[action.uid]; delete markers_[action.uid];
return markers_; return markers_;
@ -202,15 +200,19 @@ const reducer = (state = initial, action) => {
}, {deep: true}); }, {deep: true});
break; break;
case SESSION_PTY_DATA: case SESSION_PTY_DATA: // eslint-disable-line no-case-declarations
// ignore activity markers for current tab // ignore activity markers for current tab
if (action.uid === state.activeUid) break; if (action.uid === state.activeUid) {
break;
}
// current time for comparisons // current time for comparisons
let now = Date.now(); const now = Date.now();
// if first data events after open, ignore // if first data events after open, ignore
if (now - state.openAt[action.uid] < 1000) break; if (now - state.openAt[action.uid] < 1000) {
break;
}
// we ignore activity markers that are within // we ignore activity markers that are within
// proximity of a resize event, since we // proximity of a resize event, since we
@ -274,7 +276,7 @@ const reducer = (state = initial, action) => {
} }
} }
if (null != state.cols && null != state.rows && if (state.cols !== null && state.rows !== null &&
(state.rows !== state_.rows || (state.rows !== state_.rows ||
state.cols !== state_.cols)) { state.cols !== state_.cols)) {
state_ = state_.merge({notifications: {resize: true}}, {deep: true}); state_ = state_.merge({notifications: {resize: true}}, {deep: true});

View file

@ -1,2 +1,3 @@
import RPC from './utils/rpc'; import RPC from './utils/rpc';
export default new RPC(); export default new RPC();

View file

@ -25,7 +25,7 @@ export function getColorList (colors) {
return colors; return colors;
} }
return colorList.map((colorName) => { return colorList.map(colorName => {
return colors[colorName]; return colors[colorName];
}); });
} }

View file

@ -1,4 +1,5 @@
import {ipcRenderer, remote} from 'electron'; import {ipcRenderer, remote} from 'electron';
const plugins = remote.require('./plugins'); const plugins = remote.require('./plugins');
export function getConfig() { export function getConfig() {

View file

@ -5,7 +5,7 @@
// defer or add to existing side effects at will // defer or add to existing side effects at will
// as the result of an action being triggered // as the result of an action being triggered
export default (store) => (next) => (action) => { export default () => next => action => {
const ret = next(action); const ret = next(action);
if (action.effect) { if (action.effect) {
action.effect(); action.effect();

View file

@ -7,11 +7,13 @@
// PR: https://github.com/kevva/executable/pull/10 // PR: https://github.com/kevva/executable/pull/10
export function isExecutable(fileStat) { export function isExecutable(fileStat) {
if (process.platform === 'win32') return true; if (process.platform === 'win32') {
return true;
}
return Boolean( return Boolean(
(fileStat['mode'] & parseInt('0001', 8)) || (fileStat.mode & parseInt('0001', 8)) ||
(fileStat['mode'] & parseInt('0010', 8)) || (fileStat.mode & parseInt('0010', 8)) ||
(fileStat['mode'] & parseInt('0100', 8)) (fileStat.mode & parseInt('0100', 8))
); );
} }

View file

@ -6,8 +6,8 @@ import React from 'react';
import Notification from '../components/notification'; import Notification from '../components/notification';
import notify from './notify'; import notify from './notify';
var Module = require('module'); const Module = require('module'); // eslint-disable-line import/newline-after-import
var originalLoad = Module._load; const originalLoad = Module._load;
Module._load = function (path) { Module._load = function (path) {
if (path === 'react') { if (path === 'react') {
return React; return React;
@ -16,7 +16,7 @@ Module._load = function (path) {
}; };
// remote interface to `../plugins` // remote interface to `../plugins`
let plugins = remote.require('./plugins'); const plugins = remote.require('./plugins');
// `require`d modules // `require`d modules
let modules; let modules;
@ -38,8 +38,10 @@ const { path, localPath } = plugins.getBasePaths();
const clearModulesCache = () => { const clearModulesCache = () => {
// trigger unload hooks // trigger unload hooks
modules.forEach((mod) => { modules.forEach(mod => {
if (mod.onRendererUnload) mod.onRendererUnload(window); if (mod.onRendererUnload) {
mod.onRendererUnload(window);
}
}); });
// clear require cache // clear require cache
@ -51,7 +53,7 @@ const clearModulesCache = () => {
} }
}; };
const getPluginName = (path) => window.require('path').basename(path); const getPluginName = path => window.require('path').basename(path);
const loadModules = () => { const loadModules = () => {
console.log('(re)loading renderer plugins'); console.log('(re)loading renderer plugins');
@ -72,7 +74,7 @@ const loadModules = () => {
termPropsDecorators = []; termPropsDecorators = [];
modules = paths.plugins.concat(paths.localPlugins) modules = paths.plugins.concat(paths.localPlugins)
.map((path) => { .map(path => {
let mod; let mod;
const pluginName = getPluginName(path); const pluginName = getPluginName(path);
@ -83,12 +85,14 @@ const loadModules = () => {
} catch (err) { } catch (err) {
console.error(err.stack); console.error(err.stack);
notify('Plugin load error', `"${pluginName}" failed to load in the renderer process. Check Developer Tools for details.`); notify('Plugin load error', `"${pluginName}" failed to load in the renderer process. Check Developer Tools for details.`);
return; return undefined;
} }
for (const i in mod) { for (const i in mod) {
if ({}.hasOwnProperty.call(mod, i)) {
mod[i]._pluginName = pluginName; mod[i]._pluginName = pluginName;
} }
}
if (mod.middleware) { if (mod.middleware) {
middlewares.push(mod.middleware); middlewares.push(mod.middleware);
@ -152,7 +156,7 @@ const loadModules = () => {
return mod; return mod;
}) })
.filter((mod) => !!mod); .filter(mod => Boolean(mod));
}; };
// load modules for initial decoration // load modules for initial decoration
@ -169,10 +173,12 @@ export function reload () {
export function getTermProps(uid, parentProps, props) { export function getTermProps(uid, parentProps, props) {
let props_; let props_;
termPropsDecorators.forEach((fn) => { termPropsDecorators.forEach(fn => {
let ret_; let ret_;
if (!props_) props_ = Object.assign({}, props); if (!props_) {
props_ = Object.assign({}, props);
}
try { try {
ret_ = fn(uid, parentProps, props_); ret_ = fn(uid, parentProps, props_);
@ -182,7 +188,7 @@ export function getTermProps (uid, parentProps, props) {
return; return;
} }
if (!ret_ || 'object' !== typeof ret_) { if (!ret_ || typeof ret_ !== 'object') {
notify('Plugin error', `${fn._pluginName}: Invalid return value of \`getTermProps\` (object expected).`); notify('Plugin error', `${fn._pluginName}: Invalid return value of \`getTermProps\` (object expected).`);
return; return;
} }
@ -196,10 +202,12 @@ export function getTermProps (uid, parentProps, props) {
export function getTabsProps(parentProps, props) { export function getTabsProps(parentProps, props) {
let props_; let props_;
tabsPropsDecorators.forEach((fn) => { tabsPropsDecorators.forEach(fn => {
let ret_; let ret_;
if (!props_) props_ = Object.assign({}, props); if (!props_) {
props_ = Object.assign({}, props);
}
try { try {
ret_ = fn(parentProps, props_); ret_ = fn(parentProps, props_);
@ -209,7 +217,7 @@ export function getTabsProps (parentProps, props) {
return; return;
} }
if (!ret_ || 'object' !== typeof ret_) { if (!ret_ || typeof ret_ !== 'object') {
notify('Plugin error', `${fn._pluginName}: Invalid return value of \`getTabsProps\` (object expected).`); notify('Plugin error', `${fn._pluginName}: Invalid return value of \`getTabsProps\` (object expected).`);
return; return;
} }
@ -223,10 +231,12 @@ export function getTabsProps (parentProps, props) {
export function getTabProps(tab, parentProps, props) { export function getTabProps(tab, parentProps, props) {
let props_; let props_;
tabPropsDecorators.forEach((fn) => { tabPropsDecorators.forEach(fn => {
let ret_; let ret_;
if (!props_) props_ = Object.assign({}, props); if (!props_) {
props_ = Object.assign({}, props);
}
try { try {
ret_ = fn(tab, parentProps, props_); ret_ = fn(tab, parentProps, props_);
@ -236,7 +246,7 @@ export function getTabProps (tab, parentProps, props) {
return; return;
} }
if (!ret_ || 'object' !== typeof ret_) { if (!ret_ || typeof ret_ !== 'object') {
notify('Plugin error', `${fn._pluginName}: Invalid return value of \`getTabProps\` (object expected).`); notify('Plugin error', `${fn._pluginName}: Invalid return value of \`getTabProps\` (object expected).`);
return; return;
} }
@ -251,11 +261,11 @@ export function getTabProps (tab, parentProps, props) {
// plugins can override mapToState, dispatchToProps // plugins can override mapToState, dispatchToProps
// and the class gets decorated (proxied) // and the class gets decorated (proxied)
export function connect(stateFn, dispatchFn, c, d = {}) { export function connect(stateFn, dispatchFn, c, d = {}) {
return function (Class, name) { return (Class, name) => {
return reduxConnect( return reduxConnect(
function (state) { state => {
let ret = stateFn(state); let ret = stateFn(state);
connectors[name].state.forEach((fn) => { connectors[name].state.forEach(fn => {
let ret_; let ret_;
try { try {
@ -266,7 +276,7 @@ export function connect (stateFn, dispatchFn, c, d = {}) {
return; return;
} }
if (!ret_ || 'object' !== typeof ret_) { if (!ret_ || typeof ret_ !== 'object') {
notify('Plugin error', `${fn._pluginName}: Invalid return value of \`map${name}State\` (object expected).`); notify('Plugin error', `${fn._pluginName}: Invalid return value of \`map${name}State\` (object expected).`);
return; return;
} }
@ -275,9 +285,9 @@ export function connect (stateFn, dispatchFn, c, d = {}) {
}); });
return ret; return ret;
}, },
function (dispatch) { dispatch => {
let ret = dispatchFn(dispatch); let ret = dispatchFn(dispatch);
connectors[name].dispatch.forEach((fn) => { connectors[name].dispatch.forEach(fn => {
let ret_; let ret_;
try { try {
@ -288,7 +298,7 @@ export function connect (stateFn, dispatchFn, c, d = {}) {
return; return;
} }
if (!ret_ || 'object' !== typeof ret_) { if (!ret_ || typeof ret_ !== 'object') {
notify('Plugin error', `${fn._pluginName}: Invalid return value of \`map${name}Dispatch\` (object expected).`); notify('Plugin error', `${fn._pluginName}: Invalid return value of \`map${name}Dispatch\` (object expected).`);
return; return;
} }
@ -307,7 +317,7 @@ export function decorateUIReducer (fn) {
return (state, action) => { return (state, action) => {
let state_ = fn(state, action); let state_ = fn(state, action);
uiReducers.forEach((pluginReducer) => { uiReducers.forEach(pluginReducer => {
let state__; let state__;
try { try {
@ -318,7 +328,7 @@ export function decorateUIReducer (fn) {
return; return;
} }
if (!state__ || 'object' !== typeof state__) { if (!state__ || typeof state__ !== 'object') {
notify('Plugin error', `${fn._pluginName}: Invalid return value of \`reduceUI\`.`); notify('Plugin error', `${fn._pluginName}: Invalid return value of \`reduceUI\`.`);
return; return;
} }
@ -334,7 +344,7 @@ export function decorateSessionsReducer (fn) {
return (state, action) => { return (state, action) => {
let state_ = fn(state, action); let state_ = fn(state, action);
sessionsReducers.forEach((pluginReducer) => { sessionsReducers.forEach(pluginReducer => {
let state__; let state__;
try { try {
@ -345,7 +355,7 @@ export function decorateSessionsReducer (fn) {
return; return;
} }
if (!state__ || 'object' !== typeof state__) { if (!state__ || typeof state__ !== 'object') {
notify('Plugin error', `${fn._pluginName}: Invalid return value of \`reduceSessions\`.`); notify('Plugin error', `${fn._pluginName}: Invalid return value of \`reduceSessions\`.`);
return; return;
} }
@ -358,10 +368,10 @@ export function decorateSessionsReducer (fn) {
} }
// redux middleware generator // redux middleware generator
export const middleware = (store) => (next) => (action) => { export const middleware = store => next => action => {
const nextMiddleware = remaining => action => remaining.length const nextMiddleware = remaining => action => remaining.length ?
? remaining[0](store)(nextMiddleware(remaining.slice(1)))(action) remaining[0](store)(nextMiddleware(remaining.slice(1)))(action) :
: next(action); next(action);
nextMiddleware(middlewares)(action); nextMiddleware(middlewares)(action);
}; };
@ -369,7 +379,7 @@ function getDecorated (parent, name) {
if (!decorated[name]) { if (!decorated[name]) {
let class_ = parent; let class_ = parent;
modules.forEach((mod) => { modules.forEach(mod => {
const method = 'decorate' + name; const method = 'decorate' + name;
const fn = mod[method]; const fn = mod[method];
@ -384,7 +394,7 @@ function getDecorated (parent, name) {
return; return;
} }
if (!class__ || 'function' !== typeof class__.prototype.render) { if (!class__ || typeof class__.prototype.render !== 'function') {
notify('Plugin error', `${fn._pluginName}: Invalid return value of \`${method}\`. No \`render\` method found. Please return a \`React.Component\`.`); notify('Plugin error', `${fn._pluginName}: Invalid return value of \`${method}\`. No \`render\` method found. Please return a \`React.Component\`.`);
return; return;
} }

View file

@ -38,7 +38,9 @@ export default class Client {
} }
emit(ev, data) { emit(ev, data) {
if (!this.id) throw new Error('Not ready'); if (!this.id) {
throw new Error('Not ready');
}
this.ipc.send(this.id, {ev, data}); this.ipc.send(this.id, {ev, data});
} }

View file

@ -6,7 +6,7 @@ exports.clear = function (terminal) {
// Use selection extend upon dblclick // Use selection extend upon dblclick
exports.extend = function (terminal) { exports.extend = function (terminal) {
let sel = terminal.document_.getSelection(); const sel = terminal.document_.getSelection();
// Test if focusNode exist and nodeName is #text // Test if focusNode exist and nodeName is #text
if (sel.focusNode && sel.focusNode.nodeName === '#text') { if (sel.focusNode && sel.focusNode.nodeName === '#text') {
@ -17,10 +17,13 @@ exports.extend = function (terminal) {
// Fix a bug in ScrollPort selectAll behavior // Fix a bug in ScrollPort selectAll behavior
// Select all rows in the viewport // Select all rows in the viewport
exports.all = function (terminal) { exports.all = function (terminal) {
let scrollPort = terminal.scrollPort_; const scrollPort = terminal.scrollPort_;
let firstRow, lastRowIndex, lastRow; let firstRow;
let lastRow;
if (scrollPort.topFold_.nextSibling.rowIndex !== 0) { if (scrollPort.topFold_.nextSibling.rowIndex === 0) {
firstRow = scrollPort.topFold_.nextSibling;
} else {
while (scrollPort.topFold_.previousSibling) { while (scrollPort.topFold_.previousSibling) {
scrollPort.rowNodes_.removeChild(scrollPort.topFold_.previousSibling); scrollPort.rowNodes_.removeChild(scrollPort.topFold_.previousSibling);
} }
@ -28,21 +31,19 @@ exports.all = function (terminal) {
firstRow = scrollPort.fetchRowNode_(0); firstRow = scrollPort.fetchRowNode_(0);
scrollPort.rowNodes_.insertBefore(firstRow, scrollPort.topFold_); scrollPort.rowNodes_.insertBefore(firstRow, scrollPort.topFold_);
scrollPort.syncRowNodesDimensions_(); scrollPort.syncRowNodesDimensions_();
} else {
firstRow = scrollPort.topFold_.nextSibling;
} }
lastRowIndex = scrollPort.rowProvider_.getRowCount() - 1; const lastRowIndex = scrollPort.rowProvider_.getRowCount() - 1;
if (scrollPort.bottomFold_.previousSibling.rowIndex !== lastRowIndex) { if (scrollPort.bottomFold_.previousSibling.rowIndex === lastRowIndex) {
lastRow = scrollPort.bottomFold_.previousSibling.rowIndex;
} else {
while (scrollPort.bottomFold_.nextSibling) { while (scrollPort.bottomFold_.nextSibling) {
scrollPort.rowNodes_.removeChild(scrollPort.bottomFold_.nextSibling); scrollPort.rowNodes_.removeChild(scrollPort.bottomFold_.nextSibling);
} }
lastRow = scrollPort.fetchRowNode_(lastRowIndex); lastRow = scrollPort.fetchRowNode_(lastRowIndex);
scrollPort.rowNodes_.appendChild(lastRow); scrollPort.rowNodes_.appendChild(lastRow);
} else {
lastRow = scrollPort.bottomFold_.previousSibling.rowIndex;
} }
scrollPort.selection.sync(); scrollPort.selection.sync();

View file

@ -3,11 +3,15 @@ import * as regex from './url-regex';
export const domainRegex = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b|^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*:)*?:?0*1$/; export const domainRegex = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b|^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*:)*?:?0*1$/;
export default function isUrlCommand(shell, data) { export default function isUrlCommand(shell, data) {
const matcher = regex[shell]; const matcher = regex[shell]; // eslint-disable-line import/namespace
if (undefined === matcher || !data) return null; if (undefined === matcher || !data) {
return null;
}
const match = data.match(matcher); const match = data.match(matcher);
if (!match) return null; if (!match) {
return null;
}
const protocol = match[1]; const protocol = match[1];
const path = match[2]; const path = match[2];

View file

@ -36,51 +36,47 @@
"devDependencies": { "devDependencies": {
"babel-cli": "^6.11.4", "babel-cli": "^6.11.4",
"babel-core": "^6.11.4", "babel-core": "^6.11.4",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.4", "babel-loader": "^6.2.4",
"babel-preset-react": "^6.11.1", "babel-preset-react": "^6.11.1",
"copy-webpack-plugin": "^3.0.1", "copy-webpack-plugin": "^3.0.1",
"electron-builder": "^7.0.1", "electron-builder": "^7.0.1",
"electron": "1.4.0", "electron": "1.4.0",
"eslint": "^3.2.0", "eslint-config-xo-react": "^0.9.0",
"eslint-config-standard": "^5.3.5", "eslint-plugin-react": "^6.2.2",
"eslint-plugin-promise": "^2.0.0",
"eslint-plugin-react": "^6.0.0",
"eslint-plugin-standard": "^2.0.0",
"husky": "^0.11.6", "husky": "^0.11.6",
"webpack": "^2.1.0-beta.15" "webpack": "^2.1.0-beta.15",
"xo": "^0.16.0"
}, },
"eslintConfig": { "xo": {
"extends": "standard", "extends": "xo-react",
"plugins": [ "esnext": true,
"react" "space": true,
"env": [
"browser",
"node",
"mocha"
], ],
"rules": { "rules": {
"yoda": "off", "react/jsx-filename-extension": 0,
"semi": [ "react/prop-types": 0,
"error", "babel/new-cap": 0,
"always" "quote-props": 0,
], "import/no-extraneous-dependencies": 0,
"no-unused-vars": "error", "no-warning-comments": 0,
"no-extra-semi": "error", "complexity": 0,
"semi-spacing": [ "react/no-danger": 0,
"error", "react/no-string-refs": 0,
{ "react/jsx-key": 0,
"before": false, "no-nested-ternary": 0,
"after": true "react/jsx-no-bind": 0
}
],
"react/jsx-uses-react": "warn",
"react/jsx-uses-vars": "warn"
}, },
"parserOptions": { "ignore": [
"ecmaFeatures": { "dist",
"jsx": true "build",
} "app/dist",
}, "app/static",
"env": { "assets"
"mocha": true ]
}
}, },
"babel": { "babel": {
"presets": [ "presets": [
@ -106,7 +102,7 @@
}, },
"scripts": { "scripts": {
"dev": "webpack --watch", "dev": "webpack --watch",
"lint": "eslint .", "lint": "xo",
"build": "NODE_ENV=production webpack", "build": "NODE_ENV=production webpack",
"test": "npm run lint && electron-mocha test/*", "test": "npm run lint && electron-mocha test/*",
"start": "electron app", "start": "electron app",

View file

@ -1,3 +1,4 @@
/* eslint-disable prefer-arrow-callback */
require('../setup'); require('../setup');
const {_toDependencies} = require('../../app/plugins'); const {_toDependencies} = require('../../app/plugins');
@ -9,7 +10,7 @@ describe('plugins', function () {
'@org1/project4#1.0.0', '@org2/project5@alpha', '@org1/project4#1.0.0', '@org2/project5@alpha',
'@org3/project6']; '@org3/project6'];
_toDependencies({plugins: plugins}).should.be.eql({ _toDependencies({plugins}).should.be.eql({
'project1': 'latest', 'project1': 'latest',
'project2': '1.0.0', 'project2': '1.0.0',
'project3': 'beta', 'project3': 'beta',

View file

@ -1,6 +1,7 @@
const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const Copy = require('copy-webpack-plugin'); const Copy = require('copy-webpack-plugin');
const path = require('path');
const nodeEnv = process.env.NODE_ENV || 'development'; const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production'; const isProd = nodeEnv === 'production';
@ -27,7 +28,7 @@ module.exports = {
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': { 'process.env': { // eslint-disable-line quote-props
'NODE_ENV': JSON.stringify(nodeEnv) 'NODE_ENV': JSON.stringify(nodeEnv)
} }
}), }),