-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathindex.tsx
246 lines (193 loc) · 7.22 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import './v8-snapshot-util';
import {webFrame} from 'electron';
import React from 'react';
import {createRoot} from 'react-dom/client';
import {Provider} from 'react-redux';
import type {configOptions} from '../typings/config';
import {loadConfig, reloadConfig} from './actions/config';
import init from './actions/index';
import {addNotificationMessage} from './actions/notifications';
import * as sessionActions from './actions/sessions';
import * as termGroupActions from './actions/term-groups';
import * as uiActions from './actions/ui';
import * as updaterActions from './actions/updater';
import HyperContainer from './containers/hyper';
import rpc from './rpc';
import configureStore from './store/configure-store';
import * as config from './utils/config';
import {getBase64FileData} from './utils/file';
import * as plugins from './utils/plugins';
// 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);
}
const store_ = configureStore();
Object.defineProperty(window, 'store', {get: () => store_});
Object.defineProperty(window, 'rpc', {get: () => rpc});
Object.defineProperty(window, 'config', {get: () => config});
Object.defineProperty(window, 'plugins', {get: () => plugins});
const fetchFileData = (configData: configOptions) => {
const configInfo: configOptions = {...configData, bellSound: null};
if (!configInfo.bell || configInfo.bell.toUpperCase() !== 'SOUND' || !configInfo.bellSoundURL) {
store_.dispatch(reloadConfig(configInfo));
return;
}
void getBase64FileData(configInfo.bellSoundURL).then((base64FileData) => {
// prepend "base64," to the result of this method in order for this to work properly within xterm.js
const bellSound = !base64FileData ? null : 'base64,' + base64FileData;
configInfo.bellSound = bellSound;
store_.dispatch(reloadConfig(configInfo));
});
};
// initialize config
store_.dispatch(loadConfig(config.getConfig()));
fetchFileData(config.getConfig());
config.subscribe(() => {
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));
}
});
// initialize communication with main electron process
// and subscribe to all user intents for example from menus
rpc.on('ready', () => {
store_.dispatch(init());
store_.dispatch(uiActions.setFontSmoothing());
});
rpc.on('session add', (data) => {
store_.dispatch(sessionActions.addSession(data));
});
rpc.on('session data', (d: string) => {
// the uid is a uuid v4 so it's 36 chars long
const uid = d.slice(0, 36);
const data = d.slice(36);
store_.dispatch(sessionActions.addSessionData(uid, data));
});
rpc.on('session data send', ({uid, data, escaped}) => {
store_.dispatch(sessionActions.sendSessionData(uid, data, escaped));
});
rpc.on('session exit', ({uid}) => {
store_.dispatch(termGroupActions.ptyExitTermGroup(uid));
});
rpc.on('termgroup close req', () => {
store_.dispatch(termGroupActions.exitActiveTermGroup());
});
rpc.on('session clear req', () => {
store_.dispatch(sessionActions.clearActiveSession());
});
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'));
});
rpc.on('session break req', () => {
store_.dispatch(sessionActions.sendSessionData(null, '\x03'));
});
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'));
});
rpc.on('session search', () => {
store_.dispatch(sessionActions.openSearch());
});
rpc.on('session search close', () => {
store_.dispatch(sessionActions.closeSearch());
});
rpc.on('termgroup add req', ({activeUid, profile}) => {
store_.dispatch(termGroupActions.requestTermGroup(activeUid, profile));
});
rpc.on('split request horizontal', ({activeUid, profile}) => {
store_.dispatch(termGroupActions.requestHorizontalSplit(activeUid, profile));
});
rpc.on('split request vertical', ({activeUid, profile}) => {
store_.dispatch(termGroupActions.requestVerticalSplit(activeUid, profile));
});
rpc.on('reset fontSize req', () => {
store_.dispatch(uiActions.resetFontSize());
});
rpc.on('increase fontSize req', () => {
store_.dispatch(uiActions.increaseFontSize());
});
rpc.on('decrease fontSize req', () => {
store_.dispatch(uiActions.decreaseFontSize());
});
rpc.on('move left req', () => {
store_.dispatch(uiActions.moveLeft());
});
rpc.on('move right req', () => {
store_.dispatch(uiActions.moveRight());
});
rpc.on('move jump req', (index) => {
store_.dispatch(uiActions.moveTo(index));
});
rpc.on('next pane req', () => {
store_.dispatch(uiActions.moveToNextPane());
});
rpc.on('prev pane req', () => {
store_.dispatch(uiActions.moveToPreviousPane());
});
rpc.on('open file', ({path}) => {
store_.dispatch(uiActions.openFile(path));
});
rpc.on('open ssh', (parsedUrl) => {
store_.dispatch(uiActions.openSSH(parsedUrl));
});
rpc.on('update available', ({releaseName, releaseNotes, releaseUrl, canInstall}) => {
store_.dispatch(updaterActions.updateAvailable(releaseName, releaseNotes, releaseUrl, canInstall));
});
rpc.on('move', (window) => {
store_.dispatch(uiActions.windowMove(window));
});
rpc.on('windowGeometry change', (data) => {
store_.dispatch(uiActions.windowGeometryUpdated(data));
});
rpc.on('add notification', ({text, url, dismissable}) => {
store_.dispatch(addNotificationMessage(text, url, dismissable));
});
rpc.on('enter full screen', () => {
store_.dispatch(uiActions.enterFullScreen());
});
rpc.on('leave full screen', () => {
store_.dispatch(uiActions.leaveFullScreen());
});
const root = createRoot(document.getElementById('mount')!);
root.render(
<Provider store={store_}>
<HyperContainer />
</Provider>
);
rpc.on('reload', () => {
plugins.reload();
});