@lethevimlet/sshift 1.3.8 → 1.4.0
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
CHANGED
|
@@ -81,11 +81,60 @@ function registerSFTPHandlers(socket, io) {
|
|
|
81
81
|
console.log('[SFTP] Emitting sftp-list-result for sessionId:', data.sessionId, 'files:', files.length);
|
|
82
82
|
socket.emit('sftp-list-result', { path: data.path, files, sessionId: data.sessionId });
|
|
83
83
|
} catch (err) {
|
|
84
|
-
console.error('[SFTP] Error in sftp-list:', err.message);
|
|
85
|
-
|
|
84
|
+
console.error('[SFTP] Error in sftp-list:', err.message, 'code:', err.code);
|
|
85
|
+
|
|
86
|
+
const homeDir = sftpManager.home(data.sessionId);
|
|
87
|
+
const isPermissionDenied = err.code === 3
|
|
88
|
+
|| (err.message && (
|
|
89
|
+
err.message.includes('Permission denied')
|
|
90
|
+
|| err.message.includes('permission denied')
|
|
91
|
+
|| err.message.includes('EACCES')
|
|
92
|
+
));
|
|
93
|
+
|
|
94
|
+
// If listing "/" fails with permission denied and we know the home
|
|
95
|
+
// directory, try falling back to it automatically. This handles the
|
|
96
|
+
// common case of chrooted SFTP servers that restrict root access.
|
|
97
|
+
if (isPermissionDenied && homeDir && data.path === '/') {
|
|
98
|
+
console.log('[SFTP] Permission denied on /, falling back to home directory:', homeDir);
|
|
99
|
+
try {
|
|
100
|
+
const homeFiles = await sftpManager.list(data.sessionId, homeDir);
|
|
101
|
+
socket.emit('sftp-list-result', {
|
|
102
|
+
path: homeDir,
|
|
103
|
+
files: homeFiles,
|
|
104
|
+
sessionId: data.sessionId,
|
|
105
|
+
redirectedFrom: '/',
|
|
106
|
+
homeDir
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
} catch (homeErr) {
|
|
110
|
+
console.error('[SFTP] Home directory also failed:', homeErr.message);
|
|
111
|
+
socket.emit('sftp-error', {
|
|
112
|
+
message: homeErr.message,
|
|
113
|
+
sessionId: data.sessionId,
|
|
114
|
+
homeDir
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
socket.emit('sftp-error', {
|
|
121
|
+
message: err.message,
|
|
122
|
+
sessionId: data.sessionId,
|
|
123
|
+
homeDir,
|
|
124
|
+
isPermissionDenied
|
|
125
|
+
});
|
|
86
126
|
}
|
|
87
127
|
});
|
|
88
128
|
|
|
129
|
+
// SFTP get home directory
|
|
130
|
+
socket.on('sftp-home', (data) => {
|
|
131
|
+
const homeDir = sftpManager.home(data.sessionId);
|
|
132
|
+
socket.emit('sftp-home-result', {
|
|
133
|
+
sessionId: data.sessionId,
|
|
134
|
+
homeDir
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
89
138
|
// SFTP download (streamed)
|
|
90
139
|
socket.on('sftp-download', async (data) => {
|
|
91
140
|
try {
|
|
@@ -86,16 +86,30 @@ class SFTPManager {
|
|
|
86
86
|
conn: conn,
|
|
87
87
|
sftp: sftp,
|
|
88
88
|
socket: socket,
|
|
89
|
-
// Connection info for sessions API
|
|
90
89
|
host: options.host,
|
|
91
90
|
port: options.port || 22,
|
|
92
91
|
username: options.username,
|
|
93
|
-
connectedAt: Date.now()
|
|
92
|
+
connectedAt: Date.now(),
|
|
93
|
+
homeDir: null
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
// Resolve the user's home directory so we can fall back to it
|
|
97
|
+
// when listing "/" fails (e.g. chrooted SFTP or restricted
|
|
98
|
+
// server configs). realpath('.') returns the absolute path of
|
|
99
|
+
// the remote working directory, which defaults to the user's
|
|
100
|
+
// home on most SSH servers.
|
|
101
|
+
sftp.realpath('.', (realpathErr, resolvedPath) => {
|
|
102
|
+
if (!realpathErr && resolvedPath) {
|
|
103
|
+
session.homeDir = resolvedPath;
|
|
104
|
+
console.log(`[SFTP] Resolved home directory for ${options.username}: ${resolvedPath}`);
|
|
105
|
+
} else {
|
|
106
|
+
console.warn(`[SFTP] Could not resolve home directory: ${realpathErr?.message}`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.sessions.set(sessionId, session);
|
|
110
|
+
console.log(`[SFTP] SFTP session started: ${sessionId}`);
|
|
111
|
+
resolve(sessionId);
|
|
112
|
+
});
|
|
99
113
|
});
|
|
100
114
|
});
|
|
101
115
|
|
|
@@ -114,12 +128,36 @@ class SFTPManager {
|
|
|
114
128
|
removeTab(sessionId);
|
|
115
129
|
});
|
|
116
130
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
try {
|
|
132
|
+
conn.connect(config);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
console.error(`[SFTP] Connect exception: ${err.message}`);
|
|
135
|
+
reject(err);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
home(sessionId) {
|
|
141
|
+
const session = this.sessions.get(sessionId);
|
|
142
|
+
if (!session) return null;
|
|
143
|
+
return session.homeDir || null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
realpath(sessionId, path) {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
const session = this.sessions.get(sessionId);
|
|
149
|
+
if (!session) {
|
|
150
|
+
reject(new Error('Session not found'));
|
|
151
|
+
return;
|
|
122
152
|
}
|
|
153
|
+
|
|
154
|
+
session.sftp.realpath(path, (err, resolvedPath) => {
|
|
155
|
+
if (err) {
|
|
156
|
+
reject(err);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
resolve(resolvedPath);
|
|
160
|
+
});
|
|
123
161
|
});
|
|
124
162
|
}
|
|
125
163
|
|
package/src/webapp/css/style.css
CHANGED
|
@@ -3000,12 +3000,16 @@ body.dragging-tabs .tabs-container {
|
|
|
3000
3000
|
min-width: 200px;
|
|
3001
3001
|
}
|
|
3002
3002
|
|
|
3003
|
+
.sftp-home-btn {
|
|
3004
|
+
border-radius: var(--radius-md) 0 0 var(--radius-md);
|
|
3005
|
+
padding: 8px 10px;
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3003
3008
|
.sftp-path-input {
|
|
3004
3009
|
flex: 1;
|
|
3005
3010
|
padding: 8px 12px;
|
|
3006
3011
|
background: var(--bg-tertiary);
|
|
3007
3012
|
border: 1px solid var(--border-color);
|
|
3008
|
-
border-radius: var(--radius-md) 0 0 var(--radius-md);
|
|
3009
3013
|
color: var(--text-primary);
|
|
3010
3014
|
font-family: var(--font-mono);
|
|
3011
3015
|
font-size: 13px;
|
package/src/webapp/js/app.js
CHANGED
|
@@ -1009,7 +1009,20 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1009
1009
|
return false;
|
|
1010
1010
|
}
|
|
1011
1011
|
|
|
1012
|
-
|
|
1012
|
+
// Guard: don't initialise WebGL while the terminal is hidden (display:none).
|
|
1013
|
+
// A hidden canvas has zero dimensions, producing corrupt glyph caches (Bug 3).
|
|
1014
|
+
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
1015
|
+
if (wrapper && !wrapper.classList.contains('active')) {
|
|
1016
|
+
session._webglInitPending = true;
|
|
1017
|
+
console.log('[SSHIFT] Delaying WebGL init — wrapper is hidden');
|
|
1018
|
+
return false;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
if (session._webglInitPending && session.webglAddon) {
|
|
1022
|
+
// A previous call set the pending flag and we already have an addon;
|
|
1023
|
+
// don't double-initialise.
|
|
1024
|
+
return false;
|
|
1025
|
+
}
|
|
1013
1026
|
session._webglInitPending = true;
|
|
1014
1027
|
|
|
1015
1028
|
if (session.webglAddon) {
|
|
@@ -1162,6 +1175,19 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1162
1175
|
return false;
|
|
1163
1176
|
}
|
|
1164
1177
|
|
|
1178
|
+
// Guard: refuse to fit if the container has zero or near-zero dimensions.
|
|
1179
|
+
// A zero-size container produces bogus col/row counts that propagate to
|
|
1180
|
+
// the remote PTY and cause narrow-wrap / garbled output bugs.
|
|
1181
|
+
const rect = container.getBoundingClientRect();
|
|
1182
|
+
if (rect.width < 10 || rect.height < 10) {
|
|
1183
|
+
console.warn(`[SSHIFT] Container too small to fit (${rect.width.toFixed(1)}x${rect.height.toFixed(1)}px), deferring`);
|
|
1184
|
+
session.needsResize = true;
|
|
1185
|
+
if (retryCount < 3) {
|
|
1186
|
+
requestAnimationFrame(() => this._fitTerminal(session, retryCount + 1));
|
|
1187
|
+
}
|
|
1188
|
+
return false;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1165
1191
|
void container.offsetHeight;
|
|
1166
1192
|
void wrapper.offsetHeight;
|
|
1167
1193
|
|
|
@@ -1195,6 +1221,12 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
1195
1221
|
// re-rasterised at the new size rather than stretched from the old cache.
|
|
1196
1222
|
this._resetWebGLAtlas(session);
|
|
1197
1223
|
|
|
1224
|
+
// Force a full repaint to flush stale cells from the previous dimensions.
|
|
1225
|
+
// This prevents bottom-row garbage and garbled status lines after resize.
|
|
1226
|
+
try {
|
|
1227
|
+
terminal.refresh(0, terminal.rows - 1);
|
|
1228
|
+
} catch (_) {}
|
|
1229
|
+
|
|
1198
1230
|
return true;
|
|
1199
1231
|
}
|
|
1200
1232
|
|
|
@@ -2031,16 +2063,19 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2031
2063
|
this.distributeTabsToPanels(syncedTabs);
|
|
2032
2064
|
}
|
|
2033
2065
|
|
|
2034
|
-
// Resize terminals after restoration
|
|
2035
|
-
|
|
2066
|
+
// Resize terminals after restoration.
|
|
2067
|
+
// Use requestAnimationFrame so the browser has committed the new
|
|
2068
|
+
// flex/grid layout before we measure container widths (Bug 2 & 3).
|
|
2069
|
+
// Stagger a second pass for late fonts or animations.
|
|
2070
|
+
requestAnimationFrame(() => {
|
|
2071
|
+
this._refreshAllWebGLSessions();
|
|
2036
2072
|
this.handleResize();
|
|
2037
|
-
// Additional resize after animations complete
|
|
2038
2073
|
requestAnimationFrame(() => {
|
|
2039
2074
|
this.handleResize();
|
|
2040
2075
|
});
|
|
2041
|
-
}
|
|
2076
|
+
});
|
|
2042
2077
|
|
|
2043
|
-
// Final resize attempt for slow rendering
|
|
2078
|
+
// Final resize attempt for slow rendering / font swaps
|
|
2044
2079
|
setTimeout(() => this.handleResize(), 300);
|
|
2045
2080
|
return;
|
|
2046
2081
|
}
|
|
@@ -2089,16 +2124,18 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2089
2124
|
// Use syncedTabs if available (from another browser tab), otherwise distribute evenly
|
|
2090
2125
|
this.distributeTabsToPanels(syncedTabs);
|
|
2091
2126
|
|
|
2092
|
-
|
|
2093
|
-
|
|
2127
|
+
// Resize terminals after restoration.
|
|
2128
|
+
// Use requestAnimationFrame so the browser has committed the new
|
|
2129
|
+
// flex/grid layout before we measure container widths (Bug 2 & 3).
|
|
2130
|
+
requestAnimationFrame(() => {
|
|
2131
|
+
this._refreshAllWebGLSessions();
|
|
2094
2132
|
this.handleResize();
|
|
2095
|
-
// Additional resize after animations complete
|
|
2096
2133
|
requestAnimationFrame(() => {
|
|
2097
2134
|
this.handleResize();
|
|
2098
2135
|
});
|
|
2099
|
-
}
|
|
2136
|
+
});
|
|
2100
2137
|
|
|
2101
|
-
// Final resize attempt for slow rendering
|
|
2138
|
+
// Final resize attempt for slow rendering / font swaps
|
|
2102
2139
|
setTimeout(() => this.handleResize(), 300);
|
|
2103
2140
|
|
|
2104
2141
|
// Update scroll arrows for all panels
|
|
@@ -3678,6 +3715,9 @@ const wheelHandler = (e) => {
|
|
|
3678
3715
|
this.socket.connect();
|
|
3679
3716
|
}
|
|
3680
3717
|
this._refreshAllWebGLSessions();
|
|
3718
|
+
// Refit visible terminals after tab becomes visible — the container
|
|
3719
|
+
// may have had zero dimensions while hidden (Bugs 1 & 2).
|
|
3720
|
+
requestAnimationFrame(() => this.handleResize());
|
|
3681
3721
|
});
|
|
3682
3722
|
|
|
3683
3723
|
this.socket.on('connect_error', (error) => {
|
|
@@ -4392,11 +4432,47 @@ const wheelHandler = (e) => {
|
|
|
4392
4432
|
}
|
|
4393
4433
|
});
|
|
4394
4434
|
|
|
4435
|
+
this.socket.on('sftp-home-result', (data) => {
|
|
4436
|
+
console.log('[SSHIFT] sftp-home-result received:', data);
|
|
4437
|
+
const session = this.sftpSessions.get(data.sessionId);
|
|
4438
|
+
if (session && data.homeDir) {
|
|
4439
|
+
session.homeDir = data.homeDir;
|
|
4440
|
+
console.log('[SSHIFT] Stored home directory for session:', data.homeDir);
|
|
4441
|
+
|
|
4442
|
+
// If the session still shows "/" as current path (initial load),
|
|
4443
|
+
// and listing "/" hasn't succeeded yet, navigate to home instead.
|
|
4444
|
+
// This gives users with chrooted SFTP a working starting directory.
|
|
4445
|
+
if (session.currentPath === '/' && !session._rootListSucceeded) {
|
|
4446
|
+
console.log('[SSHIFT] Navigating to home directory:', data.homeDir);
|
|
4447
|
+
session.currentPath = data.homeDir;
|
|
4448
|
+
const pathInput = document.querySelector(`#sftp-${data.sessionId} .sftp-path-input`);
|
|
4449
|
+
if (pathInput) pathInput.value = data.homeDir;
|
|
4450
|
+
this.socket.emit('sftp-list', { sessionId: data.sessionId, path: data.homeDir });
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
});
|
|
4454
|
+
|
|
4395
4455
|
this.socket.on('sftp-list-result', (data) => {
|
|
4396
4456
|
console.log('[SSHIFT] sftp-list-result received:', data);
|
|
4397
4457
|
console.log('[SSHIFT] sessionId from server:', data.sessionId);
|
|
4398
4458
|
console.log('[SSHIFT] path:', data.path);
|
|
4399
4459
|
console.log('[SSHIFT] files count:', data.files?.length || 0);
|
|
4460
|
+
|
|
4461
|
+
// Track whether root listing has succeeded (used by sftp-home-result
|
|
4462
|
+
// to decide whether to redirect to home directory).
|
|
4463
|
+
const session = this.sftpSessions.get(data.sessionId);
|
|
4464
|
+
if (session) {
|
|
4465
|
+
if (data.path === '/' && !data.redirectedFrom) {
|
|
4466
|
+
session._rootListSucceeded = true;
|
|
4467
|
+
}
|
|
4468
|
+
session.currentPath = data.path;
|
|
4469
|
+
}
|
|
4470
|
+
|
|
4471
|
+
// If listing was auto-redirected from "/" to home, notify the user.
|
|
4472
|
+
if (data.redirectedFrom) {
|
|
4473
|
+
this.showToast(`Root directory (${data.redirectedFrom}) is not accessible. Showing home directory instead.`, 'info');
|
|
4474
|
+
}
|
|
4475
|
+
|
|
4400
4476
|
this.renderSFTPFileList(data.path, data.files, data.sessionId);
|
|
4401
4477
|
});
|
|
4402
4478
|
|
|
@@ -4436,6 +4512,22 @@ const wheelHandler = (e) => {
|
|
|
4436
4512
|
} else {
|
|
4437
4513
|
this.showToast(data.message, 'error');
|
|
4438
4514
|
}
|
|
4515
|
+
} else if (data.isPermissionDenied && data.homeDir) {
|
|
4516
|
+
// Permission denied with a known home directory — show a helpful
|
|
4517
|
+
// error with a "Go Home" action instead of a bare error toast.
|
|
4518
|
+
this.showToast(`Permission denied: ${data.message}. Try navigating to your home directory.`, 'error');
|
|
4519
|
+
// Auto-navigate to home directory if we're stuck at an inaccessible path
|
|
4520
|
+
const session = data?.sessionId ? this.sftpSessions.get(data.sessionId) : null;
|
|
4521
|
+
if (session) {
|
|
4522
|
+
session.homeDir = data.homeDir;
|
|
4523
|
+
const currentPath = session.currentPath || '/';
|
|
4524
|
+
// Only auto-redirect if we haven't already navigated away
|
|
4525
|
+
const pathInput = document.querySelector(`#sftp-${data.sessionId} .sftp-path-input`);
|
|
4526
|
+
if (pathInput && pathInput.value === currentPath) {
|
|
4527
|
+
console.log('[SSHIFT] Auto-navigating SFTP to home directory:', data.homeDir);
|
|
4528
|
+
this.navigateSFTPPath(data.homeDir, data.sessionId);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4439
4531
|
} else {
|
|
4440
4532
|
this.showToast(data.message, 'error');
|
|
4441
4533
|
}
|
|
@@ -7187,8 +7279,16 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7187
7279
|
|
|
7188
7280
|
terminal.open(container);
|
|
7189
7281
|
|
|
7190
|
-
//
|
|
7191
|
-
|
|
7282
|
+
// Initialise the WebGL renderer only if the wrapper is currently
|
|
7283
|
+
// visible. Loading WebGL on a hidden (display:none) terminal
|
|
7284
|
+
// produces a zero-size canvas, corrupting the glyph texture atlas
|
|
7285
|
+
// and causing dim/invisible text (Bug 3).
|
|
7286
|
+
if (wrapper.classList.contains('active')) {
|
|
7287
|
+
this._initWebGLAddon(session, true);
|
|
7288
|
+
} else {
|
|
7289
|
+
session._webglInitPending = true;
|
|
7290
|
+
console.log('[SSHIFT] Deferring WebGL init — terminal not yet visible');
|
|
7291
|
+
}
|
|
7192
7292
|
|
|
7193
7293
|
// Load image addon if enabled and available (Sixel/iTerm2/Kitty image protocols)
|
|
7194
7294
|
if (this.imageAddonEnabled && typeof window.ImageAddon === 'function') {
|
|
@@ -7273,44 +7373,44 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7273
7373
|
// repaint interference during initial render
|
|
7274
7374
|
terminal.options.cursorBlink = true;
|
|
7275
7375
|
|
|
7276
|
-
console.log('[SSHIFT] Terminal opened, fitting...');
|
|
7277
|
-
|
|
7278
|
-
//
|
|
7279
|
-
//
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
console.warn('[SSHIFT] Fit attempt ' + attempt + ' failed:', e.message);
|
|
7296
|
-
return false;
|
|
7376
|
+
console.log('[SSHIFT] Terminal opened, waiting for fonts before fitting...');
|
|
7377
|
+
|
|
7378
|
+
// CRITICAL: Wait for custom monospace fonts (JetBrains Mono etc.) to
|
|
7379
|
+
// finish loading before calling fitAddon.fit(). If we fit before the
|
|
7380
|
+
// web font swaps in, the browser measures the fallback font's glyph
|
|
7381
|
+
// width which is typically narrower, producing far fewer columns than
|
|
7382
|
+
// the container can actually hold. Those bogus dimensions are then
|
|
7383
|
+
// sent to the remote PTY, wrapping every ~10 characters (Bug 1).
|
|
7384
|
+
// After fonts are ready we delay by one animation frame so the
|
|
7385
|
+
// browser has repainted with the correct metrics.
|
|
7386
|
+
const fontReady = document.fonts
|
|
7387
|
+
? document.fonts.ready
|
|
7388
|
+
: Promise.resolve();
|
|
7389
|
+
|
|
7390
|
+
fontReady.then(() => {
|
|
7391
|
+
// Clear the WebGL texture atlas after the font swap — glyphs cached
|
|
7392
|
+
// before the swap were rasterised at the fallback font's metrics.
|
|
7393
|
+
if (session.webglAddon) {
|
|
7394
|
+
try { session.webglAddon.clearTextureAtlas(); } catch (_) {}
|
|
7297
7395
|
}
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
setTimeout(() => {
|
|
7305
|
-
if (!attemptFit(2)) {
|
|
7306
|
-
setTimeout(() => {
|
|
7307
|
-
if (!attemptFit(3)) {
|
|
7308
|
-
console.error('[SSHIFT] All fit attempts failed');
|
|
7309
|
-
}
|
|
7310
|
-
}, 200);
|
|
7311
|
-
}
|
|
7312
|
-
}, 100);
|
|
7396
|
+
|
|
7397
|
+
// Also check if WebGL init was deferred due to hidden wrapper
|
|
7398
|
+
// (Bug 3) — the terminal may now be visible.
|
|
7399
|
+
if (session._webglInitPending && wrapper.classList.contains('active')) {
|
|
7400
|
+
session._webglInitPending = false;
|
|
7401
|
+
this._initWebGLAddon(session, true);
|
|
7313
7402
|
}
|
|
7403
|
+
|
|
7404
|
+
requestAnimationFrame(() => {
|
|
7405
|
+
const fitted = this._fitTerminal(session);
|
|
7406
|
+
if (fitted) {
|
|
7407
|
+
console.log('[SSHIFT] Terminal fitted after fonts ready, cols:', terminal.cols, 'rows:', terminal.rows);
|
|
7408
|
+
} else {
|
|
7409
|
+
// If _fitTerminal couldn't fit (e.g. wrapper not visible yet),
|
|
7410
|
+
// it will have set needsResize = true so switchTab() picks it up.
|
|
7411
|
+
console.log('[SSHIFT] Could not fit after fonts ready — deferred to tab activation');
|
|
7412
|
+
}
|
|
7413
|
+
});
|
|
7314
7414
|
});
|
|
7315
7415
|
|
|
7316
7416
|
// Handle terminal input
|
|
@@ -7665,14 +7765,26 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7665
7765
|
// Clear the terminal to remove connecting messages
|
|
7666
7766
|
session.terminal.clear();
|
|
7667
7767
|
|
|
7668
|
-
// Send initial resize
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
|
|
7675
|
-
|
|
7768
|
+
// Send initial resize — but wait for fonts first so we send
|
|
7769
|
+
// the correct column/row count (Bug 1). If fonts haven't
|
|
7770
|
+
// loaded yet, the fallback font's narrower glyphs would make
|
|
7771
|
+
// fit() report far fewer cols than the container can actually
|
|
7772
|
+
// hold. The PTY on the server wraps at those bogus dimensions.
|
|
7773
|
+
const sendResize = () => {
|
|
7774
|
+
if (session.fitAddon) {
|
|
7775
|
+
this._fitTerminal(session);
|
|
7776
|
+
this.socket.emit('ssh-resize', {
|
|
7777
|
+
sessionId: data.sessionId,
|
|
7778
|
+
cols: session.terminal.cols,
|
|
7779
|
+
rows: session.terminal.rows
|
|
7780
|
+
});
|
|
7781
|
+
}
|
|
7782
|
+
};
|
|
7783
|
+
|
|
7784
|
+
if (document.fonts && document.fonts.status !== 'loaded') {
|
|
7785
|
+
document.fonts.ready.then(sendResize);
|
|
7786
|
+
} else {
|
|
7787
|
+
sendResize();
|
|
7676
7788
|
}
|
|
7677
7789
|
|
|
7678
7790
|
// Focus the terminal so user can type immediately
|
|
@@ -7975,6 +8087,8 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7975
8087
|
name,
|
|
7976
8088
|
type: 'sftp',
|
|
7977
8089
|
currentPath: '/',
|
|
8090
|
+
homeDir: null, // Resolved from server via sftp-home
|
|
8091
|
+
_rootListSucceeded: false, // Whether listing "/" worked (used for auto-redirect)
|
|
7978
8092
|
connectionData, // Store for sticky sessions
|
|
7979
8093
|
fontSize: this.terminalFontSize, // Initialize with default font size
|
|
7980
8094
|
isRestoring: !!restoreSessionId, // Flag to indicate if this is a restored session
|
|
@@ -8026,6 +8140,9 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8026
8140
|
container.innerHTML = `
|
|
8027
8141
|
<div class="sftp-toolbar">
|
|
8028
8142
|
<div class="sftp-path">
|
|
8143
|
+
<button class="btn btn-sm sftp-home-btn" title="Home directory">
|
|
8144
|
+
<i class="fas fa-home"></i>
|
|
8145
|
+
</button>
|
|
8029
8146
|
<input type="text" class="sftp-path-input" placeholder="/path/to/directory">
|
|
8030
8147
|
<button class="btn btn-sm sftp-go-btn">
|
|
8031
8148
|
<i class="fas fa-arrow-right"></i>
|
|
@@ -8048,11 +8165,18 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8048
8165
|
|
|
8049
8166
|
// Add event listeners
|
|
8050
8167
|
const pathInput = container.querySelector('.sftp-path-input');
|
|
8168
|
+
const homeBtn = container.querySelector('.sftp-home-btn');
|
|
8051
8169
|
const goBtn = container.querySelector('.sftp-go-btn');
|
|
8052
8170
|
const refreshBtn = container.querySelector('.sftp-refresh-btn');
|
|
8053
8171
|
const mkdirBtn = container.querySelector('.sftp-mkdir-btn');
|
|
8054
8172
|
const uploadBtn = container.querySelector('.sftp-upload-btn');
|
|
8055
8173
|
|
|
8174
|
+
homeBtn.addEventListener('click', () => {
|
|
8175
|
+
const session = this.sftpSessions.get(sessionId);
|
|
8176
|
+
const homePath = session?.homeDir || '~';
|
|
8177
|
+
this.navigateSFTPPath(homePath, sessionId);
|
|
8178
|
+
});
|
|
8179
|
+
|
|
8056
8180
|
goBtn.addEventListener('click', () => {
|
|
8057
8181
|
this.navigateSFTPPath(pathInput.value, sessionId);
|
|
8058
8182
|
});
|
|
@@ -8127,7 +8251,12 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8127
8251
|
console.log('[SSHIFT] SFTP container parent:', sftpContainer.parentElement?.id);
|
|
8128
8252
|
}
|
|
8129
8253
|
|
|
8130
|
-
//
|
|
8254
|
+
// Request the server's home directory for this session so we can
|
|
8255
|
+
// start there instead of "/" (which may be denied by chroot / perms)
|
|
8256
|
+
this.socket.emit('sftp-home', { sessionId: data.sessionId });
|
|
8257
|
+
|
|
8258
|
+
// Also start listing the current path (or "/") immediately; if the
|
|
8259
|
+
// home-directory response arrives first we'll navigate there instead.
|
|
8131
8260
|
const pathInput = document.querySelector(`#sftp-${data.sessionId} .sftp-path-input`);
|
|
8132
8261
|
console.log('[SSHIFT] Path input found:', !!pathInput);
|
|
8133
8262
|
|
|
@@ -8137,7 +8266,6 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8137
8266
|
console.error('[SSHIFT] Path input not found for session:', data.sessionId);
|
|
8138
8267
|
}
|
|
8139
8268
|
|
|
8140
|
-
// List files in the current directory
|
|
8141
8269
|
console.log('[SSHIFT] Emitting sftp-list for path:', session.currentPath || '/');
|
|
8142
8270
|
this.socket.emit('sftp-list', { sessionId: data.sessionId, path: session.currentPath || '/' });
|
|
8143
8271
|
} else {
|
|
@@ -8270,6 +8398,16 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8270
8398
|
navigateSFTPPath(path, sessionId) {
|
|
8271
8399
|
const session = this.sftpSessions.get(sessionId);
|
|
8272
8400
|
if (session) {
|
|
8401
|
+
// Resolve ~ to the user's home directory
|
|
8402
|
+
if (path === '~' || path.startsWith('~/')) {
|
|
8403
|
+
if (session.homeDir) {
|
|
8404
|
+
path = path === '~' ? session.homeDir : session.homeDir + path.slice(1);
|
|
8405
|
+
} else {
|
|
8406
|
+
// Ask the server to resolve ~ if we don't have the home dir yet
|
|
8407
|
+
this.socket.emit('sftp-home', { sessionId });
|
|
8408
|
+
}
|
|
8409
|
+
}
|
|
8410
|
+
|
|
8273
8411
|
session.currentPath = path;
|
|
8274
8412
|
|
|
8275
8413
|
const pathInput = document.querySelector(`#sftp-${sessionId} .sftp-path-input`);
|
|
@@ -8641,10 +8779,23 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8641
8779
|
// A second RAF ensures the paint is complete before we measure.
|
|
8642
8780
|
requestAnimationFrame(() => {
|
|
8643
8781
|
requestAnimationFrame(() => {
|
|
8782
|
+
// If WebGL init was deferred because this terminal was hidden
|
|
8783
|
+
// (Bug 3), initialise it now that the wrapper is visible.
|
|
8784
|
+
if (session._webglInitPending && this.webglRenderer && typeof window.WebglAddon === 'function') {
|
|
8785
|
+
session._webglInitPending = false;
|
|
8786
|
+
console.log('[SSHIFT] Initializing deferred WebGL for session:', sessionId);
|
|
8787
|
+
this._initWebGLAddon(session, true);
|
|
8788
|
+
}
|
|
8789
|
+
|
|
8790
|
+
// Always clear the WebGL texture atlas when a tab becomes visible.
|
|
8791
|
+
// While display:none, the terminal canvas has zero dimensions and
|
|
8792
|
+
// any cached glyphs are rendered at wrong colours/sizes (Bug 3).
|
|
8793
|
+
// Clearing + refreshing forces a clean redraw at the correct size.
|
|
8794
|
+
this._resetWebGLAtlas(session);
|
|
8795
|
+
|
|
8644
8796
|
// Restore font size for this session
|
|
8645
8797
|
if (session.fontSize && session.terminal) {
|
|
8646
8798
|
session.terminal.options.fontSize = session.fontSize;
|
|
8647
|
-
this._resetWebGLAtlas(session);
|
|
8648
8799
|
console.log('[SSHIFT] Restored font size', session.fontSize, 'for session', sessionId);
|
|
8649
8800
|
}
|
|
8650
8801
|
|
|
@@ -8674,10 +8825,11 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8674
8825
|
});
|
|
8675
8826
|
});
|
|
8676
8827
|
} else if (session && session.terminal) {
|
|
8677
|
-
// For non-controllers, just focus the terminal and restore font size
|
|
8828
|
+
// For non-controllers, just focus the terminal and restore font size.
|
|
8829
|
+
// Also clear the WebGL atlas since this tab was hidden.
|
|
8830
|
+
this._resetWebGLAtlas(session);
|
|
8678
8831
|
if (session.fontSize) {
|
|
8679
8832
|
session.terminal.options.fontSize = session.fontSize;
|
|
8680
|
-
this._resetWebGLAtlas(session);
|
|
8681
8833
|
}
|
|
8682
8834
|
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
8683
8835
|
session.mobileHandler._focusHiddenTextarea();
|