2022-04-14 08:50:54 -08:00
|
|
|
import './v8-snapshot-util';
|
2016-10-12 17:35:44 -08:00
|
|
|
import {webFrame} from 'electron';
|
2016-07-13 12:44:24 -08:00
|
|
|
import React from 'react';
|
2023-07-25 09:30:19 -08:00
|
|
|
|
2023-07-23 23:29:12 -08:00
|
|
|
import {createRoot} from 'react-dom/client';
|
2023-07-25 09:30:19 -08:00
|
|
|
import {Provider} from 'react-redux';
|
2016-09-21 06:27:11 -08:00
|
|
|
|
2023-07-25 09:30:19 -08:00
|
|
|
import type {configOptions} from '../typings/config';
|
|
|
|
|
|
|
|
|
|
import {loadConfig, reloadConfig} from './actions/config';
|
2016-10-25 04:53:15 -08:00
|
|
|
import init from './actions/index';
|
2023-07-25 09:30:19 -08:00
|
|
|
import {addNotificationMessage} from './actions/notifications';
|
2016-07-13 12:44:24 -08:00
|
|
|
import * as sessionActions from './actions/sessions';
|
2016-10-03 18:00:50 -08:00
|
|
|
import * as termGroupActions from './actions/term-groups';
|
2023-07-25 09:30:19 -08:00
|
|
|
import * as uiActions from './actions/ui';
|
|
|
|
|
import * as updaterActions from './actions/updater';
|
2016-10-08 08:26:07 -08:00
|
|
|
import HyperContainer from './containers/hyper';
|
2023-07-25 09:30:19 -08:00
|
|
|
import rpc from './rpc';
|
2016-09-21 18:29:23 -08:00
|
|
|
import configureStore from './store/configure-store';
|
2023-07-25 09:30:19 -08:00
|
|
|
import * as config from './utils/config';
|
|
|
|
|
import {getBase64FileData} from './utils/file';
|
|
|
|
|
import * as plugins from './utils/plugins';
|
2016-07-20 14:20:40 -08:00
|
|
|
|
2018-12-25 17:15:25 -09:00
|
|
|
// On Linux, the default zoom was somehow changed with Electron 3 (or maybe 2).
|
|
|
|
|
// Setting zoom factor to 1.2 brings back the normal default size
|
|
|
|
|
if (process.platform === 'linux') {
|
|
|
|
|
webFrame.setZoomFactor(1.2);
|
|
|
|
|
}
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2016-09-21 14:11:42 -08:00
|
|
|
const store_ = configureStore();
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2019-10-12 02:15:25 -08:00
|
|
|
Object.defineProperty(window, 'store', {get: () => store_});
|
|
|
|
|
Object.defineProperty(window, 'rpc', {get: () => rpc});
|
|
|
|
|
Object.defineProperty(window, 'config', {get: () => config});
|
|
|
|
|
Object.defineProperty(window, 'plugins', {get: () => plugins});
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2020-04-27 05:32:08 -08:00
|
|
|
const fetchFileData = (configData: configOptions) => {
|
|
|
|
|
const configInfo: configOptions = {...configData, bellSound: null};
|
2019-10-08 07:13:35 -08:00
|
|
|
if (!configInfo.bell || configInfo.bell.toUpperCase() !== 'SOUND' || !configInfo.bellSoundURL) {
|
2019-10-02 16:08:40 -08:00
|
|
|
store_.dispatch(reloadConfig(configInfo));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 08:42:20 -08:00
|
|
|
void getBase64FileData(configInfo.bellSoundURL).then((base64FileData) => {
|
2019-10-02 16:08:40 -08:00
|
|
|
// prepend "base64," to the result of this method in order for this to work properly within xterm.js
|
2019-10-08 07:13:35 -08:00
|
|
|
const bellSound = !base64FileData ? null : 'base64,' + base64FileData;
|
2019-10-02 16:08:40 -08:00
|
|
|
configInfo.bellSound = bellSound;
|
|
|
|
|
store_.dispatch(reloadConfig(configInfo));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
// initialize config
|
2016-07-13 21:19:32 -08:00
|
|
|
store_.dispatch(loadConfig(config.getConfig()));
|
2019-10-02 16:08:40 -08:00
|
|
|
fetchFileData(config.getConfig());
|
|
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
config.subscribe(() => {
|
2019-10-02 16:08:40 -08:00
|
|
|
const configInfo = config.getConfig();
|
|
|
|
|
configInfo.bellSound = store_.getState().ui.bellSound;
|
|
|
|
|
// The only async part of the config is the bellSound so we will check if the bellSoundURL
|
|
|
|
|
// has changed to determine if we should re-read this file and dispatch an update to the config
|
|
|
|
|
if (store_.getState().ui.bellSoundURL !== config.getConfig().bellSoundURL) {
|
|
|
|
|
fetchFileData(configInfo);
|
|
|
|
|
} else {
|
|
|
|
|
// No change in the bellSoundURL so continue with a normal reloadConfig, reusing the value
|
|
|
|
|
// we already have for `bellSound`
|
|
|
|
|
store_.dispatch(reloadConfig(configInfo));
|
|
|
|
|
}
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// initialize communication with main electron process
|
2016-07-17 13:05:37 -08:00
|
|
|
// and subscribe to all user intents for example from menus
|
2016-07-13 12:44:24 -08:00
|
|
|
rpc.on('ready', () => {
|
2016-07-13 21:19:32 -08:00
|
|
|
store_.dispatch(init());
|
2016-07-19 10:30:57 -08:00
|
|
|
store_.dispatch(uiActions.setFontSmoothing());
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
2020-03-25 02:15:08 -08:00
|
|
|
rpc.on('session add', (data) => {
|
2016-10-03 18:00:50 -08:00
|
|
|
store_.dispatch(sessionActions.addSession(data));
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
2020-06-19 04:51:34 -08:00
|
|
|
rpc.on('session data', (d: string) => {
|
2017-02-17 18:55:48 -09:00
|
|
|
// the uid is a uuid v4 so it's 36 chars long
|
|
|
|
|
const uid = d.slice(0, 36);
|
|
|
|
|
const data = d.slice(36);
|
2017-09-25 04:00:11 -08:00
|
|
|
store_.dispatch(sessionActions.addSessionData(uid, data));
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
2017-06-14 08:12:03 -08:00
|
|
|
rpc.on('session data send', ({uid, data, escaped}) => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(uid, data, escaped));
|
2016-08-04 05:43:57 -08:00
|
|
|
});
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
rpc.on('session exit', ({uid}) => {
|
2016-10-03 18:00:50 -08:00
|
|
|
store_.dispatch(termGroupActions.ptyExitTermGroup(uid));
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
rpc.on('termgroup close req', () => {
|
|
|
|
|
store_.dispatch(termGroupActions.exitActiveTermGroup());
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session clear req', () => {
|
2016-07-13 21:19:32 -08:00
|
|
|
store_.dispatch(sessionActions.clearActiveSession());
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
2017-11-06 11:27:25 -09:00
|
|
|
rpc.on('session move word left req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1bb'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session move word right req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1bf'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session move line beginning req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1bOH'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session move line end req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1bOF'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session del word left req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1b\x7f'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session del word right req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1bd'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session del line beginning req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1bw'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session del line end req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x10B'));
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-18 07:17:20 -09:00
|
|
|
rpc.on('session break req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x03'));
|
2019-09-23 09:37:22 -08:00
|
|
|
});
|
|
|
|
|
|
2020-12-09 21:21:47 -09:00
|
|
|
rpc.on('session stop req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1a'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session quit req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x1c'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session tmux req', () => {
|
|
|
|
|
store_.dispatch(sessionActions.sendSessionData(null, '\x02'));
|
|
|
|
|
});
|
|
|
|
|
|
2019-09-23 09:37:22 -08:00
|
|
|
rpc.on('session search', () => {
|
2022-01-08 20:35:57 -09:00
|
|
|
store_.dispatch(sessionActions.openSearch());
|
2019-09-23 09:37:22 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('session search close', () => {
|
|
|
|
|
store_.dispatch(sessionActions.closeSearch());
|
2017-12-18 07:17:20 -09:00
|
|
|
});
|
|
|
|
|
|
2023-06-28 21:04:33 -08:00
|
|
|
rpc.on('termgroup add req', ({activeUid, profile}) => {
|
|
|
|
|
store_.dispatch(termGroupActions.requestTermGroup(activeUid, profile));
|
2016-10-03 18:00:50 -08:00
|
|
|
});
|
|
|
|
|
|
2023-06-28 21:04:33 -08:00
|
|
|
rpc.on('split request horizontal', ({activeUid, profile}) => {
|
|
|
|
|
store_.dispatch(termGroupActions.requestHorizontalSplit(activeUid, profile));
|
2016-10-03 18:00:50 -08:00
|
|
|
});
|
|
|
|
|
|
2023-06-28 21:04:33 -08:00
|
|
|
rpc.on('split request vertical', ({activeUid, profile}) => {
|
|
|
|
|
store_.dispatch(termGroupActions.requestVerticalSplit(activeUid, profile));
|
2016-10-03 18:00:50 -08:00
|
|
|
});
|
|
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
rpc.on('reset fontSize req', () => {
|
2016-07-13 21:19:32 -08:00
|
|
|
store_.dispatch(uiActions.resetFontSize());
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('increase fontSize req', () => {
|
2016-07-13 21:19:32 -08:00
|
|
|
store_.dispatch(uiActions.increaseFontSize());
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('decrease fontSize req', () => {
|
2016-07-13 21:37:46 -08:00
|
|
|
store_.dispatch(uiActions.decreaseFontSize());
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('move left req', () => {
|
2016-07-13 21:19:32 -08:00
|
|
|
store_.dispatch(uiActions.moveLeft());
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('move right req', () => {
|
2016-07-13 21:19:32 -08:00
|
|
|
store_.dispatch(uiActions.moveRight());
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
2020-03-25 02:15:08 -08:00
|
|
|
rpc.on('move jump req', (index) => {
|
2017-10-05 10:39:39 -08:00
|
|
|
store_.dispatch(uiActions.moveTo(index));
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
rpc.on('next pane req', () => {
|
|
|
|
|
store_.dispatch(uiActions.moveToNextPane());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('prev pane req', () => {
|
|
|
|
|
store_.dispatch(uiActions.moveToPreviousPane());
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
rpc.on('open file', ({path}) => {
|
2016-08-01 14:52:21 -08:00
|
|
|
store_.dispatch(uiActions.openFile(path));
|
|
|
|
|
});
|
|
|
|
|
|
2023-05-05 20:52:45 -08:00
|
|
|
rpc.on('open ssh', (parsedUrl) => {
|
|
|
|
|
store_.dispatch(uiActions.openSSH(parsedUrl));
|
2018-02-12 11:20:45 -09:00
|
|
|
});
|
|
|
|
|
|
2017-11-29 04:26:24 -09:00
|
|
|
rpc.on('update available', ({releaseName, releaseNotes, releaseUrl, canInstall}) => {
|
|
|
|
|
store_.dispatch(updaterActions.updateAvailable(releaseName, releaseNotes, releaseUrl, canInstall));
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
|
2020-03-25 02:15:08 -08:00
|
|
|
rpc.on('move', (window) => {
|
2019-02-26 14:22:52 -09:00
|
|
|
store_.dispatch(uiActions.windowMove(window));
|
2016-07-19 10:30:57 -08:00
|
|
|
});
|
|
|
|
|
|
2021-09-07 21:57:40 -08:00
|
|
|
rpc.on('windowGeometry change', (data) => {
|
|
|
|
|
store_.dispatch(uiActions.windowGeometryUpdated(data));
|
2017-01-10 20:45:49 -09:00
|
|
|
});
|
|
|
|
|
|
2016-10-07 19:28:40 -08:00
|
|
|
rpc.on('add notification', ({text, url, dismissable}) => {
|
|
|
|
|
store_.dispatch(addNotificationMessage(text, url, dismissable));
|
|
|
|
|
});
|
|
|
|
|
|
2019-05-08 17:43:50 -08:00
|
|
|
rpc.on('enter full screen', () => {
|
|
|
|
|
store_.dispatch(uiActions.enterFullScreen());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rpc.on('leave full screen', () => {
|
|
|
|
|
store_.dispatch(uiActions.leaveFullScreen());
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-23 23:29:12 -08:00
|
|
|
const root = createRoot(document.getElementById('mount')!);
|
|
|
|
|
|
|
|
|
|
root.render(
|
2016-09-21 06:27:11 -08:00
|
|
|
<Provider store={store_}>
|
2017-09-10 05:35:10 -08:00
|
|
|
<HyperContainer />
|
2023-07-23 23:29:12 -08:00
|
|
|
</Provider>
|
2016-07-13 12:44:24 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
rpc.on('reload', () => {
|
|
|
|
|
plugins.reload();
|
|
|
|
|
});
|