Skip to content

Commit 8a8fdac

Browse files
committed
Code style: Standard => XO ✨
1 parent c7c5780 commit 8a8fdac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+847
-720
lines changed

app/auto-updater.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
const { autoUpdater } = require('electron');
2-
const { version } = require('./package');
3-
const notify = require('./notify'); // eslint-disable-line no-unused-vars
1+
const {autoUpdater} = require('electron');
42
const ms = require('ms');
53

4+
const notify = require('./notify'); // eslint-disable-line no-unused-vars
5+
const {version} = require('./package');
6+
67
// accepted values: `osx`, `win32`
78
// https://nuts.gitbook.com/update-windows.html
8-
const platform = 'darwin' === process.platform
9-
? 'osx'
10-
: process.platform;
9+
const platform = process.platform === 'darwin' ?
10+
'osx' :
11+
process.platform;
1112
const FEED_URL = `https://hyperterm-updates.now.sh/update/${platform}`;
1213
let isInit = false;
1314

14-
function init () {
15+
function init() {
1516
autoUpdater.on('error', (err, msg) => {
1617
console.error('Error fetching updates', msg + ' (' + err.stack + ')');
1718
});
@@ -30,12 +31,14 @@ function init () {
3031
}
3132

3233
module.exports = function (win) {
33-
if (!isInit) init();
34+
if (!isInit) {
35+
init();
36+
}
3437

35-
const { rpc } = win;
38+
const {rpc} = win;
3639

3740
const onupdate = (ev, releaseNotes, releaseName) => {
38-
rpc.emit('update available', { releaseNotes, releaseName });
41+
rpc.emit('update available', {releaseNotes, releaseName});
3942
};
4043

4144
autoUpdater.on('update-downloaded', onupdate);

app/config.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
const { dialog } = require('electron');
2-
const { homedir } = require('os');
3-
const { resolve } = require('path');
4-
const { readFileSync, writeFileSync } = require('fs');
5-
const gaze = require('gaze');
1+
const {homedir} = require('os');
2+
const {readFileSync, writeFileSync} = require('fs');
3+
const {resolve} = require('path');
64
const vm = require('vm');
5+
6+
const {dialog} = require('electron');
7+
const gaze = require('gaze');
78
const notify = require('./notify');
89

910
const path = resolve(homedir(), '.hyperterm.js');
1011
const watchers = [];
1112

1213
let cfg = {};
1314

14-
function watch () {
15+
function watch() {
1516
gaze(path, function (err) {
16-
if (err) throw err;
17+
if (err) {
18+
throw err;
19+
}
1720
this.on('changed', () => {
1821
try {
1922
if (exec(readFileSync(path, 'utf8'))) {
2023
notify('HyperTerm configuration reloaded!');
21-
watchers.forEach((fn) => fn());
24+
watchers.forEach(fn => fn());
2225
}
2326
} catch (err) {
2427
dialog.showMessageBox({
@@ -31,12 +34,14 @@ function watch () {
3134
}
3235

3336
let _str; // last script
34-
function exec (str) {
35-
if (str === _str) return false;
37+
function exec(str) {
38+
if (str === _str) {
39+
return false;
40+
}
3641
_str = str;
3742
const script = new vm.Script(str);
3843
const module = {};
39-
script.runInNewContext({ module });
44+
script.runInNewContext({module});
4045
if (!module.exports) {
4146
throw new Error('Error reading configuration: `module.exports` not set');
4247
}

app/index.js

+47-37
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
const { app, BrowserWindow, shell, Menu } = require('electron');
2-
const createRPC = require('./rpc');
3-
const createMenu = require('./menu');
1+
const {parse: parseUrl} = require('url');
2+
const {resolve} = require('path');
3+
4+
const {app, BrowserWindow, shell, Menu} = require('electron');
45
const uuid = require('uuid');
5-
const { resolve } = require('path');
6-
const { parse: parseUrl } = require('url');
76
const fileUriToPath = require('file-uri-to-path');
87
const isDev = require('electron-is-dev');
98
const AutoUpdater = require('./auto-updater');
109
const toElectronBackgroundColor = require('./utils/to-electron-background-color');
10+
11+
const createMenu = require('./menu');
12+
const createRPC = require('./rpc');
1113
const notify = require('./notify');
1214

1315
app.commandLine.appendSwitch('js-flags', '--harmony');
1416

1517
// set up config
1618
const config = require('./config');
19+
1720
config.init();
21+
1822
const plugins = require('./plugins');
1923
const Session = require('./session');
2024

@@ -28,7 +32,9 @@ app.getWindows = () => new Set([...windowSet]); // return a clone
2832
// function to retrive the last focused window in windowSet;
2933
// added to app object in order to expose it to plugins.
3034
app.getLastFocusedWindow = () => {
31-
if (!windowSet.size) return null;
35+
if (!windowSet.size) {
36+
return null;
37+
}
3238
return Array.from(windowSet).reduce((lastWindow, win) => {
3339
return win.focusTime > lastWindow.focusTime ? win : lastWindow;
3440
});
@@ -48,11 +54,11 @@ const url = 'file://' + resolve(
4854
console.log('electron will open', url);
4955

5056
app.on('ready', () => {
51-
function createWindow (fn) {
57+
function createWindow(fn) {
5258
let cfg = plugins.getDecoratedConfig();
5359

5460
const [width, height] = cfg.windowSize || [540, 380];
55-
const { screen } = require('electron');
61+
const {screen} = require('electron');
5662

5763
let startX = 50;
5864
let startY = 50;
@@ -63,7 +69,7 @@ app.on('ready', () => {
6369
const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow();
6470
if (focusedWindow) {
6571
const points = focusedWindow.getPosition();
66-
const currentScreen = screen.getDisplayNearestPoint({ x: points[0], y: points[1] });
72+
const currentScreen = screen.getDisplayNearestPoint({x: points[0], y: points[1]});
6773

6874
const biggestX = ((points[0] + 100 + width) - currentScreen.bounds.x);
6975
const biggestY = ((points[1] + 100 + height) - currentScreen.bounds.y);
@@ -132,7 +138,9 @@ app.on('ready', () => {
132138

133139
// If no callback is passed to createWindow,
134140
// a new session will be created by default.
135-
if (!fn) fn = (win) => win.rpc.emit('session add req');
141+
if (!fn) {
142+
fn = win => win.rpc.emit('session add req');
143+
}
136144

137145
// app.windowCallback is the createWindow callback
138146
// that can be setted before the 'ready' app event
@@ -149,29 +157,29 @@ app.on('ready', () => {
149157
}
150158
});
151159

152-
rpc.on('new', ({ rows = 40, cols = 100, cwd = process.env.HOME }) => {
160+
rpc.on('new', ({rows = 40, cols = 100, cwd = process.env.HOME}) => {
153161
const shell = cfg.shell;
154162
const shellArgs = cfg.shellArgs && Array.from(cfg.shellArgs);
155163

156-
initSession({ rows, cols, cwd, shell, shellArgs }, (uid, session) => {
164+
initSession({rows, cols, cwd, shell, shellArgs}, (uid, session) => {
157165
sessions.set(uid, session);
158166
rpc.emit('session add', {
159167
uid,
160168
shell: session.shell,
161169
pid: session.pty.pid
162170
});
163171

164-
session.on('data', (data) => {
165-
rpc.emit('session data', { uid, data });
172+
session.on('data', data => {
173+
rpc.emit('session data', {uid, data});
166174
});
167175

168-
session.on('title', (title) => {
176+
session.on('title', title => {
169177
win.setTitle(title);
170-
rpc.emit('session title', { uid, title });
178+
rpc.emit('session title', {uid, title});
171179
});
172180

173181
session.on('exit', () => {
174-
rpc.emit('session exit', { uid });
182+
rpc.emit('session exit', {uid});
175183
sessions.delete(uid);
176184
});
177185
});
@@ -180,7 +188,7 @@ app.on('ready', () => {
180188
// TODO: this goes away when we are able to poll
181189
// for the title ourseleves, instead of relying
182190
// on Session and focus/blur to subscribe
183-
rpc.on('focus', ({ uid }) => {
191+
rpc.on('focus', ({uid}) => {
184192
const session = sessions.get(uid);
185193
if (typeof session !== 'undefined' && typeof session.lastTitle !== 'undefined') {
186194
win.setTitle(session.lastTitle);
@@ -191,7 +199,7 @@ app.on('ready', () => {
191199
console.log('session not found by', uid);
192200
}
193201
});
194-
rpc.on('blur', ({ uid }) => {
202+
rpc.on('blur', ({uid}) => {
195203
const session = sessions.get(uid);
196204

197205
if (session) {
@@ -201,7 +209,7 @@ app.on('ready', () => {
201209
}
202210
});
203211

204-
rpc.on('exit', ({ uid }) => {
212+
rpc.on('exit', ({uid}) => {
205213
const session = sessions.get(uid);
206214

207215
if (session) {
@@ -219,17 +227,17 @@ app.on('ready', () => {
219227
win.maximize();
220228
});
221229

222-
rpc.on('resize', ({ cols, rows }) => {
223-
sessions.forEach((session) => {
224-
session.resize({ cols, rows });
230+
rpc.on('resize', ({cols, rows}) => {
231+
sessions.forEach(session => {
232+
session.resize({cols, rows});
225233
});
226234
});
227235

228-
rpc.on('data', ({ uid, data }) => {
236+
rpc.on('data', ({uid, data}) => {
229237
sessions.get(uid).write(data);
230238
});
231239

232-
rpc.on('open external', ({ url }) => {
240+
rpc.on('open external', ({url}) => {
233241
shell.openExternal(url);
234242
});
235243

@@ -257,11 +265,11 @@ app.on('ready', () => {
257265
// If file is dropped onto the terminal window, navigate event is prevented
258266
// and his path is added to active session.
259267
win.webContents.on('will-navigate', (event, url) => {
260-
var protocol = typeof url === 'string' && parseUrl(url).protocol;
268+
const protocol = typeof url === 'string' && parseUrl(url).protocol;
261269
if (protocol === 'file:') {
262270
event.preventDefault();
263-
let path = fileUriToPath(url).replace(/ /g, '\\ ');
264-
rpc.emit('session data send', { data: path });
271+
const path = fileUriToPath(url).replace(/ /g, '\\ ');
272+
rpc.emit('session data send', {data: path});
265273
}
266274
});
267275

@@ -276,7 +284,7 @@ app.on('ready', () => {
276284
// load plugins
277285
load();
278286

279-
const pluginsUnsubscribe = plugins.subscribe((err) => {
287+
const pluginsUnsubscribe = plugins.subscribe(err => {
280288
if (!err) {
281289
load();
282290
win.webContents.send('plugins change');
@@ -331,16 +339,18 @@ app.on('ready', () => {
331339
const tpl = plugins.decorateMenu(createMenu({
332340
createWindow,
333341
updatePlugins: () => {
334-
plugins.updatePlugins({ force: true });
342+
plugins.updatePlugins({force: true});
335343
}
336344
}));
337345

338346
// If we're on Mac make a Dock Menu
339347
if (process.platform === 'darwin') {
340-
const { app, Menu } = require('electron');
341-
const dockMenu = Menu.buildFromTemplate([
342-
{label: 'New Window', click () { createWindow(); }}
343-
]);
348+
const dockMenu = Menu.buildFromTemplate([{
349+
label: 'New Window',
350+
click() {
351+
createWindow();
352+
}
353+
}]);
344354
app.dock.setMenu(dockMenu);
345355
}
346356

@@ -356,16 +366,16 @@ app.on('ready', () => {
356366
plugins.subscribe(load);
357367
});
358368

359-
function initSession (opts, fn) {
369+
function initSession(opts, fn) {
360370
fn(uuid.v4(), new Session(opts));
361371
}
362372

363373
app.on('open-file', (event, path) => {
364374
const lastWindow = app.getLastFocusedWindow();
365-
const callback = win => win.rpc.emit('open file', { path });
375+
const callback = win => win.rpc.emit('open file', {path});
366376
if (lastWindow) {
367377
callback(lastWindow);
368-
} else if (!lastWindow && app.hasOwnProperty('createWindow')) {
378+
} else if (!lastWindow && {}.hasOwnProperty.call(app, 'createWindow')) {
369379
app.createWindow(callback);
370380
} else {
371381
// if createWindow not exists yet ('ready' event was not fired),

0 commit comments

Comments
 (0)