2017-01-21 09:54:32 -09:00
|
|
|
// Print diagnostic information for a few arguments instead of running Hyper.
|
|
|
|
|
if (['--help', '-v', '--version'].includes(process.argv[1])) {
|
|
|
|
|
const {version} = require('./package');
|
|
|
|
|
const configLocation = process.platform === 'win32' ? process.env.userprofile + '\\.hyper.js' : '~/.hyper.js';
|
|
|
|
|
console.log(`Hyper version ${version}`);
|
|
|
|
|
console.log('Hyper does not accept any command line arguments. Please modify the config file instead.');
|
|
|
|
|
console.log(`Hyper configuration file located at: ${configLocation}`);
|
|
|
|
|
// eslint-disable-next-line unicorn/no-process-exit
|
|
|
|
|
process.exit();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 03:06:03 -09:00
|
|
|
// handle startup squirrel events
|
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
|
// eslint-disable-next-line import/order
|
|
|
|
|
const systemContextMenu = require('./system-context-menu');
|
|
|
|
|
|
|
|
|
|
switch (process.argv[1]) {
|
|
|
|
|
case '--squirrel-install':
|
|
|
|
|
case '--squirrel-updated':
|
|
|
|
|
systemContextMenu.add(() => {
|
|
|
|
|
// eslint-disable-next-line curly, unicorn/no-process-exit
|
|
|
|
|
if (require('electron-squirrel-startup')) process.exit();
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case '--squirrel-uninstall':
|
|
|
|
|
systemContextMenu.remove(() => {
|
|
|
|
|
// eslint-disable-next-line curly, unicorn/no-process-exit
|
|
|
|
|
if (require('electron-squirrel-startup')) process.exit();
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// eslint-disable-next-line curly, unicorn/no-process-exit
|
|
|
|
|
if (require('electron-squirrel-startup')) process.exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
// Native
|
2016-11-22 03:06:03 -09:00
|
|
|
const {resolve, isAbsolute} = require('path');
|
2016-12-02 14:51:16 -09:00
|
|
|
const {homedir} = require('os');
|
2016-09-21 06:27:11 -08:00
|
|
|
|
|
|
|
|
// Packages
|
|
|
|
|
const {parse: parseUrl} = require('url');
|
|
|
|
|
const {app, BrowserWindow, shell, Menu} = require('electron');
|
2016-10-12 17:35:44 -08:00
|
|
|
const {gitDescribe} = require('git-describe');
|
2016-07-25 10:01:01 -08:00
|
|
|
const uuid = require('uuid');
|
2016-08-04 05:43:57 -08:00
|
|
|
const fileUriToPath = require('file-uri-to-path');
|
2016-07-01 12:26:51 -08:00
|
|
|
const isDev = require('electron-is-dev');
|
2016-09-21 06:27:11 -08:00
|
|
|
|
|
|
|
|
// Ours
|
2016-07-06 06:58:39 -08:00
|
|
|
const AutoUpdater = require('./auto-updater');
|
2016-09-18 22:47:33 -08:00
|
|
|
const toElectronBackgroundColor = require('./utils/to-electron-background-color');
|
2017-05-25 22:59:02 -08:00
|
|
|
const AppMenu = require('./menus/menu');
|
2016-09-21 06:27:11 -08:00
|
|
|
const createRPC = require('./rpc');
|
2016-07-26 15:37:42 -08:00
|
|
|
const notify = require('./notify');
|
2016-10-07 19:28:40 -08:00
|
|
|
const fetchNotifications = require('./notifications');
|
2016-07-07 12:49:34 -08:00
|
|
|
|
2017-05-20 13:35:11 -08:00
|
|
|
app.commandLine.appendSwitch('js-flags', '--harmony-async-await');
|
2016-07-27 18:02:19 -08:00
|
|
|
|
2016-07-07 12:49:34 -08:00
|
|
|
// set up config
|
2016-07-07 07:17:02 -08:00
|
|
|
const config = require('./config');
|
2016-09-21 06:27:11 -08:00
|
|
|
|
2016-07-07 12:49:34 -08:00
|
|
|
config.init();
|
2016-09-21 06:27:11 -08:00
|
|
|
|
2016-07-07 12:49:34 -08:00
|
|
|
const plugins = require('./plugins');
|
2016-07-24 10:03:24 -08:00
|
|
|
const Session = require('./session');
|
2016-06-30 22:01:04 -08:00
|
|
|
|
2016-07-18 16:11:30 -08:00
|
|
|
const windowSet = new Set([]);
|
|
|
|
|
|
2016-07-16 10:58:21 -08:00
|
|
|
// expose to plugins
|
|
|
|
|
app.config = config;
|
|
|
|
|
app.plugins = plugins;
|
2016-07-18 16:11:30 -08:00
|
|
|
app.getWindows = () => new Set([...windowSet]); // return a clone
|
2016-07-16 10:58:21 -08:00
|
|
|
|
2016-10-10 02:26:47 -08:00
|
|
|
// function to retrieve the last focused window in windowSet;
|
2016-08-01 14:52:21 -08:00
|
|
|
// added to app object in order to expose it to plugins.
|
|
|
|
|
app.getLastFocusedWindow = () => {
|
2016-09-21 06:27:11 -08:00
|
|
|
if (!windowSet.size) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-08-01 14:52:21 -08:00
|
|
|
return Array.from(windowSet).reduce((lastWindow, win) => {
|
|
|
|
|
return win.focusTime > lastWindow.focusTime ? win : lastWindow;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-01 12:26:51 -08:00
|
|
|
if (isDev) {
|
|
|
|
|
console.log('running in dev mode');
|
2016-09-20 14:51:15 -08:00
|
|
|
|
|
|
|
|
// Overide default appVersion which is set from package.json
|
|
|
|
|
gitDescribe({customArguments: ['--tags']}, (error, gitInfo) => {
|
2016-09-21 06:27:11 -08:00
|
|
|
if (!error) {
|
|
|
|
|
app.setVersion(gitInfo.raw);
|
|
|
|
|
}
|
2016-09-20 14:51:15 -08:00
|
|
|
});
|
2016-06-30 22:01:04 -08:00
|
|
|
} else {
|
2016-07-01 12:26:51 -08:00
|
|
|
console.log('running in prod mode');
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
|
|
|
|
|
2016-07-01 12:26:51 -08:00
|
|
|
const url = 'file://' + resolve(
|
2016-07-01 14:44:24 -08:00
|
|
|
isDev ? __dirname : app.getAppPath(),
|
2016-07-01 12:26:51 -08:00
|
|
|
'index.html'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
console.log('electron will open', url);
|
|
|
|
|
|
2016-09-21 14:11:42 -08:00
|
|
|
app.on('ready', () => installDevExtensions(isDev).then(() => {
|
2016-10-01 17:44:34 -08:00
|
|
|
function createWindow(fn, options = {}) {
|
2016-07-26 15:37:42 -08:00
|
|
|
let cfg = plugins.getDecoratedConfig();
|
|
|
|
|
|
2016-10-01 17:44:34 -08:00
|
|
|
const winSet = app.config.window.get();
|
|
|
|
|
let [startX, startY] = winSet.position;
|
|
|
|
|
|
|
|
|
|
const [width, height] = options.size ? options.size : (cfg.windowSize || winSet.size);
|
2016-09-21 06:27:11 -08:00
|
|
|
const {screen} = require('electron');
|
2016-08-01 16:00:49 -08:00
|
|
|
|
2016-10-01 17:44:34 -08:00
|
|
|
const winPos = options.position;
|
2016-08-01 16:00:49 -08:00
|
|
|
|
|
|
|
|
// Open the new window roughly the height of the header away from the
|
|
|
|
|
// previous window. This also ensures in multi monitor setups that the
|
|
|
|
|
// new terminal is on the correct screen.
|
2016-08-06 02:58:57 -08:00
|
|
|
const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow();
|
2016-10-01 17:44:34 -08:00
|
|
|
// In case of options defaults position and size, we should ignore the focusedWindow.
|
|
|
|
|
if (winPos !== undefined) {
|
|
|
|
|
[startX, startY] = winPos;
|
|
|
|
|
} else if (focusedWindow) {
|
2016-08-06 02:58:57 -08:00
|
|
|
const points = focusedWindow.getPosition();
|
2016-09-21 06:27:11 -08:00
|
|
|
const currentScreen = screen.getDisplayNearestPoint({x: points[0], y: points[1]});
|
2016-08-01 16:00:49 -08:00
|
|
|
|
|
|
|
|
const biggestX = ((points[0] + 100 + width) - currentScreen.bounds.x);
|
|
|
|
|
const biggestY = ((points[1] + 100 + height) - currentScreen.bounds.y);
|
|
|
|
|
|
|
|
|
|
if (biggestX > currentScreen.size.width) {
|
|
|
|
|
startX = 50;
|
|
|
|
|
} else {
|
|
|
|
|
startX = points[0] + 34;
|
|
|
|
|
}
|
|
|
|
|
if (biggestY > currentScreen.size.height) {
|
|
|
|
|
startY = 50;
|
|
|
|
|
} else {
|
|
|
|
|
startY = points[1] + 34;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-18 08:44:33 -08:00
|
|
|
|
2016-07-21 16:32:39 -08:00
|
|
|
const browserDefaults = {
|
2016-07-22 10:47:23 -08:00
|
|
|
width,
|
|
|
|
|
height,
|
2016-07-14 06:55:24 -08:00
|
|
|
minHeight: 190,
|
|
|
|
|
minWidth: 370,
|
2016-11-11 08:18:04 -09:00
|
|
|
titleBarStyle: 'hidden-inset', // macOS only
|
2016-10-06 09:33:08 -08:00
|
|
|
title: 'Hyper.app',
|
2016-09-18 22:47:33 -08:00
|
|
|
backgroundColor: toElectronBackgroundColor(cfg.backgroundColor || '#000'),
|
2016-11-11 08:18:04 -09:00
|
|
|
// we want to go frameless on windows and linux
|
|
|
|
|
frame: process.platform === 'darwin',
|
2017-01-10 20:45:49 -09:00
|
|
|
transparent: process.platform === 'darwin',
|
2016-07-16 17:30:12 -08:00
|
|
|
icon: resolve(__dirname, 'static/icon.png'),
|
2016-10-08 08:26:07 -08:00
|
|
|
// we only want to show when the prompt is ready for user input
|
|
|
|
|
// HYPERTERM_DEBUG for backwards compatibility with hyperterm
|
|
|
|
|
show: process.env.HYPER_DEBUG || process.env.HYPERTERM_DEBUG || isDev,
|
2016-08-01 16:00:49 -08:00
|
|
|
x: startX,
|
2016-11-16 09:44:04 -09:00
|
|
|
y: startY,
|
|
|
|
|
acceptFirstMouse: true
|
2016-07-21 16:32:39 -08:00
|
|
|
};
|
|
|
|
|
const browserOptions = plugins.getDecoratedBrowserOptions(browserDefaults);
|
|
|
|
|
|
|
|
|
|
const win = new BrowserWindow(browserOptions);
|
2016-07-18 16:11:30 -08:00
|
|
|
windowSet.add(win);
|
2016-08-01 14:52:21 -08:00
|
|
|
|
2016-07-01 12:26:51 -08:00
|
|
|
win.loadURL(url);
|
2016-06-30 22:01:04 -08:00
|
|
|
|
|
|
|
|
const rpc = createRPC(win);
|
|
|
|
|
const sessions = new Map();
|
2016-07-07 15:22:45 -08:00
|
|
|
|
|
|
|
|
// config changes
|
2016-07-07 07:17:02 -08:00
|
|
|
const cfgUnsubscribe = config.subscribe(() => {
|
2016-07-26 15:37:42 -08:00
|
|
|
const cfg_ = plugins.getDecoratedConfig();
|
|
|
|
|
|
2016-09-18 22:47:33 -08:00
|
|
|
// notify renderer
|
2016-07-07 07:17:02 -08:00
|
|
|
win.webContents.send('config change');
|
2016-07-26 15:37:42 -08:00
|
|
|
|
2016-09-18 22:47:33 -08:00
|
|
|
// notify user that shell changes require new sessions
|
2017-02-15 12:03:39 -09:00
|
|
|
if (cfg_.shell !== cfg.shell ||
|
|
|
|
|
JSON.stringify(cfg_.shellArgs) !== JSON.stringify(cfg.shellArgs)) {
|
2016-07-26 15:37:42 -08:00
|
|
|
notify(
|
|
|
|
|
'Shell configuration changed!',
|
|
|
|
|
'Open a new tab or window to start using the new shell'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-18 22:47:33 -08:00
|
|
|
// update background color if necessary
|
2016-07-26 15:37:42 -08:00
|
|
|
cfg = cfg_;
|
2016-07-07 07:17:02 -08:00
|
|
|
});
|
|
|
|
|
|
2016-06-30 22:01:04 -08:00
|
|
|
rpc.on('init', () => {
|
2016-12-19 07:17:26 -09:00
|
|
|
// we update the backgroundColor once the init is called.
|
|
|
|
|
// when we do a win.reload() we need need to reset the backgroundColor
|
|
|
|
|
win.setBackgroundColor(toElectronBackgroundColor(cfg.backgroundColor || '#000'));
|
2016-12-29 11:52:37 -09:00
|
|
|
win.show();
|
2016-08-01 14:52:21 -08:00
|
|
|
|
|
|
|
|
// If no callback is passed to createWindow,
|
|
|
|
|
// a new session will be created by default.
|
2016-09-21 06:27:11 -08:00
|
|
|
if (!fn) {
|
2016-10-03 18:00:50 -08:00
|
|
|
fn = win => win.rpc.emit('termgroup add req');
|
2016-09-21 06:27:11 -08:00
|
|
|
}
|
2016-08-01 14:52:21 -08:00
|
|
|
|
|
|
|
|
// app.windowCallback is the createWindow callback
|
2016-10-10 02:26:47 -08:00
|
|
|
// that can be set before the 'ready' app event
|
|
|
|
|
// and createWindow deifinition. It's executed in place of
|
2016-08-01 14:52:21 -08:00
|
|
|
// the callback passed as parameter, and deleted right after.
|
|
|
|
|
(app.windowCallback || fn)(win);
|
|
|
|
|
delete (app.windowCallback);
|
2016-07-07 15:22:45 -08:00
|
|
|
|
2016-10-07 19:28:40 -08:00
|
|
|
fetchNotifications(win);
|
2016-07-07 15:22:45 -08:00
|
|
|
// auto updates
|
2016-07-21 10:54:14 -08:00
|
|
|
if (!isDev && process.platform !== 'linux') {
|
2016-07-08 04:48:53 -08:00
|
|
|
AutoUpdater(win);
|
2016-07-07 15:22:45 -08:00
|
|
|
} else {
|
|
|
|
|
console.log('ignoring auto updates during dev');
|
|
|
|
|
}
|
2016-06-30 22:01:04 -08:00
|
|
|
});
|
|
|
|
|
|
2016-12-02 14:51:16 -09:00
|
|
|
rpc.on('new', ({rows = 40, cols = 100, cwd = process.argv[1] && isAbsolute(process.argv[1]) ? process.argv[1] : homedir(), splitDirection}) => {
|
2016-07-17 13:05:08 -08:00
|
|
|
const shell = cfg.shell;
|
2016-08-31 18:33:01 -08:00
|
|
|
const shellArgs = cfg.shellArgs && Array.from(cfg.shellArgs);
|
2016-07-17 13:05:08 -08:00
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
initSession({rows, cols, cwd, shell, shellArgs}, (uid, session) => {
|
2016-06-30 22:01:04 -08:00
|
|
|
sessions.set(uid, session);
|
2016-07-14 15:40:15 -08:00
|
|
|
rpc.emit('session add', {
|
2016-10-03 18:00:50 -08:00
|
|
|
rows,
|
|
|
|
|
cols,
|
2016-07-14 15:40:15 -08:00
|
|
|
uid,
|
2016-10-03 18:00:50 -08:00
|
|
|
splitDirection,
|
2016-07-16 14:41:13 -08:00
|
|
|
shell: session.shell,
|
|
|
|
|
pid: session.pty.pid
|
2016-07-14 15:40:15 -08:00
|
|
|
});
|
2016-06-30 22:01:04 -08:00
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
session.on('data', data => {
|
2017-02-17 18:55:48 -09:00
|
|
|
rpc.emit('session data', uid + data);
|
2016-06-30 22:01:04 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
session.on('exit', () => {
|
2016-09-21 06:27:11 -08:00
|
|
|
rpc.emit('session exit', {uid});
|
2016-07-03 12:35:45 -08:00
|
|
|
sessions.delete(uid);
|
2016-06-30 22:01:04 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
rpc.on('exit', ({uid}) => {
|
2016-07-24 10:02:21 -08:00
|
|
|
const session = sessions.get(uid);
|
|
|
|
|
if (session) {
|
|
|
|
|
session.exit();
|
|
|
|
|
} else {
|
|
|
|
|
console.log('session not found by', uid);
|
|
|
|
|
}
|
2016-06-30 22:01:04 -08:00
|
|
|
});
|
|
|
|
|
|
2016-07-04 16:48:38 -08:00
|
|
|
rpc.on('unmaximize', () => {
|
2016-07-04 17:54:55 -08:00
|
|
|
win.unmaximize();
|
2016-07-04 16:48:38 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('maximize', () => {
|
2016-07-04 17:54:55 -08:00
|
|
|
win.maximize();
|
2016-07-04 16:48:38 -08:00
|
|
|
});
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
rpc.on('resize', ({uid, cols, rows}) => {
|
|
|
|
|
const session = sessions.get(uid);
|
|
|
|
|
session.resize({cols, rows});
|
2016-06-30 22:01:04 -08:00
|
|
|
});
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
rpc.on('data', ({uid, data}) => {
|
2016-06-30 22:01:04 -08:00
|
|
|
sessions.get(uid).write(data);
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
rpc.on('open external', ({url}) => {
|
2016-07-01 12:01:33 -08:00
|
|
|
shell.openExternal(url);
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-19 10:30:57 -08:00
|
|
|
rpc.win.on('move', () => {
|
|
|
|
|
rpc.emit('move');
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-11 08:18:04 -09:00
|
|
|
rpc.on('open hamburger menu', ({x, y}) => {
|
2017-05-03 14:30:00 -08:00
|
|
|
Menu.getApplicationMenu().popup(Math.ceil(x), Math.ceil(y));
|
2016-11-11 08:18:04 -09:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('minimize', () => {
|
|
|
|
|
win.minimize();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('close', () => {
|
|
|
|
|
win.close();
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-30 22:01:04 -08:00
|
|
|
const deleteSessions = () => {
|
|
|
|
|
sessions.forEach((session, key) => {
|
|
|
|
|
session.removeAllListeners();
|
|
|
|
|
session.destroy();
|
|
|
|
|
sessions.delete(key);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// we reset the rpc channel only upon
|
|
|
|
|
// subsequent refreshes (ie: F5)
|
|
|
|
|
let i = 0;
|
|
|
|
|
win.webContents.on('did-navigate', () => {
|
|
|
|
|
if (i++) {
|
|
|
|
|
deleteSessions();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-08-04 05:43:57 -08:00
|
|
|
// If file is dropped onto the terminal window, navigate event is prevented
|
|
|
|
|
// and his path is added to active session.
|
|
|
|
|
win.webContents.on('will-navigate', (event, url) => {
|
2016-09-21 06:27:11 -08:00
|
|
|
const protocol = typeof url === 'string' && parseUrl(url).protocol;
|
2016-08-04 05:43:57 -08:00
|
|
|
if (protocol === 'file:') {
|
|
|
|
|
event.preventDefault();
|
2016-09-21 06:27:11 -08:00
|
|
|
const path = fileUriToPath(url).replace(/ /g, '\\ ');
|
|
|
|
|
rpc.emit('session data send', {data: path});
|
2017-01-25 16:24:01 -09:00
|
|
|
} else if (protocol === 'http:' || protocol === 'https:') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
rpc.emit('session data send', {data: url});
|
2016-08-04 05:43:57 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-07 16:16:44 -08:00
|
|
|
// expose internals to extension authors
|
|
|
|
|
win.rpc = rpc;
|
|
|
|
|
win.sessions = sessions;
|
|
|
|
|
|
|
|
|
|
const load = () => {
|
|
|
|
|
plugins.onWindow(win);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// load plugins
|
|
|
|
|
load();
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
const pluginsUnsubscribe = plugins.subscribe(err => {
|
2016-07-13 12:44:24 -08:00
|
|
|
if (!err) {
|
|
|
|
|
load();
|
2016-07-16 10:58:56 -08:00
|
|
|
win.webContents.send('plugins change');
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
2016-07-07 16:16:44 -08:00
|
|
|
});
|
|
|
|
|
|
2016-08-01 14:52:21 -08:00
|
|
|
// Keep track of focus time of every window, to figure out
|
|
|
|
|
// which one of the existing window is the last focused.
|
|
|
|
|
// Works nicely even if a window is closed and removed.
|
2016-08-06 02:58:57 -08:00
|
|
|
const updateFocusTime = () => {
|
2016-08-01 14:52:21 -08:00
|
|
|
win.focusTime = process.uptime();
|
2016-08-06 02:58:57 -08:00
|
|
|
};
|
|
|
|
|
win.on('focus', () => {
|
|
|
|
|
updateFocusTime();
|
2016-08-01 14:52:21 -08:00
|
|
|
});
|
2016-08-06 02:58:57 -08:00
|
|
|
// Ensure focusTime is set on window open. The focus event doesn't
|
|
|
|
|
// fire from the dock (see bug #583)
|
|
|
|
|
updateFocusTime();
|
2016-08-01 14:52:21 -08:00
|
|
|
|
2016-06-30 22:01:04 -08:00
|
|
|
// the window can be closed by the browser process itself
|
|
|
|
|
win.on('close', () => {
|
2016-10-17 16:16:39 -08:00
|
|
|
app.config.window.recordState(win);
|
2016-07-18 16:11:30 -08:00
|
|
|
windowSet.delete(win);
|
2016-06-30 22:01:04 -08:00
|
|
|
rpc.destroy();
|
|
|
|
|
deleteSessions();
|
2016-07-07 07:17:02 -08:00
|
|
|
cfgUnsubscribe();
|
2016-07-07 16:16:44 -08:00
|
|
|
pluginsUnsubscribe();
|
2016-07-29 20:12:21 -08:00
|
|
|
});
|
|
|
|
|
|
2017-01-10 20:45:49 -09:00
|
|
|
// Same deal as above, grabbing the window titlebar when the window
|
|
|
|
|
// is maximized on Windows results in unmaximize, without hitting any
|
|
|
|
|
// app buttons
|
|
|
|
|
for (const ev of ['maximize', 'unmaximize', 'minimize', 'restore']) {
|
|
|
|
|
win.on(ev, () => rpc.emit('windowGeometry change'));
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 20:12:21 -08:00
|
|
|
win.on('closed', () => {
|
2016-11-11 08:18:04 -09:00
|
|
|
if (process.platform !== 'darwin' && windowSet.size === 0) {
|
2016-07-29 20:12:21 -08:00
|
|
|
app.quit();
|
2016-07-26 19:11:54 -08:00
|
|
|
}
|
2016-06-30 22:01:04 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when opening create a new window
|
|
|
|
|
createWindow();
|
|
|
|
|
|
2016-07-18 16:11:30 -08:00
|
|
|
// expose to plugins
|
|
|
|
|
app.createWindow = createWindow;
|
|
|
|
|
|
2016-07-01 16:02:08 -08:00
|
|
|
// mac only. when the dock icon is clicked
|
|
|
|
|
// and we don't have any active windows open,
|
|
|
|
|
// we open one
|
|
|
|
|
app.on('activate', () => {
|
2016-07-18 16:11:30 -08:00
|
|
|
if (!windowSet.size) {
|
2016-07-01 16:02:08 -08:00
|
|
|
createWindow();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-25 22:59:02 -08:00
|
|
|
const makeMenu = () => {
|
|
|
|
|
const menu = plugins.decorateMenu(
|
|
|
|
|
AppMenu(createWindow, () => {
|
2016-09-21 06:27:11 -08:00
|
|
|
plugins.updatePlugins({force: true});
|
2017-05-25 22:59:02 -08:00
|
|
|
})
|
|
|
|
|
);
|
2016-07-18 08:44:33 -08:00
|
|
|
|
2016-08-03 16:52:31 -08:00
|
|
|
// If we're on Mac make a Dock Menu
|
|
|
|
|
if (process.platform === 'darwin') {
|
2016-09-21 06:27:11 -08:00
|
|
|
const dockMenu = Menu.buildFromTemplate([{
|
|
|
|
|
label: 'New Window',
|
|
|
|
|
click() {
|
|
|
|
|
createWindow();
|
|
|
|
|
}
|
|
|
|
|
}]);
|
2016-08-03 16:52:31 -08:00
|
|
|
app.dock.setMenu(dockMenu);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 22:59:02 -08:00
|
|
|
Menu.setApplicationMenu(
|
|
|
|
|
Menu.buildFromTemplate(menu)
|
|
|
|
|
);
|
2016-07-07 16:16:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const load = () => {
|
|
|
|
|
plugins.onApp(app);
|
2017-05-25 22:59:02 -08:00
|
|
|
makeMenu();
|
2016-07-07 16:16:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
load();
|
|
|
|
|
plugins.subscribe(load);
|
2016-09-21 14:11:42 -08:00
|
|
|
}).catch(err => {
|
|
|
|
|
console.error('Error while loading devtools extensions', err);
|
|
|
|
|
}));
|
2016-06-30 22:01:04 -08:00
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
function initSession(opts, fn) {
|
2016-07-25 10:01:01 -08:00
|
|
|
fn(uuid.v4(), new Session(opts));
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
2016-08-01 14:52:21 -08:00
|
|
|
|
|
|
|
|
app.on('open-file', (event, path) => {
|
|
|
|
|
const lastWindow = app.getLastFocusedWindow();
|
2016-09-21 06:27:11 -08:00
|
|
|
const callback = win => win.rpc.emit('open file', {path});
|
2016-08-01 14:52:21 -08:00
|
|
|
if (lastWindow) {
|
|
|
|
|
callback(lastWindow);
|
2016-09-21 06:27:11 -08:00
|
|
|
} else if (!lastWindow && {}.hasOwnProperty.call(app, 'createWindow')) {
|
2016-08-01 14:52:21 -08:00
|
|
|
app.createWindow(callback);
|
|
|
|
|
} else {
|
2016-10-10 02:26:47 -08:00
|
|
|
// If createWindow doesn't exist yet ('ready' event was not fired),
|
2016-08-01 14:52:21 -08:00
|
|
|
// sets his callback to an app.windowCallback property.
|
|
|
|
|
app.windowCallback = callback;
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-09-21 14:11:42 -08:00
|
|
|
|
|
|
|
|
function installDevExtensions(isDev) {
|
|
|
|
|
if (!isDev) {
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
2016-10-12 17:35:44 -08:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
|
const installer = require('electron-devtools-installer');
|
2016-09-21 14:11:42 -08:00
|
|
|
|
|
|
|
|
const extensions = [
|
|
|
|
|
'REACT_DEVELOPER_TOOLS',
|
|
|
|
|
'REDUX_DEVTOOLS'
|
|
|
|
|
];
|
|
|
|
|
const forceDownload = Boolean(process.env.UPGRADE_EXTENSIONS);
|
|
|
|
|
|
|
|
|
|
return Promise.all(extensions.map(name => installer.default(installer[name], forceDownload)));
|
|
|
|
|
}
|