@lethevimlet/sshift 0.2.0 → 0.3.1
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/README.md +60 -1061
- package/example.config.json +1 -0
- package/package.json +2 -1
- package/src/server/index.js +185 -86
- package/src/server/utils/config.js +83 -17
- package/src/server/utils/env-loader.js +26 -5
- package/src/webapp/css/style.css +665 -42
- package/src/webapp/index.html +4 -1
- package/src/webapp/js/app.js +555 -78
- package/src/webapp/js/mobile-terminal.js +1370 -0
package/src/webapp/js/app.js
CHANGED
|
@@ -30,6 +30,7 @@ class SSHIFTClient {
|
|
|
30
30
|
this.isRestoring = false; // Flag to prevent saving during restoration
|
|
31
31
|
this.isSyncingTabs = false; // Flag to prevent saveTabs emission during tabs-sync
|
|
32
32
|
this.sftpClipboard = null; // For cut/copy/paste: { action: 'cut'|'copy', path: string, name: string, sessionId: string }
|
|
33
|
+
this.terminalClipboardContent = null; // Pre-read clipboard content for context menu paste
|
|
33
34
|
this.terminalColorOverride = true; // Default to true, will be loaded in initThemeAndAccent
|
|
34
35
|
this.terminalBgColor = '#0d1117';
|
|
35
36
|
this.terminalFgColor = '#e6edf3';
|
|
@@ -45,6 +46,7 @@ class SSHIFTClient {
|
|
|
45
46
|
this.mobileKeysBarEnabled = true; // Default to enabled
|
|
46
47
|
this.ctrlPressed = false; // Track Ctrl key state
|
|
47
48
|
this.altPressed = false; // Track Alt key state
|
|
49
|
+
this.currentKeyboardHeight = 0; // Track actual keyboard height for positioning
|
|
48
50
|
|
|
49
51
|
// Terminal font size (for pinch-to-zoom on mobile)
|
|
50
52
|
this.terminalFontSize = 14; // Default font size
|
|
@@ -469,13 +471,54 @@ class SSHIFTClient {
|
|
|
469
471
|
return text;
|
|
470
472
|
}
|
|
471
473
|
} catch (err) {
|
|
472
|
-
console.warn('[SSHIFT] Modern clipboard API failed
|
|
474
|
+
console.warn('[SSHIFT] Modern clipboard API failed:', err);
|
|
473
475
|
}
|
|
474
476
|
|
|
475
|
-
// Fallback:
|
|
477
|
+
// Fallback: return empty string - paste will be handled by browser's native paste event
|
|
478
|
+
// or the user can use Ctrl+Shift+V for force paste
|
|
479
|
+
return '';
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// Helper method to paste from clipboard using hidden textarea (more reliable for context menus)
|
|
483
|
+
async pasteFromClipboard() {
|
|
484
|
+
// Try modern clipboard API first
|
|
485
|
+
try {
|
|
486
|
+
if (navigator.clipboard && navigator.clipboard.readText) {
|
|
487
|
+
const text = await navigator.clipboard.readText();
|
|
488
|
+
if (text) {
|
|
489
|
+
return text;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
} catch (err) {
|
|
493
|
+
console.warn('[SSHIFT] Clipboard API failed, trying textarea fallback:', err);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Fallback: Create a hidden textarea and use execCommand
|
|
476
497
|
return new Promise((resolve) => {
|
|
477
|
-
const
|
|
478
|
-
|
|
498
|
+
const textarea = document.createElement('textarea');
|
|
499
|
+
textarea.style.position = 'fixed';
|
|
500
|
+
textarea.style.left = '-9999px';
|
|
501
|
+
textarea.style.top = '-9999px';
|
|
502
|
+
textarea.style.opacity = '0';
|
|
503
|
+
textarea.setAttribute('readonly', '');
|
|
504
|
+
document.body.appendChild(textarea);
|
|
505
|
+
|
|
506
|
+
textarea.focus();
|
|
507
|
+
textarea.select();
|
|
508
|
+
|
|
509
|
+
let pastedText = '';
|
|
510
|
+
try {
|
|
511
|
+
// Try to paste using execCommand
|
|
512
|
+
const successful = document.execCommand('paste');
|
|
513
|
+
if (successful) {
|
|
514
|
+
pastedText = textarea.value;
|
|
515
|
+
}
|
|
516
|
+
} catch (err) {
|
|
517
|
+
console.warn('[SSHIFT] execCommand paste failed:', err);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
document.body.removeChild(textarea);
|
|
521
|
+
resolve(pastedText);
|
|
479
522
|
});
|
|
480
523
|
}
|
|
481
524
|
|
|
@@ -552,6 +595,11 @@ class SSHIFTClient {
|
|
|
552
595
|
if (session.fitAddon && session.isController) {
|
|
553
596
|
session.fitAddon.fit();
|
|
554
597
|
}
|
|
598
|
+
|
|
599
|
+
// Refresh mobile selection overlay after font change
|
|
600
|
+
if (session.mobileHandler) {
|
|
601
|
+
session.mobileHandler.refreshSelection();
|
|
602
|
+
}
|
|
555
603
|
|
|
556
604
|
console.log('[SSHIFT] Font size set to', size, 'for session', sessionId);
|
|
557
605
|
}
|
|
@@ -577,6 +625,10 @@ class SSHIFTClient {
|
|
|
577
625
|
if (session.fitAddon && session.isController) {
|
|
578
626
|
session.fitAddon.fit();
|
|
579
627
|
}
|
|
628
|
+
// Refresh mobile selection overlay
|
|
629
|
+
if (session.mobileHandler) {
|
|
630
|
+
session.mobileHandler.refreshSelection();
|
|
631
|
+
}
|
|
580
632
|
}
|
|
581
633
|
});
|
|
582
634
|
|
|
@@ -2057,6 +2109,12 @@ class SSHIFTClient {
|
|
|
2057
2109
|
|
|
2058
2110
|
// Also set up on the main terminal element as fallback
|
|
2059
2111
|
setupTouchHandlers(terminalElement, 'terminal');
|
|
2112
|
+
|
|
2113
|
+
// Note: On mobile, we use xterm.js's native touch selection which provides
|
|
2114
|
+
// the native Android/iOS selection handles and copy/paste menu.
|
|
2115
|
+
// No custom long-press context menu is needed on mobile.
|
|
2116
|
+
console.log('[SSHIFT] Mobile touch selection enabled - using native selection UI');
|
|
2117
|
+
|
|
2060
2118
|
} else {
|
|
2061
2119
|
console.warn('[SSHIFT] Terminal element not found for touch handlers');
|
|
2062
2120
|
}
|
|
@@ -2120,11 +2178,10 @@ class SSHIFTClient {
|
|
|
2120
2178
|
// Hide/show header and tabs based on scroll direction
|
|
2121
2179
|
// When scrolling UP (into scrollback, scrollDiff > 0), show header/tabs for navigation
|
|
2122
2180
|
// When scrolling DOWN (towards bottom, scrollDiff < 0), hide header/tabs to maximize terminal space
|
|
2181
|
+
// But never hide when keyboard is open - they must stay fixed at top
|
|
2123
2182
|
if (scrollDiff > 2) {
|
|
2124
|
-
// Scrolling UP (into scrollback history) - show header and tabs
|
|
2125
2183
|
this.showHeaderAndTabs();
|
|
2126
|
-
} else if (scrollDiff < -2) {
|
|
2127
|
-
// Scrolling DOWN (towards bottom) - hide header and tabs
|
|
2184
|
+
} else if (scrollDiff < -2 && this.currentKeyboardHeight <= 50) {
|
|
2128
2185
|
this.hideHeaderAndTabs();
|
|
2129
2186
|
}
|
|
2130
2187
|
|
|
@@ -2135,6 +2192,8 @@ class SSHIFTClient {
|
|
|
2135
2192
|
hideHeaderAndTabs() {
|
|
2136
2193
|
if (this.headerHidden) return;
|
|
2137
2194
|
|
|
2195
|
+
console.log('[SSHIFT] Hiding header and tabs');
|
|
2196
|
+
|
|
2138
2197
|
const header = document.querySelector('.header');
|
|
2139
2198
|
const tabsContainer = document.querySelector('.tabs-container');
|
|
2140
2199
|
const appContainer = document.querySelector('.app-container');
|
|
@@ -2154,6 +2213,11 @@ class SSHIFTClient {
|
|
|
2154
2213
|
appContainer.classList.add('header-hidden', 'tabs-hidden');
|
|
2155
2214
|
}
|
|
2156
2215
|
|
|
2216
|
+
console.log('[SSHIFT] Header/tabs hidden - headerHidden:', this.headerHidden, 'tabsHidden:', this.tabsHidden);
|
|
2217
|
+
|
|
2218
|
+
// Update mobile keys bar position if keyboard is visible
|
|
2219
|
+
this.updateMobileKeysBarPosition();
|
|
2220
|
+
|
|
2157
2221
|
// Refit terminal to use the new space
|
|
2158
2222
|
this.refitActiveTerminal();
|
|
2159
2223
|
}
|
|
@@ -2161,6 +2225,8 @@ class SSHIFTClient {
|
|
|
2161
2225
|
showHeaderAndTabs() {
|
|
2162
2226
|
if (!this.headerHidden && !this.tabsHidden) return;
|
|
2163
2227
|
|
|
2228
|
+
console.log('[SSHIFT] Showing header and tabs');
|
|
2229
|
+
|
|
2164
2230
|
const header = document.querySelector('.header');
|
|
2165
2231
|
const tabsContainer = document.querySelector('.tabs-container');
|
|
2166
2232
|
const appContainer = document.querySelector('.app-container');
|
|
@@ -2180,6 +2246,11 @@ class SSHIFTClient {
|
|
|
2180
2246
|
appContainer.classList.remove('header-hidden', 'tabs-hidden');
|
|
2181
2247
|
}
|
|
2182
2248
|
|
|
2249
|
+
console.log('[SSHIFT] Header/tabs shown - headerHidden:', this.headerHidden, 'tabsHidden:', this.tabsHidden);
|
|
2250
|
+
|
|
2251
|
+
// Update mobile keys bar position if keyboard is visible
|
|
2252
|
+
this.updateMobileKeysBarPosition();
|
|
2253
|
+
|
|
2183
2254
|
// Refit terminal to use the new space
|
|
2184
2255
|
this.refitActiveTerminal();
|
|
2185
2256
|
}
|
|
@@ -2277,9 +2348,14 @@ class SSHIFTClient {
|
|
|
2277
2348
|
|
|
2278
2349
|
if (shouldShow) {
|
|
2279
2350
|
mobileKeysBar.classList.add('visible');
|
|
2351
|
+
// Set the mobile keys bar height CSS variable for layout calculations
|
|
2352
|
+
const heights = this.getFixedUIHeights();
|
|
2353
|
+
document.documentElement.style.setProperty('--mobile-keys-bar-height', `${heights.mobileKeysBar}px`);
|
|
2280
2354
|
console.log('[SSHIFT] Mobile keys bar shown');
|
|
2281
2355
|
} else {
|
|
2282
2356
|
mobileKeysBar.classList.remove('visible');
|
|
2357
|
+
// Remove the mobile keys bar height CSS variable when hidden
|
|
2358
|
+
document.documentElement.style.removeProperty('--mobile-keys-bar-height');
|
|
2283
2359
|
console.log('[SSHIFT] Mobile keys bar hidden');
|
|
2284
2360
|
}
|
|
2285
2361
|
}
|
|
@@ -2340,48 +2416,78 @@ class SSHIFTClient {
|
|
|
2340
2416
|
|
|
2341
2417
|
// Get heights dynamically
|
|
2342
2418
|
const heights = this.getFixedUIHeights();
|
|
2343
|
-
const bufferHeight = 5; // Add small bottom margin when keyboard is visible
|
|
2344
2419
|
|
|
2345
2420
|
if (keyboardHeight > 50) {
|
|
2346
|
-
|
|
2347
|
-
mobileKeysBar.style.bottom = `${keyboardHeight}px`;
|
|
2421
|
+
this.currentKeyboardHeight = keyboardHeight;
|
|
2348
2422
|
|
|
2349
|
-
|
|
2350
|
-
|
|
2423
|
+
if (this.headerHidden || this.tabsHidden) {
|
|
2424
|
+
this.showHeaderAndTabs();
|
|
2425
|
+
}
|
|
2351
2426
|
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
const xtermElement = activeWrapper.querySelector('.xterm');
|
|
2363
|
-
if (xtermElement) {
|
|
2364
|
-
xtermElement.style.paddingBottom = '0px';
|
|
2365
|
-
}
|
|
2366
|
-
}
|
|
2427
|
+
const header = document.querySelector('.header');
|
|
2428
|
+
const tabsContainer = document.querySelector('.tabs-container');
|
|
2429
|
+
const vvOffsetTop = window.visualViewport.offsetTop || 0;
|
|
2430
|
+
|
|
2431
|
+
if (header) {
|
|
2432
|
+
header.style.position = 'fixed';
|
|
2433
|
+
header.style.top = `${vvOffsetTop}px`;
|
|
2434
|
+
header.style.left = '0';
|
|
2435
|
+
header.style.right = '0';
|
|
2436
|
+
header.style.zIndex = '100';
|
|
2367
2437
|
}
|
|
2438
|
+
if (tabsContainer) {
|
|
2439
|
+
tabsContainer.style.position = 'fixed';
|
|
2440
|
+
tabsContainer.style.top = `${vvOffsetTop + heights.header}px`;
|
|
2441
|
+
tabsContainer.style.left = '0';
|
|
2442
|
+
tabsContainer.style.right = '0';
|
|
2443
|
+
tabsContainer.style.zIndex = '45';
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
let keysBarBottom = keyboardHeight;
|
|
2447
|
+
keysBarBottom += 3;
|
|
2448
|
+
keysBarBottom = Math.max(0, keysBarBottom);
|
|
2449
|
+
|
|
2450
|
+
console.log('[SSHIFT] Keyboard open - keyboardHeight:', keyboardHeight,
|
|
2451
|
+
'header hidden:', this.headerHidden, '(' + heights.header + 'px)',
|
|
2452
|
+
'tabs hidden:', this.tabsHidden, '(' + heights.tabs + 'px)',
|
|
2453
|
+
'keysBarBottom:', keysBarBottom);
|
|
2454
|
+
|
|
2455
|
+
mobileKeysBar.style.bottom = `${keysBarBottom}px`;
|
|
2456
|
+
|
|
2457
|
+
document.documentElement.style.setProperty('--keyboard-height', `${keyboardHeight}px`);
|
|
2458
|
+
document.documentElement.style.setProperty('--viewport-height', `${viewportHeight}px`);
|
|
2459
|
+
document.documentElement.style.setProperty('--mobile-keys-bar-height', `${heights.mobileKeysBar}px`);
|
|
2460
|
+
document.documentElement.style.setProperty('--vv-offset-top', `${vvOffsetTop}px`);
|
|
2461
|
+
|
|
2462
|
+
document.body.classList.add('keyboard-visible');
|
|
2368
2463
|
} else {
|
|
2369
|
-
// Keyboard is closed - reset position
|
|
2370
2464
|
mobileKeysBar.style.bottom = '0px';
|
|
2465
|
+
this.currentKeyboardHeight = 0;
|
|
2371
2466
|
|
|
2372
|
-
|
|
2373
|
-
const
|
|
2467
|
+
const header = document.querySelector('.header');
|
|
2468
|
+
const tabsContainer = document.querySelector('.tabs-container');
|
|
2374
2469
|
|
|
2375
|
-
if (
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2470
|
+
if (header) {
|
|
2471
|
+
header.style.top = '';
|
|
2472
|
+
header.style.left = '';
|
|
2473
|
+
header.style.right = '';
|
|
2474
|
+
}
|
|
2475
|
+
if (tabsContainer) {
|
|
2476
|
+
tabsContainer.style.top = '';
|
|
2477
|
+
tabsContainer.style.left = '';
|
|
2478
|
+
tabsContainer.style.right = '';
|
|
2384
2479
|
}
|
|
2480
|
+
|
|
2481
|
+
if (this.headerHidden || this.tabsHidden) {
|
|
2482
|
+
this.showHeaderAndTabs();
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
document.documentElement.style.removeProperty('--keyboard-height');
|
|
2486
|
+
document.documentElement.style.removeProperty('--viewport-height');
|
|
2487
|
+
document.documentElement.style.removeProperty('--mobile-keys-bar-height');
|
|
2488
|
+
document.documentElement.style.removeProperty('--vv-offset-top');
|
|
2489
|
+
|
|
2490
|
+
document.body.classList.remove('keyboard-visible');
|
|
2385
2491
|
}
|
|
2386
2492
|
|
|
2387
2493
|
// Refit the active terminal to use the new available space
|
|
@@ -2393,13 +2499,65 @@ class SSHIFTClient {
|
|
|
2393
2499
|
};
|
|
2394
2500
|
|
|
2395
2501
|
window.visualViewport.addEventListener('resize', updatePosition);
|
|
2396
|
-
|
|
2397
|
-
//
|
|
2502
|
+
|
|
2503
|
+
// Also listen for visual viewport scroll to keep header/tabs pinned
|
|
2504
|
+
// Android can scroll the visual viewport when keyboard is open
|
|
2505
|
+
const updateHeaderPosition = () => {
|
|
2506
|
+
if (this.currentKeyboardHeight > 50) {
|
|
2507
|
+
const header = document.querySelector('.header');
|
|
2508
|
+
const tabsContainer = document.querySelector('.tabs-container');
|
|
2509
|
+
const heights = this.getFixedUIHeights();
|
|
2510
|
+
const vvOffsetTop = window.visualViewport.offsetTop || 0;
|
|
2511
|
+
|
|
2512
|
+
if (header) {
|
|
2513
|
+
header.style.position = 'fixed';
|
|
2514
|
+
header.style.top = `${vvOffsetTop}px`;
|
|
2515
|
+
header.style.left = '0';
|
|
2516
|
+
header.style.right = '0';
|
|
2517
|
+
}
|
|
2518
|
+
if (tabsContainer) {
|
|
2519
|
+
tabsContainer.style.position = 'fixed';
|
|
2520
|
+
tabsContainer.style.top = `${vvOffsetTop + heights.header}px`;
|
|
2521
|
+
tabsContainer.style.left = '0';
|
|
2522
|
+
tabsContainer.style.right = '0';
|
|
2523
|
+
}
|
|
2524
|
+
document.documentElement.style.setProperty('--vv-offset-top', `${vvOffsetTop}px`);
|
|
2525
|
+
}
|
|
2526
|
+
};
|
|
2527
|
+
|
|
2528
|
+
window.visualViewport.addEventListener('scroll', updateHeaderPosition);
|
|
2398
2529
|
|
|
2399
2530
|
// Initial update
|
|
2400
2531
|
updatePosition();
|
|
2401
2532
|
}
|
|
2402
2533
|
}
|
|
2534
|
+
|
|
2535
|
+
// Update mobile keys bar position when header/tabs visibility changes
|
|
2536
|
+
updateMobileKeysBarPosition() {
|
|
2537
|
+
if (!this.isMobile) return;
|
|
2538
|
+
|
|
2539
|
+
const mobileKeysBar = document.querySelector('.mobile-keys-bar');
|
|
2540
|
+
if (!mobileKeysBar) return;
|
|
2541
|
+
|
|
2542
|
+
// Only update if keyboard is visible
|
|
2543
|
+
if (this.currentKeyboardHeight <= 50) return;
|
|
2544
|
+
|
|
2545
|
+
// Position the mobile keys bar just above the keyboard
|
|
2546
|
+
// The keyboard height is measured from the bottom of the window,
|
|
2547
|
+
// so we position the bar at that height plus a small buffer
|
|
2548
|
+
let keysBarBottom = this.currentKeyboardHeight;
|
|
2549
|
+
|
|
2550
|
+
// Add small buffer to prevent gap between bar and keyboard
|
|
2551
|
+
keysBarBottom += 3;
|
|
2552
|
+
|
|
2553
|
+
// Ensure we don't go below 0
|
|
2554
|
+
keysBarBottom = Math.max(0, keysBarBottom);
|
|
2555
|
+
|
|
2556
|
+
// Update the position
|
|
2557
|
+
mobileKeysBar.style.bottom = `${keysBarBottom}px`;
|
|
2558
|
+
|
|
2559
|
+
console.log('[SSHIFT] Updated mobile keys bar position:', keysBarBottom, 'px (keyboardHeight:', this.currentKeyboardHeight, 'header hidden:', this.headerHidden, 'tabs hidden:', this.tabsHidden, ')');
|
|
2560
|
+
}
|
|
2403
2561
|
|
|
2404
2562
|
initMobileKeysBar() {
|
|
2405
2563
|
if (!this.isMobile) return;
|
|
@@ -2459,8 +2617,13 @@ class SSHIFTClient {
|
|
|
2459
2617
|
// Focus the active terminal
|
|
2460
2618
|
if (this.activeSessionId) {
|
|
2461
2619
|
const session = this.sessions.get(this.activeSessionId);
|
|
2462
|
-
if (session
|
|
2463
|
-
|
|
2620
|
+
if (session) {
|
|
2621
|
+
// On mobile, use the mobile handler's hidden textarea
|
|
2622
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
2623
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
2624
|
+
} else if (session.terminal && session.terminal.textarea) {
|
|
2625
|
+
session.terminal.textarea.focus();
|
|
2626
|
+
}
|
|
2464
2627
|
}
|
|
2465
2628
|
}
|
|
2466
2629
|
}
|
|
@@ -2550,7 +2713,9 @@ class SSHIFTClient {
|
|
|
2550
2713
|
}
|
|
2551
2714
|
|
|
2552
2715
|
// Focus terminal after sending key
|
|
2553
|
-
if (
|
|
2716
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
2717
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
2718
|
+
} else if (terminal.textarea) {
|
|
2554
2719
|
terminal.textarea.focus();
|
|
2555
2720
|
}
|
|
2556
2721
|
}
|
|
@@ -2866,7 +3031,11 @@ class SSHIFTClient {
|
|
|
2866
3031
|
|
|
2867
3032
|
// Focus the terminal
|
|
2868
3033
|
if (session.terminal) {
|
|
2869
|
-
session.
|
|
3034
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
3035
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
3036
|
+
} else {
|
|
3037
|
+
session.terminal.focus();
|
|
3038
|
+
}
|
|
2870
3039
|
console.log('[SSHIFT] Terminal focused after joining session');
|
|
2871
3040
|
}
|
|
2872
3041
|
}
|
|
@@ -2936,7 +3105,11 @@ class SSHIFTClient {
|
|
|
2936
3105
|
}
|
|
2937
3106
|
|
|
2938
3107
|
// Focus the terminal
|
|
2939
|
-
session.
|
|
3108
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
3109
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
3110
|
+
} else {
|
|
3111
|
+
session.terminal.focus();
|
|
3112
|
+
}
|
|
2940
3113
|
});
|
|
2941
3114
|
}
|
|
2942
3115
|
});
|
|
@@ -4565,7 +4738,8 @@ class SSHIFTClient {
|
|
|
4565
4738
|
isAtBottom: true, // Auto-scroll by default when new data arrives
|
|
4566
4739
|
isController: false, // Default to observer - will be set to true for session creator or when taking control
|
|
4567
4740
|
syncing: false, // Flag to prevent data writes during screen sync
|
|
4568
|
-
fontSize: this.terminalFontSize // Initialize with default font size
|
|
4741
|
+
fontSize: this.terminalFontSize, // Initialize with default font size
|
|
4742
|
+
mobileHandler: null // Mobile terminal handler for touch interactions
|
|
4569
4743
|
});
|
|
4570
4744
|
|
|
4571
4745
|
// Switch to the new tab FIRST to make the container visible
|
|
@@ -5249,45 +5423,81 @@ class SSHIFTClient {
|
|
|
5249
5423
|
return true; // Allow default behavior for other keys
|
|
5250
5424
|
});
|
|
5251
5425
|
|
|
5252
|
-
// Handle right-click for context menu
|
|
5253
|
-
container.addEventListener('contextmenu', (e) => {
|
|
5426
|
+
// Handle right-click for context menu (desktop only)
|
|
5427
|
+
container.addEventListener('contextmenu', async (e) => {
|
|
5428
|
+
// On mobile, skip custom context menu - use native selection UI instead
|
|
5429
|
+
if (this.isMobile) {
|
|
5430
|
+
console.log('[SSHIFT] Mobile device - using native selection UI, skipping custom context menu');
|
|
5431
|
+
// Don't prevent default - let native selection work
|
|
5432
|
+
return;
|
|
5433
|
+
}
|
|
5434
|
+
|
|
5254
5435
|
console.log('[SSHIFT] Context menu triggered, hasSelection:', terminal.hasSelection());
|
|
5255
5436
|
e.preventDefault();
|
|
5256
5437
|
|
|
5257
|
-
//
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5438
|
+
// Pre-read clipboard content during user gesture (right-click)
|
|
5439
|
+
// This is needed because clipboard API requires user gesture
|
|
5440
|
+
this.terminalClipboardContent = null;
|
|
5441
|
+
|
|
5442
|
+
// Try modern Clipboard API first
|
|
5443
|
+
try {
|
|
5444
|
+
if (navigator.clipboard && navigator.clipboard.readText) {
|
|
5445
|
+
console.log('[SSHIFT] Attempting to read clipboard via Clipboard API...');
|
|
5446
|
+
const text = await navigator.clipboard.readText();
|
|
5447
|
+
this.terminalClipboardContent = text;
|
|
5448
|
+
console.log('[SSHIFT] Pre-read clipboard content successfully, length:', text?.length || 0);
|
|
5449
|
+
} else {
|
|
5450
|
+
console.warn('[SSHIFT] Clipboard API not available, will use fallback on paste');
|
|
5451
|
+
}
|
|
5452
|
+
} catch (err) {
|
|
5453
|
+
console.warn('[SSHIFT] Could not pre-read clipboard:', err.name, err.message);
|
|
5454
|
+
// Clipboard API failed, but we'll try fallback when user clicks paste
|
|
5455
|
+
}
|
|
5456
|
+
|
|
5457
|
+
// Show terminal context menu
|
|
5458
|
+
this.showTerminalContextMenu(sessionId, terminal, e);
|
|
5459
|
+
});
|
|
5460
|
+
|
|
5461
|
+
// Handle native paste event from browser
|
|
5462
|
+
container.addEventListener('paste', (e) => {
|
|
5463
|
+
console.log('[SSHIFT] Native paste event triggered');
|
|
5464
|
+
e.preventDefault();
|
|
5465
|
+
|
|
5466
|
+
// Get pasted data from clipboard
|
|
5467
|
+
let pastedText = '';
|
|
5468
|
+
if (e.clipboardData && e.clipboardData.getData) {
|
|
5469
|
+
pastedText = e.clipboardData.getData('text/plain');
|
|
5470
|
+
}
|
|
5471
|
+
|
|
5472
|
+
if (pastedText) {
|
|
5473
|
+
console.log('[SSHIFT] Pasted text length:', pastedText.length);
|
|
5474
|
+
const sess = this.sessions.get(sessionId);
|
|
5475
|
+
if (sess && sess.connected) {
|
|
5476
|
+
this.socket.emit('ssh-data', { sessionId, data: pastedText });
|
|
5477
|
+
this.showToast('Pasted from clipboard', 'success');
|
|
5269
5478
|
}
|
|
5270
5479
|
} else {
|
|
5271
|
-
|
|
5272
|
-
console.log('[SSHIFT] Attempting to paste from clipboard');
|
|
5273
|
-
this.readFromClipboard().then(text => {
|
|
5274
|
-
console.log('[SSHIFT] Clipboard content:', text ? 'found' : 'empty');
|
|
5275
|
-
if (text) {
|
|
5276
|
-
const sess = this.sessions.get(sessionId);
|
|
5277
|
-
if (sess && sess.connected) {
|
|
5278
|
-
this.socket.emit('ssh-data', { sessionId, data: text });
|
|
5279
|
-
this.showToast('Pasted from clipboard', 'success');
|
|
5280
|
-
}
|
|
5281
|
-
} else {
|
|
5282
|
-
this.showToast('Clipboard is empty', 'info');
|
|
5283
|
-
}
|
|
5284
|
-
});
|
|
5480
|
+
this.showToast('Clipboard is empty', 'info');
|
|
5285
5481
|
}
|
|
5286
5482
|
});
|
|
5287
5483
|
|
|
5288
5484
|
session.terminal = terminal;
|
|
5289
5485
|
session.fitAddon = fitAddon;
|
|
5290
5486
|
|
|
5487
|
+
// Initialize mobile terminal handler for touch interactions
|
|
5488
|
+
if (this.isMobile && typeof window.MobileTerminalHandler === 'function') {
|
|
5489
|
+
try {
|
|
5490
|
+
const terminalWrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
5491
|
+
if (terminalWrapper) {
|
|
5492
|
+
session.mobileHandler = new window.MobileTerminalHandler(terminal, session, this);
|
|
5493
|
+
session.mobileHandler.init(terminalWrapper);
|
|
5494
|
+
console.log('[SSHIFT] Mobile terminal handler initialized for session:', sessionId);
|
|
5495
|
+
}
|
|
5496
|
+
} catch (e) {
|
|
5497
|
+
console.warn('[SSHIFT] Failed to initialize mobile handler:', e);
|
|
5498
|
+
}
|
|
5499
|
+
}
|
|
5500
|
+
|
|
5291
5501
|
// Setup ResizeObserver to handle container size changes
|
|
5292
5502
|
// This ensures the terminal is refitted when the container is resized
|
|
5293
5503
|
// We observe the wrapper (parent) because it persists across layout changes
|
|
@@ -5384,7 +5594,11 @@ class SSHIFTClient {
|
|
|
5384
5594
|
}
|
|
5385
5595
|
|
|
5386
5596
|
// Focus the terminal so user can type immediately
|
|
5387
|
-
session.
|
|
5597
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
5598
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
5599
|
+
} else {
|
|
5600
|
+
session.terminal.focus();
|
|
5601
|
+
}
|
|
5388
5602
|
console.log('[SSHIFT] Terminal focused after connection');
|
|
5389
5603
|
} else {
|
|
5390
5604
|
console.error('[SSHIFT] No terminal in session!');
|
|
@@ -5857,7 +6071,11 @@ class SSHIFTClient {
|
|
|
5857
6071
|
|
|
5858
6072
|
// Focus the terminal so user can type
|
|
5859
6073
|
if (session.terminal) {
|
|
5860
|
-
session.
|
|
6074
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
6075
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
6076
|
+
} else {
|
|
6077
|
+
session.terminal.focus();
|
|
6078
|
+
}
|
|
5861
6079
|
console.log('[SSHIFT] Terminal focused for session:', sessionId);
|
|
5862
6080
|
}
|
|
5863
6081
|
|
|
@@ -5874,7 +6092,11 @@ class SSHIFTClient {
|
|
|
5874
6092
|
session.terminal.options.fontSize = session.fontSize;
|
|
5875
6093
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
5876
6094
|
}
|
|
5877
|
-
session.
|
|
6095
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
6096
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
6097
|
+
} else {
|
|
6098
|
+
session.terminal.focus();
|
|
6099
|
+
}
|
|
5878
6100
|
}
|
|
5879
6101
|
|
|
5880
6102
|
// Handle SFTP sessions
|
|
@@ -5917,6 +6139,11 @@ class SSHIFTClient {
|
|
|
5917
6139
|
clearTimeout(session.resizeTimeout);
|
|
5918
6140
|
session.resizeTimeout = null;
|
|
5919
6141
|
}
|
|
6142
|
+
// Clean up mobile handler
|
|
6143
|
+
if (session.mobileHandler) {
|
|
6144
|
+
session.mobileHandler.destroy();
|
|
6145
|
+
session.mobileHandler = null;
|
|
6146
|
+
}
|
|
5920
6147
|
if (session.terminal) {
|
|
5921
6148
|
session.terminal.dispose();
|
|
5922
6149
|
}
|
|
@@ -6999,6 +7226,256 @@ class SSHIFTClient {
|
|
|
6999
7226
|
});
|
|
7000
7227
|
}
|
|
7001
7228
|
|
|
7229
|
+
async showTerminalContextMenu(sessionId, terminal, event) {
|
|
7230
|
+
// Remove any existing context menu
|
|
7231
|
+
const existingMenu = document.querySelector('.terminal-context-menu');
|
|
7232
|
+
if (existingMenu) {
|
|
7233
|
+
existingMenu.remove();
|
|
7234
|
+
}
|
|
7235
|
+
|
|
7236
|
+
const menu = document.createElement('div');
|
|
7237
|
+
menu.className = 'terminal-context-menu active';
|
|
7238
|
+
|
|
7239
|
+
const hasSelection = terminal.hasSelection();
|
|
7240
|
+
const selection = hasSelection ? terminal.getSelection() : '';
|
|
7241
|
+
|
|
7242
|
+
menu.innerHTML = `
|
|
7243
|
+
<div class="terminal-context-menu-item ${hasSelection ? '' : 'disabled'}" data-action="copy">
|
|
7244
|
+
<i class="fas fa-copy"></i>
|
|
7245
|
+
<span>Copy</span>
|
|
7246
|
+
</div>
|
|
7247
|
+
<div class="terminal-context-menu-item" data-action="paste">
|
|
7248
|
+
<i class="fas fa-paste"></i>
|
|
7249
|
+
<span>Paste</span>
|
|
7250
|
+
</div>
|
|
7251
|
+
<div class="terminal-context-menu-divider"></div>
|
|
7252
|
+
<div class="terminal-context-menu-item" data-action="selectall">
|
|
7253
|
+
<i class="fas fa-object-group"></i>
|
|
7254
|
+
<span>Select All</span>
|
|
7255
|
+
</div>
|
|
7256
|
+
`;
|
|
7257
|
+
|
|
7258
|
+
// Position the menu at cursor
|
|
7259
|
+
menu.style.left = `${event.clientX}px`;
|
|
7260
|
+
menu.style.top = `${event.clientY}px`;
|
|
7261
|
+
|
|
7262
|
+
// Handle menu item clicks
|
|
7263
|
+
menu.querySelectorAll('.terminal-context-menu-item').forEach(item => {
|
|
7264
|
+
item.addEventListener('click', async (e) => {
|
|
7265
|
+
e.stopPropagation();
|
|
7266
|
+
const action = item.dataset.action;
|
|
7267
|
+
|
|
7268
|
+
// Don't do anything if item is disabled
|
|
7269
|
+
if (item.classList.contains('disabled')) {
|
|
7270
|
+
return;
|
|
7271
|
+
}
|
|
7272
|
+
|
|
7273
|
+
switch (action) {
|
|
7274
|
+
case 'copy':
|
|
7275
|
+
if (hasSelection && selection) {
|
|
7276
|
+
const success = await this.copyToClipboard(selection);
|
|
7277
|
+
if (success) {
|
|
7278
|
+
this.showToast('Copied to clipboard', 'success');
|
|
7279
|
+
terminal.clearSelection();
|
|
7280
|
+
// Focus terminal after copy
|
|
7281
|
+
const session = this.sessions.get(sessionId);
|
|
7282
|
+
if (this.isMobile && session && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
7283
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
7284
|
+
} else {
|
|
7285
|
+
terminal.focus();
|
|
7286
|
+
}
|
|
7287
|
+
} else {
|
|
7288
|
+
this.showToast('Failed to copy', 'error');
|
|
7289
|
+
}
|
|
7290
|
+
}
|
|
7291
|
+
break;
|
|
7292
|
+
case 'paste':
|
|
7293
|
+
console.log('[SSHIFT] Paste menu item clicked');
|
|
7294
|
+
// Try to paste - use pre-read content first, then try reading on click
|
|
7295
|
+
const doPaste = async () => {
|
|
7296
|
+
let clipboardContent = this.terminalClipboardContent;
|
|
7297
|
+
|
|
7298
|
+
// If no pre-read content, try to read now (click is also a user gesture)
|
|
7299
|
+
if (!clipboardContent) {
|
|
7300
|
+
console.log('[SSHIFT] No pre-read content, attempting to read clipboard on click...');
|
|
7301
|
+
try {
|
|
7302
|
+
if (navigator.clipboard && navigator.clipboard.readText) {
|
|
7303
|
+
clipboardContent = await navigator.clipboard.readText();
|
|
7304
|
+
console.log('[SSHIFT] Read clipboard on click, length:', clipboardContent?.length || 0);
|
|
7305
|
+
}
|
|
7306
|
+
} catch (err) {
|
|
7307
|
+
console.warn('[SSHIFT] Could not read clipboard on click:', err.name, err.message);
|
|
7308
|
+
}
|
|
7309
|
+
}
|
|
7310
|
+
|
|
7311
|
+
console.log('[SSHIFT] Final clipboard content:', clipboardContent?.length || 0);
|
|
7312
|
+
|
|
7313
|
+
if (clipboardContent) {
|
|
7314
|
+
// We have clipboard content, paste it
|
|
7315
|
+
const sess = this.sessions.get(sessionId);
|
|
7316
|
+
console.log('[SSHIFT] Session found:', !!sess, 'connected:', sess?.connected);
|
|
7317
|
+
if (sess && sess.connected) {
|
|
7318
|
+
this.socket.emit('ssh-data', { sessionId, data: clipboardContent });
|
|
7319
|
+
this.showToast('Pasted from clipboard', 'success');
|
|
7320
|
+
console.log('[SSHIFT] Paste successful');
|
|
7321
|
+
// Focus terminal after paste
|
|
7322
|
+
if (this.isMobile && sess.mobileHandler && sess.mobileHandler.hiddenTextarea) {
|
|
7323
|
+
sess.mobileHandler._focusHiddenTextarea();
|
|
7324
|
+
} else {
|
|
7325
|
+
terminal.focus();
|
|
7326
|
+
}
|
|
7327
|
+
} else {
|
|
7328
|
+
console.error('[SSHIFT] Session not connected');
|
|
7329
|
+
this.showToast('Session not connected', 'error');
|
|
7330
|
+
}
|
|
7331
|
+
} else {
|
|
7332
|
+
// Clipboard API not available (HTTP context), show paste modal
|
|
7333
|
+
console.log('[SSHIFT] Clipboard API not available, showing paste modal');
|
|
7334
|
+
this.showPasteModal(sessionId);
|
|
7335
|
+
}
|
|
7336
|
+
|
|
7337
|
+
// Clear the stored clipboard content
|
|
7338
|
+
this.terminalClipboardContent = null;
|
|
7339
|
+
};
|
|
7340
|
+
|
|
7341
|
+
doPaste();
|
|
7342
|
+
break;
|
|
7343
|
+
case 'selectall':
|
|
7344
|
+
terminal.selectAll();
|
|
7345
|
+
// Focus terminal after select all
|
|
7346
|
+
const session = this.sessions.get(sessionId);
|
|
7347
|
+
if (this.isMobile && session && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
7348
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
7349
|
+
} else {
|
|
7350
|
+
terminal.focus();
|
|
7351
|
+
}
|
|
7352
|
+
break;
|
|
7353
|
+
}
|
|
7354
|
+
|
|
7355
|
+
menu.remove();
|
|
7356
|
+
});
|
|
7357
|
+
});
|
|
7358
|
+
|
|
7359
|
+
document.body.appendChild(menu);
|
|
7360
|
+
|
|
7361
|
+
// Close menu when clicking outside
|
|
7362
|
+
const closeMenu = (e) => {
|
|
7363
|
+
if (!menu.contains(e.target)) {
|
|
7364
|
+
e.preventDefault();
|
|
7365
|
+
e.stopImmediatePropagation();
|
|
7366
|
+
menu.remove();
|
|
7367
|
+
document.removeEventListener('click', closeMenu, true);
|
|
7368
|
+
}
|
|
7369
|
+
};
|
|
7370
|
+
|
|
7371
|
+
// Delay adding the listener to prevent immediate close
|
|
7372
|
+
setTimeout(() => {
|
|
7373
|
+
document.addEventListener('click', closeMenu, true); // Use capture phase
|
|
7374
|
+
}, 100);
|
|
7375
|
+
}
|
|
7376
|
+
|
|
7377
|
+
showPasteModal(sessionId) {
|
|
7378
|
+
// Remove any existing paste modal
|
|
7379
|
+
const existingModal = document.querySelector('.paste-modal');
|
|
7380
|
+
if (existingModal) {
|
|
7381
|
+
existingModal.remove();
|
|
7382
|
+
}
|
|
7383
|
+
|
|
7384
|
+
// Create modal
|
|
7385
|
+
const modal = document.createElement('div');
|
|
7386
|
+
modal.className = 'paste-modal';
|
|
7387
|
+
modal.innerHTML = `
|
|
7388
|
+
<div class="paste-modal-content">
|
|
7389
|
+
<div class="paste-modal-header">
|
|
7390
|
+
<h3>Paste to Terminal</h3>
|
|
7391
|
+
<button class="paste-modal-close">×</button>
|
|
7392
|
+
</div>
|
|
7393
|
+
<div class="paste-modal-body">
|
|
7394
|
+
<p>Clipboard access requires HTTPS. Please paste your text below:</p>
|
|
7395
|
+
<textarea class="paste-textarea" placeholder="Paste your text here (Ctrl+V or right-click → Paste)..." rows="6"></textarea>
|
|
7396
|
+
</div>
|
|
7397
|
+
<div class="paste-modal-footer">
|
|
7398
|
+
<button class="paste-modal-btn paste-modal-cancel">Cancel</button>
|
|
7399
|
+
<button class="paste-modal-btn paste-modal-submit">Paste</button>
|
|
7400
|
+
</div>
|
|
7401
|
+
</div>
|
|
7402
|
+
`;
|
|
7403
|
+
|
|
7404
|
+
document.body.appendChild(modal);
|
|
7405
|
+
|
|
7406
|
+
// Get elements
|
|
7407
|
+
const textarea = modal.querySelector('.paste-textarea');
|
|
7408
|
+
const closeBtn = modal.querySelector('.paste-modal-close');
|
|
7409
|
+
const cancelBtn = modal.querySelector('.paste-modal-cancel');
|
|
7410
|
+
const submitBtn = modal.querySelector('.paste-modal-submit');
|
|
7411
|
+
|
|
7412
|
+
// Focus textarea
|
|
7413
|
+
setTimeout(() => textarea.focus(), 100);
|
|
7414
|
+
|
|
7415
|
+
// Handle paste in textarea
|
|
7416
|
+
textarea.addEventListener('paste', (e) => {
|
|
7417
|
+
// Let the paste happen naturally in the textarea
|
|
7418
|
+
// Then auto-submit after a short delay
|
|
7419
|
+
setTimeout(() => {
|
|
7420
|
+
if (textarea.value.trim()) {
|
|
7421
|
+
submitBtn.click();
|
|
7422
|
+
}
|
|
7423
|
+
}, 100);
|
|
7424
|
+
});
|
|
7425
|
+
|
|
7426
|
+
// Handle submit
|
|
7427
|
+
const handleSubmit = () => {
|
|
7428
|
+
const text = textarea.value;
|
|
7429
|
+
if (text) {
|
|
7430
|
+
const sess = this.sessions.get(sessionId);
|
|
7431
|
+
if (sess && sess.connected) {
|
|
7432
|
+
this.socket.emit('ssh-data', { sessionId, data: text });
|
|
7433
|
+
this.showToast('Pasted from clipboard', 'success');
|
|
7434
|
+
// Focus terminal after paste
|
|
7435
|
+
if (sess.terminal) {
|
|
7436
|
+
if (this.isMobile && sess.mobileHandler && sess.mobileHandler.hiddenTextarea) {
|
|
7437
|
+
sess.mobileHandler._focusHiddenTextarea();
|
|
7438
|
+
} else {
|
|
7439
|
+
sess.terminal.focus();
|
|
7440
|
+
}
|
|
7441
|
+
}
|
|
7442
|
+
} else {
|
|
7443
|
+
this.showToast('Session not connected', 'error');
|
|
7444
|
+
}
|
|
7445
|
+
}
|
|
7446
|
+
modal.remove();
|
|
7447
|
+
};
|
|
7448
|
+
|
|
7449
|
+
// Handle cancel
|
|
7450
|
+
const handleCancel = () => {
|
|
7451
|
+
modal.remove();
|
|
7452
|
+
};
|
|
7453
|
+
|
|
7454
|
+
// Event listeners
|
|
7455
|
+
submitBtn.addEventListener('click', handleSubmit);
|
|
7456
|
+
cancelBtn.addEventListener('click', handleCancel);
|
|
7457
|
+
closeBtn.addEventListener('click', handleCancel);
|
|
7458
|
+
|
|
7459
|
+
// Close on escape
|
|
7460
|
+
const handleKeydown = (e) => {
|
|
7461
|
+
if (e.key === 'Escape') {
|
|
7462
|
+
handleCancel();
|
|
7463
|
+
document.removeEventListener('keydown', handleKeydown);
|
|
7464
|
+
} else if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
|
7465
|
+
handleSubmit();
|
|
7466
|
+
document.removeEventListener('keydown', handleKeydown);
|
|
7467
|
+
}
|
|
7468
|
+
};
|
|
7469
|
+
document.addEventListener('keydown', handleKeydown);
|
|
7470
|
+
|
|
7471
|
+
// Close on outside click
|
|
7472
|
+
modal.addEventListener('click', (e) => {
|
|
7473
|
+
if (e.target === modal) {
|
|
7474
|
+
handleCancel();
|
|
7475
|
+
}
|
|
7476
|
+
});
|
|
7477
|
+
}
|
|
7478
|
+
|
|
7002
7479
|
showTabContextMenu(sessionId, event) {
|
|
7003
7480
|
// Remove any existing context menu
|
|
7004
7481
|
const existingMenu = document.querySelector('.tab-context-menu');
|