@lethevimlet/sshift 1.3.5 → 1.3.7
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/webapp/css/style.css +0 -4
- package/src/webapp/js/app.js +133 -43
package/package.json
CHANGED
package/src/webapp/css/style.css
CHANGED
|
@@ -1970,13 +1970,11 @@ body {
|
|
|
1970
1970
|
@keyframes tab-flash {
|
|
1971
1971
|
0%, 100% {
|
|
1972
1972
|
background: transparent;
|
|
1973
|
-
border-bottom-color: var(--accent-primary);
|
|
1974
1973
|
color: var(--accent-primary);
|
|
1975
1974
|
}
|
|
1976
1975
|
50% {
|
|
1977
1976
|
background: var(--accent-primary);
|
|
1978
1977
|
color: #fff;
|
|
1979
|
-
border-bottom-color: var(--accent-primary);
|
|
1980
1978
|
}
|
|
1981
1979
|
}
|
|
1982
1980
|
|
|
@@ -2040,13 +2038,11 @@ body {
|
|
|
2040
2038
|
@keyframes tab-flash-light {
|
|
2041
2039
|
0%, 100% {
|
|
2042
2040
|
background: transparent;
|
|
2043
|
-
border-bottom-color: var(--accent-primary);
|
|
2044
2041
|
color: var(--accent-primary);
|
|
2045
2042
|
}
|
|
2046
2043
|
50% {
|
|
2047
2044
|
background: var(--accent-primary);
|
|
2048
2045
|
color: #fff;
|
|
2049
|
-
border-bottom-color: var(--accent-primary);
|
|
2050
2046
|
}
|
|
2051
2047
|
}
|
|
2052
2048
|
|
package/src/webapp/js/app.js
CHANGED
|
@@ -995,6 +995,130 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
995
995
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
996
996
|
}
|
|
997
997
|
|
|
998
|
+
// Initialize (or re-initialize) the WebGL renderer addon for a session.
|
|
999
|
+
// Handles context-loss tracking with a retry cap: after 3 losses the session
|
|
1000
|
+
// permanently falls back to the canvas renderer so we don't loop endlessly.
|
|
1001
|
+
// The `initialLoad` flag controls whether we wait for web fonts before
|
|
1002
|
+
// clearing the atlas (only needed on first creation, not on recreation).
|
|
1003
|
+
_initWebGLAddon(session, initialLoad = false) {
|
|
1004
|
+
if (!session || !session.terminal) return false;
|
|
1005
|
+
if (!this.webglRenderer || typeof window.WebglAddon !== 'function') return false;
|
|
1006
|
+
|
|
1007
|
+
if ((session.webglContextLossCount || 0) >= 3) {
|
|
1008
|
+
console.warn('[SSHIFT] Too many WebGL context losses for session, staying on canvas renderer');
|
|
1009
|
+
return false;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
if (session._webglInitPending) return false;
|
|
1013
|
+
session._webglInitPending = true;
|
|
1014
|
+
|
|
1015
|
+
if (session.webglAddon) {
|
|
1016
|
+
try { session.webglAddon.dispose(); } catch (_) {}
|
|
1017
|
+
session.webglAddon = null;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
try {
|
|
1021
|
+
const webglAddon = new window.WebglAddon();
|
|
1022
|
+
|
|
1023
|
+
webglAddon.onContextLoss(() => {
|
|
1024
|
+
console.warn('[SSHIFT] WebGL context lost');
|
|
1025
|
+
try { webglAddon.dispose(); } catch (_) {}
|
|
1026
|
+
session.webglAddon = null;
|
|
1027
|
+
session.webglContextLossCount = (session.webglContextLossCount || 0) + 1;
|
|
1028
|
+
|
|
1029
|
+
if (session.webglContextLossCount < 3) {
|
|
1030
|
+
console.log('[SSHIFT] Scheduling WebGL addon recreation via requestAnimationFrame');
|
|
1031
|
+
requestAnimationFrame(() => {
|
|
1032
|
+
if (session.terminal && !session.webglAddon && (session.webglContextLossCount || 0) < 3) {
|
|
1033
|
+
console.log('[SSHIFT] Attempting WebGL addon recreation after context loss');
|
|
1034
|
+
this._initWebGLAddon(session, false);
|
|
1035
|
+
if (session.fitAddon && !document.hidden) {
|
|
1036
|
+
try { session.fitAddon.fit(); } catch (_) {}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
} else {
|
|
1041
|
+
console.warn('[SSHIFT] Repeated WebGL context loss, permanently falling back to canvas renderer');
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
session.terminal.loadAddon(webglAddon);
|
|
1048
|
+
session.webglAddon = webglAddon;
|
|
1049
|
+
|
|
1050
|
+
const canvas = session.terminal.element?.querySelector('canvas');
|
|
1051
|
+
if (canvas) {
|
|
1052
|
+
const onCanvasContextLoss = () => {
|
|
1053
|
+
if (session.webglAddon) {
|
|
1054
|
+
console.warn('[SSHIFT] Raw canvas webglcontextlost event caught');
|
|
1055
|
+
try { session.webglAddon.dispose(); } catch (_) {}
|
|
1056
|
+
session.webglAddon = null;
|
|
1057
|
+
session.webglContextLossCount = (session.webglContextLossCount || 0) + 1;
|
|
1058
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1059
|
+
}
|
|
1060
|
+
canvas.removeEventListener('webglcontextlost', onCanvasContextLoss);
|
|
1061
|
+
};
|
|
1062
|
+
canvas.addEventListener('webglcontextlost', onCanvasContextLoss);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
session._webglInitPending = false;
|
|
1066
|
+
console.log('[SSHIFT] WebglAddon loaded');
|
|
1067
|
+
|
|
1068
|
+
if (initialLoad) {
|
|
1069
|
+
document.fonts.ready.then(() => {
|
|
1070
|
+
if (session.webglAddon) {
|
|
1071
|
+
try { session.webglAddon.clearTextureAtlas(); } catch (_) {}
|
|
1072
|
+
}
|
|
1073
|
+
if (session.terminal) {
|
|
1074
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1075
|
+
}
|
|
1076
|
+
console.log('[SSHIFT] WebGL atlas cleared after fonts ready');
|
|
1077
|
+
});
|
|
1078
|
+
} else {
|
|
1079
|
+
try { webglAddon.clearTextureAtlas(); } catch (_) {}
|
|
1080
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1081
|
+
if (session.fitAddon) {
|
|
1082
|
+
try { session.fitAddon.fit(); } catch (_) {}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
return true;
|
|
1087
|
+
} catch (e) {
|
|
1088
|
+
session._webglInitPending = false;
|
|
1089
|
+
console.warn('[SSHIFT] Failed to load WebglAddon, falling back to canvas renderer:', e.message);
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// Called on visibilitychange (tab becomes visible). Browsers may reclaim
|
|
1095
|
+
// GPU memory from background tabs, which can invalidate the WebGL glyph
|
|
1096
|
+
// texture atlas or cause a full context loss. For sessions that still have
|
|
1097
|
+
// a WebGL addon we clear the stale atlas and force a repaint; for sessions
|
|
1098
|
+
// whose addon was lost while the tab was hidden we attempt to recreate it
|
|
1099
|
+
// (up to the 3-loss cap in _initWebGLAddon).
|
|
1100
|
+
// Wrapped in requestAnimationFrame to ensure layout is recalculated before
|
|
1101
|
+
// we touch the canvas — the container may have had zero dimensions while
|
|
1102
|
+
// the tab was hidden.
|
|
1103
|
+
_refreshAllWebGLSessions() {
|
|
1104
|
+
requestAnimationFrame(() => {
|
|
1105
|
+
const refresh = (session) => {
|
|
1106
|
+
if (!session || !session.terminal || !this.webglRenderer) return;
|
|
1107
|
+
if (session.webglAddon) {
|
|
1108
|
+
try { session.webglAddon.clearTextureAtlas(); } catch (_) {}
|
|
1109
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
1110
|
+
} else if ((session.webglContextLossCount || 0) < 3 && typeof window.WebglAddon === 'function') {
|
|
1111
|
+
this._initWebGLAddon(session, false);
|
|
1112
|
+
if (session.fitAddon) {
|
|
1113
|
+
try { session.fitAddon.fit(); } catch (_) {}
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
this.sessions.forEach(refresh);
|
|
1118
|
+
this.sftpSessions.forEach(refresh);
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
|
|
998
1122
|
// Watch for devicePixelRatio changes (zoom, monitor move, DPI switch).
|
|
999
1123
|
// When DPR changes the WebGL glyph atlas is built for the old pixel ratio
|
|
1000
1124
|
// and every glyph becomes mis-scaled; clearing the atlas forces a rebuild.
|
|
@@ -3544,12 +3668,16 @@ const wheelHandler = (e) => {
|
|
|
3544
3668
|
}
|
|
3545
3669
|
});
|
|
3546
3670
|
|
|
3547
|
-
// When the tab becomes visible again,
|
|
3671
|
+
// When the tab becomes visible again, reconnect the socket if needed
|
|
3672
|
+
// and refresh WebGL terminal renderers (the browser may reclaim GPU
|
|
3673
|
+
// memory from background tabs, invalidating the glyph texture atlas).
|
|
3548
3674
|
document.addEventListener('visibilitychange', () => {
|
|
3549
|
-
if (
|
|
3675
|
+
if (document.hidden) return;
|
|
3676
|
+
if (!this.socket.connected) {
|
|
3550
3677
|
console.log('[SSHIFT] Tab visible and socket disconnected, triggering reconnect');
|
|
3551
3678
|
this.socket.connect();
|
|
3552
3679
|
}
|
|
3680
|
+
this._refreshAllWebGLSessions();
|
|
3553
3681
|
});
|
|
3554
3682
|
|
|
3555
3683
|
this.socket.on('connect_error', (error) => {
|
|
@@ -6587,6 +6715,8 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
6587
6715
|
terminal: null,
|
|
6588
6716
|
fitAddon: null,
|
|
6589
6717
|
webglAddon: null,
|
|
6718
|
+
webglContextLossCount: 0,
|
|
6719
|
+
_webglInitPending: false,
|
|
6590
6720
|
connecting: true,
|
|
6591
6721
|
connected: false,
|
|
6592
6722
|
connectionData,
|
|
@@ -7058,47 +7188,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7058
7188
|
terminal.open(container);
|
|
7059
7189
|
|
|
7060
7190
|
// Load WebGL renderer addon if enabled and available
|
|
7061
|
-
|
|
7062
|
-
try {
|
|
7063
|
-
const webglAddon = new window.WebglAddon();
|
|
7064
|
-
webglAddon.onContextLoss(() => {
|
|
7065
|
-
console.warn('[SSHIFT] WebGL context lost, disposing addon');
|
|
7066
|
-
try {
|
|
7067
|
-
webglAddon.dispose();
|
|
7068
|
-
} catch (_) {}
|
|
7069
|
-
session.webglAddon = null;
|
|
7070
|
-
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
7071
|
-
});
|
|
7072
|
-
terminal.loadAddon(webglAddon);
|
|
7073
|
-
session.webglAddon = webglAddon;
|
|
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
|
-
});
|
|
7094
|
-
} catch (e) {
|
|
7095
|
-
console.warn('[SSHIFT] Failed to load WebglAddon, falling back to canvas renderer:', e.message);
|
|
7096
|
-
}
|
|
7097
|
-
} else if (this.webglRenderer) {
|
|
7098
|
-
console.warn('[SSHIFT] WebglAddon not available (window.WebglAddon type:', typeof window.WebglAddon, '), using canvas renderer');
|
|
7099
|
-
} else {
|
|
7100
|
-
console.log('[SSHIFT] WebGL renderer disabled in settings, using canvas renderer');
|
|
7101
|
-
}
|
|
7191
|
+
this._initWebGLAddon(session, true);
|
|
7102
7192
|
|
|
7103
7193
|
// Load image addon if enabled and available (Sixel/iTerm2/Kitty image protocols)
|
|
7104
7194
|
if (this.imageAddonEnabled && typeof window.ImageAddon === 'function') {
|