@lethevimlet/sshift 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server/index.js +12 -8
- package/src/webapp/js/app.js +117 -25
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -225,14 +225,6 @@ async function initializeServer() {
|
|
|
225
225
|
key: sslCredentials.key,
|
|
226
226
|
cert: sslCredentials.cert
|
|
227
227
|
}, app);
|
|
228
|
-
server.on('request', (req, res) => {
|
|
229
|
-
if (!req.socket.encrypted) {
|
|
230
|
-
const host = req.headers.host ? req.headers.host.split(':')[0] : 'localhost';
|
|
231
|
-
const port = getPort();
|
|
232
|
-
res.writeHead(301, { Location: `https://${host}:${port}${req.url}` });
|
|
233
|
-
res.end();
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
228
|
actuallyHttps = true;
|
|
237
229
|
console.log('[HTTPS] HTTPS server created with HTTP redirect enabled (dual-protocol)');
|
|
238
230
|
} else {
|
|
@@ -282,6 +274,18 @@ async function initializeServer() {
|
|
|
282
274
|
config,
|
|
283
275
|
});
|
|
284
276
|
|
|
277
|
+
// HTTP to HTTPS redirect middleware (for dual-protocol httpolyglot server)
|
|
278
|
+
if (enableHttpRedirect) {
|
|
279
|
+
app.use((req, res, next) => {
|
|
280
|
+
if (!req.socket.encrypted) {
|
|
281
|
+
const host = req.headers.host ? req.headers.host.split(':')[0] : 'localhost';
|
|
282
|
+
const port = getPort();
|
|
283
|
+
return res.redirect(301, `https://${host}:${port}${req.url}`);
|
|
284
|
+
}
|
|
285
|
+
next();
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
285
289
|
// Middleware
|
|
286
290
|
app.use(express.json());
|
|
287
291
|
|
package/src/webapp/js/app.js
CHANGED
|
@@ -980,6 +980,45 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
980
980
|
// Don't persist - font size is session-only
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
// Clear the WebGL glyph texture atlas and force a full repaint.
|
|
984
|
+
// The atlas caches rasterised glyphs; if it was built before the web font
|
|
985
|
+
// finished loading (or after a DPR / font-size change) those cached glyphs
|
|
986
|
+
// are blank or stale, producing the "black box" rendering artefacts.
|
|
987
|
+
// Clearing forces every cell to be re-rasterised with correct glyphs.
|
|
988
|
+
_resetWebGLAtlas(session) {
|
|
989
|
+
if (!session || !session.terminal) return;
|
|
990
|
+
if (session.webglAddon) {
|
|
991
|
+
try {
|
|
992
|
+
session.webglAddon.clearTextureAtlas();
|
|
993
|
+
} catch (_) {}
|
|
994
|
+
}
|
|
995
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// Watch for devicePixelRatio changes (zoom, monitor move, DPI switch).
|
|
999
|
+
// When DPR changes the WebGL glyph atlas is built for the old pixel ratio
|
|
1000
|
+
// and every glyph becomes mis-scaled; clearing the atlas forces a rebuild.
|
|
1001
|
+
_setupDPRListener() {
|
|
1002
|
+
let currentDPR = window.devicePixelRatio;
|
|
1003
|
+
const query = matchMedia(`(resolution: ${currentDPR}dppx)`);
|
|
1004
|
+
const onChange = () => {
|
|
1005
|
+
const newDPR = window.devicePixelRatio;
|
|
1006
|
+
if (newDPR !== currentDPR) {
|
|
1007
|
+
console.log('[SSHIFT] devicePixelRatio changed from', currentDPR, 'to', newDPR);
|
|
1008
|
+
currentDPR = newDPR;
|
|
1009
|
+
this.sessions.forEach(session => this._resetWebGLAtlas(session));
|
|
1010
|
+
this.sftpSessions.forEach(session => this._resetWebGLAtlas(session));
|
|
1011
|
+
}
|
|
1012
|
+
// Re-register for the new DPR value
|
|
1013
|
+
this._setupDPRListener();
|
|
1014
|
+
};
|
|
1015
|
+
if (query.addEventListener) {
|
|
1016
|
+
query.addEventListener('change', onChange, { once: true });
|
|
1017
|
+
} else if (query.addListener) {
|
|
1018
|
+
query.addListener(onChange);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
983
1022
|
// Robust terminal fit with validation and retry.
|
|
984
1023
|
// Sometimes fit() is called before the browser finishes laying out a
|
|
985
1024
|
// container that just became visible (display:none -> display:flex).
|
|
@@ -1027,6 +1066,11 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1027
1066
|
}
|
|
1028
1067
|
|
|
1029
1068
|
console.log('[SSHIFT] Terminal fitted, cols:', terminal.cols, 'rows:', terminal.rows);
|
|
1069
|
+
|
|
1070
|
+
// Resize changes cell metrics; clear the WebGL atlas so glyphs are
|
|
1071
|
+
// re-rasterised at the new size rather than stretched from the old cache.
|
|
1072
|
+
this._resetWebGLAtlas(session);
|
|
1073
|
+
|
|
1030
1074
|
return true;
|
|
1031
1075
|
}
|
|
1032
1076
|
|
|
@@ -1063,8 +1107,11 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1063
1107
|
|
|
1064
1108
|
// Update the terminal
|
|
1065
1109
|
session.terminal.options.fontSize = size;
|
|
1066
|
-
|
|
1067
|
-
|
|
1110
|
+
|
|
1111
|
+
// Font-size changes invalidate the glyph atlas — clear it so
|
|
1112
|
+
// glyphs are re-rasterised at the new size.
|
|
1113
|
+
this._resetWebGLAtlas(session);
|
|
1114
|
+
|
|
1068
1115
|
if (session.fitAddon && session.isController) {
|
|
1069
1116
|
this._fitTerminal(session);
|
|
1070
1117
|
}
|
|
@@ -1092,7 +1139,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1092
1139
|
this.sessions.forEach((session) => {
|
|
1093
1140
|
if (session.terminal) {
|
|
1094
1141
|
session.terminal.options.fontSize = size;
|
|
1095
|
-
|
|
1142
|
+
this._resetWebGLAtlas(session);
|
|
1096
1143
|
if (session.fitAddon && session.isController) {
|
|
1097
1144
|
this._fitTerminal(session);
|
|
1098
1145
|
}
|
|
@@ -1105,7 +1152,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1105
1152
|
this.sftpSessions.forEach((session) => {
|
|
1106
1153
|
if (session.terminal) {
|
|
1107
1154
|
session.terminal.options.fontSize = size;
|
|
1108
|
-
|
|
1155
|
+
this._resetWebGLAtlas(session);
|
|
1109
1156
|
if (session.fitAddon) {
|
|
1110
1157
|
this._fitTerminal(session);
|
|
1111
1158
|
}
|
|
@@ -1299,8 +1346,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1299
1346
|
const newTheme = this.getTerminalTheme(theme);
|
|
1300
1347
|
console.log('[SSHIFT] Applying theme to terminal:', newTheme);
|
|
1301
1348
|
session.terminal.options.theme = newTheme;
|
|
1302
|
-
|
|
1303
|
-
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1349
|
+
this._resetWebGLAtlas(session);
|
|
1304
1350
|
|
|
1305
1351
|
// Update wrapper background to match terminal background
|
|
1306
1352
|
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
@@ -1321,8 +1367,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1321
1367
|
if (session.terminal) {
|
|
1322
1368
|
const newTheme = this.getTerminalTheme(theme);
|
|
1323
1369
|
session.terminal.options.theme = newTheme;
|
|
1324
|
-
|
|
1325
|
-
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1370
|
+
this._resetWebGLAtlas(session);
|
|
1326
1371
|
|
|
1327
1372
|
// Update wrapper background to match terminal background
|
|
1328
1373
|
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
@@ -2306,7 +2351,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2306
2351
|
// Set font size for this SFTP session
|
|
2307
2352
|
sftpSession.fontSize = Math.max(this.minFontSize, Math.min(this.maxFontSize, newSize));
|
|
2308
2353
|
sftpSession.terminal.options.fontSize = sftpSession.fontSize;
|
|
2309
|
-
|
|
2354
|
+
this._resetWebGLAtlas(sftpSession);
|
|
2310
2355
|
|
|
2311
2356
|
if (sftpSession.fitAddon) {
|
|
2312
2357
|
this._fitTerminal(sftpSession);
|
|
@@ -2430,6 +2475,12 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2430
2475
|
// Fix mobile viewport height issues
|
|
2431
2476
|
this.fixMobileViewport();
|
|
2432
2477
|
|
|
2478
|
+
// Listen for devicePixelRatio changes (browser zoom, monitor move, etc.).
|
|
2479
|
+
// DPR changes invalidate the WebGL glyph atlas because cell metrics are
|
|
2480
|
+
// derived from CSS pixels * DPR — a different DPR means every cached
|
|
2481
|
+
// glyph is now the wrong size and must be re-rasterised.
|
|
2482
|
+
this._setupDPRListener();
|
|
2483
|
+
|
|
2433
2484
|
// Load sticky config first
|
|
2434
2485
|
await this.loadStickyConfig();
|
|
2435
2486
|
|
|
@@ -6535,19 +6586,20 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
6535
6586
|
type: 'ssh',
|
|
6536
6587
|
terminal: null,
|
|
6537
6588
|
fitAddon: null,
|
|
6589
|
+
webglAddon: null,
|
|
6538
6590
|
connecting: true,
|
|
6539
6591
|
connected: false,
|
|
6540
|
-
connectionData,
|
|
6541
|
-
isRestoring: !!restoreSessionId,
|
|
6542
|
-
isAtBottom: true,
|
|
6543
|
-
isController: false,
|
|
6544
|
-
syncing: false,
|
|
6545
|
-
fontSize: this.terminalFontSize,
|
|
6546
|
-
mobileHandler: null,
|
|
6547
|
-
writeChunks: [],
|
|
6548
|
-
writeRAF: null,
|
|
6549
|
-
flushRemaining: null,
|
|
6550
|
-
originalScrollback: null,
|
|
6592
|
+
connectionData,
|
|
6593
|
+
isRestoring: !!restoreSessionId,
|
|
6594
|
+
isAtBottom: true,
|
|
6595
|
+
isController: false,
|
|
6596
|
+
syncing: false,
|
|
6597
|
+
fontSize: this.terminalFontSize,
|
|
6598
|
+
mobileHandler: null,
|
|
6599
|
+
writeChunks: [],
|
|
6600
|
+
writeRAF: null,
|
|
6601
|
+
flushRemaining: null,
|
|
6602
|
+
originalScrollback: null,
|
|
6551
6603
|
scrollbackRestoreTimer: null
|
|
6552
6604
|
});
|
|
6553
6605
|
|
|
@@ -7011,10 +7063,34 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7011
7063
|
const webglAddon = new window.WebglAddon();
|
|
7012
7064
|
webglAddon.onContextLoss(() => {
|
|
7013
7065
|
console.warn('[SSHIFT] WebGL context lost, disposing addon');
|
|
7014
|
-
|
|
7066
|
+
try {
|
|
7067
|
+
webglAddon.dispose();
|
|
7068
|
+
} catch (_) {}
|
|
7069
|
+
session.webglAddon = null;
|
|
7070
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
7015
7071
|
});
|
|
7016
7072
|
terminal.loadAddon(webglAddon);
|
|
7073
|
+
session.webglAddon = webglAddon;
|
|
7017
7074
|
console.log('[SSHIFT] WebglAddon loaded');
|
|
7075
|
+
|
|
7076
|
+
// Wait for the custom web font to finish loading before the first
|
|
7077
|
+
// data write reaches the terminal. The WebGL glyph texture atlas
|
|
7078
|
+
// is lazily populated on first render — if the font hasn't loaded
|
|
7079
|
+
// yet the browser substitutes a fallback, the atlas caches those
|
|
7080
|
+
// broken glyphs, and every cell painted from that atlas shows as a
|
|
7081
|
+
// blank/black box. Clearing the atlas *after* the font is ready
|
|
7082
|
+
// forces all glyphs to be re-rasterised with the correct face.
|
|
7083
|
+
document.fonts.ready.then(() => {
|
|
7084
|
+
if (session.webglAddon) {
|
|
7085
|
+
try {
|
|
7086
|
+
session.webglAddon.clearTextureAtlas();
|
|
7087
|
+
} catch (_) {}
|
|
7088
|
+
}
|
|
7089
|
+
if (session.terminal) {
|
|
7090
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
7091
|
+
}
|
|
7092
|
+
console.log('[SSHIFT] WebGL atlas cleared after fonts ready');
|
|
7093
|
+
});
|
|
7018
7094
|
} catch (e) {
|
|
7019
7095
|
console.warn('[SSHIFT] Failed to load WebglAddon, falling back to canvas renderer:', e.message);
|
|
7020
7096
|
}
|
|
@@ -7291,6 +7367,9 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7291
7367
|
this.showToast('Failed to copy', 'error');
|
|
7292
7368
|
}
|
|
7293
7369
|
});
|
|
7370
|
+
if (session.webglAddon) {
|
|
7371
|
+
terminal.refresh(0, terminal.rows - 1);
|
|
7372
|
+
}
|
|
7294
7373
|
return false; // Prevent default behavior
|
|
7295
7374
|
}
|
|
7296
7375
|
}
|
|
@@ -7325,6 +7404,9 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7325
7404
|
this.showToast('Failed to copy', 'error');
|
|
7326
7405
|
}
|
|
7327
7406
|
});
|
|
7407
|
+
if (session.webglAddon) {
|
|
7408
|
+
terminal.refresh(0, terminal.rows - 1);
|
|
7409
|
+
}
|
|
7328
7410
|
return false;
|
|
7329
7411
|
}
|
|
7330
7412
|
}
|
|
@@ -7383,6 +7465,17 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7383
7465
|
this.showTerminalContextMenu(sessionId, terminal, e);
|
|
7384
7466
|
});
|
|
7385
7467
|
|
|
7468
|
+
// When the selection is cleared (e.g. after copy / deselect) the
|
|
7469
|
+
// WebGL renderer can leave behind blank cells because the texture atlas
|
|
7470
|
+
// cached the "selected" version of the glyph and never re-rasterised
|
|
7471
|
+
// the deselected state. Force a full repaint on every selection change
|
|
7472
|
+
// so deselected cells are always redrawn with the correct glyph.
|
|
7473
|
+
terminal.onSelectionChange(() => {
|
|
7474
|
+
if (session.webglAddon) {
|
|
7475
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
7476
|
+
}
|
|
7477
|
+
});
|
|
7478
|
+
|
|
7386
7479
|
session.terminal = terminal;
|
|
7387
7480
|
session.fitAddon = fitAddon;
|
|
7388
7481
|
|
|
@@ -8461,7 +8554,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8461
8554
|
// Restore font size for this session
|
|
8462
8555
|
if (session.fontSize && session.terminal) {
|
|
8463
8556
|
session.terminal.options.fontSize = session.fontSize;
|
|
8464
|
-
|
|
8557
|
+
this._resetWebGLAtlas(session);
|
|
8465
8558
|
console.log('[SSHIFT] Restored font size', session.fontSize, 'for session', sessionId);
|
|
8466
8559
|
}
|
|
8467
8560
|
|
|
@@ -8494,7 +8587,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8494
8587
|
// For non-controllers, just focus the terminal and restore font size
|
|
8495
8588
|
if (session.fontSize) {
|
|
8496
8589
|
session.terminal.options.fontSize = session.fontSize;
|
|
8497
|
-
|
|
8590
|
+
this._resetWebGLAtlas(session);
|
|
8498
8591
|
}
|
|
8499
8592
|
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
8500
8593
|
session.mobileHandler._focusHiddenTextarea();
|
|
@@ -8506,10 +8599,9 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8506
8599
|
// Handle SFTP sessions
|
|
8507
8600
|
const sftpSession = this.sftpSessions.get(sessionId);
|
|
8508
8601
|
if (sftpSession && sftpSession.terminal) {
|
|
8509
|
-
// Restore font size for SFTP session
|
|
8510
8602
|
if (sftpSession.fontSize) {
|
|
8511
8603
|
sftpSession.terminal.options.fontSize = sftpSession.fontSize;
|
|
8512
|
-
|
|
8604
|
+
this._resetWebGLAtlas(sftpSession);
|
|
8513
8605
|
}
|
|
8514
8606
|
}
|
|
8515
8607
|
|