@lethevimlet/sshift 1.9.8 → 2.0.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/README.md +4 -2
- package/package.json +1 -1
- package/plugins/claude-attention/index.js +42 -1
- package/plugins/claude-attention/package.json +1 -1
- package/plugins/opencode-attention/index.js +42 -1
- package/plugins/opencode-attention/package.json +1 -1
- package/src/server/endpoints/rest/auth.js +45 -32
- package/src/server/endpoints/rest/bookmarks.js +5 -1
- package/src/server/endpoints/rest/config.js +19 -35
- package/src/server/endpoints/rest/folders.js +15 -3
- package/src/server/endpoints/rest/speech-ai.js +35 -9
- package/src/server/endpoints/rest/system.js +40 -4
- package/src/server/endpoints/ws/index.js +6 -0
- package/src/server/endpoints/ws/sftp.js +70 -10
- package/src/server/endpoints/ws/ssh.js +13 -5
- package/src/server/endpoints/ws/tabs.js +4 -4
- package/src/server/index.js +87 -3
- package/src/server/plugins/plugin-manager.js +14 -1
- package/src/server/services/bookmarks.js +1 -1
- package/src/server/services/sftp-manager.js +80 -7
- package/src/server/services/ssh-manager.js +44 -13
- package/src/server/utils/asset-version.js +26 -0
- package/src/server/utils/auth-tokens.js +254 -0
- package/src/server/utils/bookmark-encryption.js +5 -0
- package/src/server/utils/certs.js +3 -0
- package/src/server/utils/config.js +49 -6
- package/src/server/utils/key-converter.js +30 -5
- package/src/server/utils/safe-handlers.js +80 -0
- package/src/server/utils/tab-manager.js +41 -1
- package/src/webapp/index.html +28 -0
- package/src/webapp/js/app.js +356 -195
- package/src/webapp/js/mobile-terminal.js +436 -79
- package/sshift +23 -2
package/src/webapp/js/app.js
CHANGED
|
@@ -29,6 +29,9 @@ class SSHIFTClient {
|
|
|
29
29
|
this._disconnectToastTimer = null;
|
|
30
30
|
this._disconnectToastShown = false;
|
|
31
31
|
this.DISCONNECT_TOAST_GRACE_MS = 2500;
|
|
32
|
+
this.WAKE_GAP_MS = 15000; // timer gap that means the machine slept
|
|
33
|
+
this.PROBE_TIMEOUT_MS = 4000; // ack deadline for the liveness probe
|
|
34
|
+
this._authRejected = false;
|
|
32
35
|
this._staleReloadFor = null;
|
|
33
36
|
this._initReady = false; // Set true once init() completes
|
|
34
37
|
this._pendingOpenTabs = null; // Deferred open-tabs data
|
|
@@ -108,7 +111,9 @@ class SSHIFTClient {
|
|
|
108
111
|
|
|
109
112
|
console.log('[SSHIFT] Mobile detection - isMobile:', this.isMobile, 'window width:', window.innerWidth);
|
|
110
113
|
|
|
111
|
-
this.init()
|
|
114
|
+
Promise.resolve(this.init()).catch((err) => {
|
|
115
|
+
console.error('[SSHIFT] Initialization failed:', err);
|
|
116
|
+
});
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
async loadStickyConfig() {
|
|
@@ -124,13 +129,15 @@ class SSHIFTClient {
|
|
|
124
129
|
|
|
125
130
|
// If we have localStorage values, use them
|
|
126
131
|
if (localSticky !== null) {
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
// A corrupt stored value must not stop the app from starting.
|
|
133
|
+
const parse = (v, fallback) => { try { return v === null ? fallback : JSON.parse(v); } catch (_) { return fallback; } };
|
|
134
|
+
this.sticky = parse(localSticky, true);
|
|
135
|
+
this.takeControlDefault = parse(localTakeControl, true);
|
|
129
136
|
this.sshKeepaliveInterval = localKeepaliveInterval !== null ? parseInt(localKeepaliveInterval) : 10000;
|
|
130
137
|
this.sshKeepaliveCountMax = localKeepaliveCountMax !== null ? parseInt(localKeepaliveCountMax) : 1000;
|
|
131
|
-
this.mobileKeysBarEnabled =
|
|
132
|
-
this.webglRenderer =
|
|
133
|
-
this.imageAddonEnabled =
|
|
138
|
+
this.mobileKeysBarEnabled = parse(localMobileKeysBar, true);
|
|
139
|
+
this.webglRenderer = parse(localWebglRenderer, true);
|
|
140
|
+
this.imageAddonEnabled = parse(localImageAddonEnabled, true);
|
|
134
141
|
this.scrollback = localScrollback !== null ? parseInt(localScrollback) : 10000;
|
|
135
142
|
console.log('[SSHIFT] Loaded from localStorage - Sticky:', this.sticky ? 'enabled' : 'disabled',
|
|
136
143
|
'Take Control Default:', this.takeControlDefault ? 'enabled' : 'disabled',
|
|
@@ -205,13 +212,21 @@ class SSHIFTClient {
|
|
|
205
212
|
const verifyResp = await this._origFetch('/api/config', {
|
|
206
213
|
headers: { 'Authorization': `Bearer ${storedToken}` }
|
|
207
214
|
});
|
|
208
|
-
|
|
215
|
+
// Only a definite rejection forgets the remembered login. A
|
|
216
|
+
// server that is restarting, a proxy error or a network blip
|
|
217
|
+
// must not throw the user back to the password prompt.
|
|
218
|
+
if (verifyResp.status !== 401) {
|
|
209
219
|
this.authToken = storedToken;
|
|
210
220
|
this.updateSocketAuth();
|
|
211
221
|
if (lockScreen) lockScreen.style.display = 'none';
|
|
212
222
|
return;
|
|
213
223
|
}
|
|
214
|
-
} catch (e) {
|
|
224
|
+
} catch (e) {
|
|
225
|
+
this.authToken = storedToken;
|
|
226
|
+
this.updateSocketAuth();
|
|
227
|
+
if (lockScreen) lockScreen.style.display = 'none';
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
215
230
|
localStorage.removeItem('sshift_auth_token');
|
|
216
231
|
this.authToken = null;
|
|
217
232
|
}
|
|
@@ -224,7 +239,10 @@ class SSHIFTClient {
|
|
|
224
239
|
}
|
|
225
240
|
|
|
226
241
|
showLockScreen() {
|
|
227
|
-
|
|
242
|
+
// connect_error and checkAuthStatus can both ask for the lock screen;
|
|
243
|
+
// one prompt (and one submit handler) at a time.
|
|
244
|
+
if (this._lockScreenPromise) return this._lockScreenPromise;
|
|
245
|
+
this._lockScreenPromise = new Promise((resolve) => {
|
|
228
246
|
const lockScreen = document.getElementById('lockScreen');
|
|
229
247
|
const lockScreenForm = document.getElementById('lockScreenForm');
|
|
230
248
|
const lockScreenPassword = document.getElementById('lockScreenPassword');
|
|
@@ -264,6 +282,7 @@ class SSHIFTClient {
|
|
|
264
282
|
this.passwordEnabled = true;
|
|
265
283
|
if (this.bookmarkEncryptionEnabled) this.clearSensitiveTabStorage();
|
|
266
284
|
lockScreenForm.removeEventListener('submit', submitHandler);
|
|
285
|
+
this._lockScreenPromise = null;
|
|
267
286
|
resolve();
|
|
268
287
|
} else {
|
|
269
288
|
const data = await resp.json();
|
|
@@ -280,10 +299,14 @@ class SSHIFTClient {
|
|
|
280
299
|
|
|
281
300
|
lockScreenForm.addEventListener('submit', submitHandler);
|
|
282
301
|
});
|
|
302
|
+
return this._lockScreenPromise;
|
|
283
303
|
}
|
|
284
304
|
|
|
285
305
|
updateSocketAuth() {
|
|
286
306
|
if (this.socket && this.authToken) {
|
|
307
|
+
// Already connected with this token (the socket is created with the
|
|
308
|
+
// stored token): nothing to swap, don't drop the connection.
|
|
309
|
+
if (this.socket.connected && this.socket.auth && this.socket.auth.token === this.authToken) return;
|
|
287
310
|
this.socket.auth = { token: this.authToken };
|
|
288
311
|
// Deliberate reconnect: no Disconnected/Reconnected toasts for it.
|
|
289
312
|
this._silentReconnect = true;
|
|
@@ -550,6 +573,11 @@ class SSHIFTClient {
|
|
|
550
573
|
// fire saveTabs in tight succession with identical payloads; that
|
|
551
574
|
// amplified duplicates across clients and spammed the server.
|
|
552
575
|
const signature = JSON.stringify(tabsData);
|
|
576
|
+
// Decided now, not when the timer fires: by then the sync flags have
|
|
577
|
+
// long been reset.
|
|
578
|
+
if (!this.isSyncingTabs && !(this._tabSyncDepth > 0)) {
|
|
579
|
+
this._saveTabsLocalChange = true;
|
|
580
|
+
}
|
|
553
581
|
if (this._saveTabsTimer) clearTimeout(this._saveTabsTimer);
|
|
554
582
|
this._saveTabsTimer = setTimeout(() => {
|
|
555
583
|
this._saveTabsTimer = null;
|
|
@@ -563,7 +591,9 @@ class SSHIFTClient {
|
|
|
563
591
|
|
|
564
592
|
// Sync to server for cross-tab sync
|
|
565
593
|
// Don't emit if we're currently syncing from another client to prevent loops
|
|
566
|
-
|
|
594
|
+
const localChange = !!this._saveTabsLocalChange;
|
|
595
|
+
this._saveTabsLocalChange = false;
|
|
596
|
+
if (this.socket && this.socket.connected && localChange) {
|
|
567
597
|
this.socket.emit('tabs-save', tabsData);
|
|
568
598
|
}
|
|
569
599
|
}, 150);
|
|
@@ -919,8 +949,11 @@ class SSHIFTClient {
|
|
|
919
949
|
|
|
920
950
|
// Fallback to execCommand (also requires user gesture in modern browsers)
|
|
921
951
|
try {
|
|
952
|
+
const previousFocus = document.activeElement;
|
|
922
953
|
const textarea = document.createElement('textarea');
|
|
923
954
|
textarea.value = text;
|
|
955
|
+
// readonly: selecting it must not pop the phone keyboard
|
|
956
|
+
textarea.setAttribute('readonly', '');
|
|
924
957
|
textarea.style.position = 'fixed';
|
|
925
958
|
textarea.style.left = '-9999px';
|
|
926
959
|
textarea.style.top = '-9999px';
|
|
@@ -928,8 +961,12 @@ class SSHIFTClient {
|
|
|
928
961
|
document.body.appendChild(textarea);
|
|
929
962
|
textarea.focus();
|
|
930
963
|
textarea.select();
|
|
964
|
+
try { textarea.setSelectionRange(0, text.length); } catch (_) {} // iOS
|
|
931
965
|
const success = document.execCommand('copy');
|
|
932
966
|
document.body.removeChild(textarea);
|
|
967
|
+
if (previousFocus && previousFocus !== document.body && typeof previousFocus.focus === 'function') {
|
|
968
|
+
try { previousFocus.focus({ preventScroll: true }); } catch (_) {}
|
|
969
|
+
}
|
|
933
970
|
if (success) {
|
|
934
971
|
console.log('[SSHIFT] execCommand copy succeeded, length:', text.length);
|
|
935
972
|
} else {
|
|
@@ -3438,8 +3475,12 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
3438
3475
|
console.error('Failed to load bookmark order from server:', err);
|
|
3439
3476
|
}
|
|
3440
3477
|
// Fall back to localStorage
|
|
3441
|
-
|
|
3442
|
-
|
|
3478
|
+
try {
|
|
3479
|
+
const saved = localStorage.getItem('bookmarkOrder');
|
|
3480
|
+
return saved ? JSON.parse(saved) : null;
|
|
3481
|
+
} catch (_) {
|
|
3482
|
+
return null;
|
|
3483
|
+
}
|
|
3443
3484
|
}
|
|
3444
3485
|
|
|
3445
3486
|
async saveBookmarkOrder() {
|
|
@@ -4704,6 +4745,7 @@ const wheelHandler = (e) => {
|
|
|
4704
4745
|
const wasDisconnected = this._wasDisconnected;
|
|
4705
4746
|
this._wasDisconnected = false;
|
|
4706
4747
|
this._silentReconnect = false;
|
|
4748
|
+
this._authRejected = false;
|
|
4707
4749
|
this._cancelDisconnectToast();
|
|
4708
4750
|
if (wasDisconnected) {
|
|
4709
4751
|
// Only announce the recovery of an outage that was announced.
|
|
@@ -4723,13 +4765,18 @@ const wheelHandler = (e) => {
|
|
|
4723
4765
|
console.log('[SSHIFT] Disconnected from server:', reason);
|
|
4724
4766
|
this._wasDisconnected = true;
|
|
4725
4767
|
if (reason === 'io server disconnect') {
|
|
4726
|
-
//
|
|
4727
|
-
//
|
|
4768
|
+
// The server dropped us on purpose (credentials revoked). Socket.IO
|
|
4769
|
+
// never retries this by itself; try once more shortly so the page
|
|
4770
|
+
// either comes back or shows the lock screen instead of sitting
|
|
4771
|
+
// dead until F5.
|
|
4772
|
+
setTimeout(() => this._ensureConnection('server disconnect'), 1000);
|
|
4728
4773
|
} else if (!this.isUpdating && !this._silentReconnect) {
|
|
4729
4774
|
this._armDisconnectToast();
|
|
4730
4775
|
}
|
|
4731
4776
|
});
|
|
4732
4777
|
|
|
4778
|
+
this._installConnectionWatchdog();
|
|
4779
|
+
|
|
4733
4780
|
// When the tab becomes visible again, reconnect the socket if needed
|
|
4734
4781
|
// and refresh WebGL terminal renderers (the browser may reclaim GPU
|
|
4735
4782
|
// memory from background tabs, invalidating the glyph texture atlas).
|
|
@@ -4737,10 +4784,9 @@ const wheelHandler = (e) => {
|
|
|
4737
4784
|
if (document.hidden) return;
|
|
4738
4785
|
if (!this.socket.connected) {
|
|
4739
4786
|
console.log('[SSHIFT] Tab visible and socket disconnected, triggering reconnect');
|
|
4740
|
-
this.
|
|
4741
|
-
// Give the reconnect the same grace period before complaining.
|
|
4742
|
-
this._armDisconnectToast();
|
|
4787
|
+
this._ensureConnection('visible');
|
|
4743
4788
|
} else {
|
|
4789
|
+
this._ensureConnection('visible');
|
|
4744
4790
|
this._checkServerVersion();
|
|
4745
4791
|
}
|
|
4746
4792
|
this.clearFlashesForVisibleSessions();
|
|
@@ -4760,6 +4806,7 @@ const wheelHandler = (e) => {
|
|
|
4760
4806
|
this.socket.on('connect_error', (error) => {
|
|
4761
4807
|
console.error('[SSHIFT] Connection error:', error);
|
|
4762
4808
|
if (error.message === 'Authentication required') {
|
|
4809
|
+
this._authRejected = true;
|
|
4763
4810
|
this.authToken = null;
|
|
4764
4811
|
localStorage.removeItem('sshift_auth_token');
|
|
4765
4812
|
this.showLockScreen();
|
|
@@ -5460,6 +5507,14 @@ const wheelHandler = (e) => {
|
|
|
5460
5507
|
console.error('[SSHIFT] SSH Error:', data.message, 'sessionId:', data.sessionId);
|
|
5461
5508
|
this._dismissConnectingToasts();
|
|
5462
5509
|
|
|
5510
|
+
// The session ended on the server while this page was away (closed
|
|
5511
|
+
// on another device, remote exit): drop the tab instead of
|
|
5512
|
+
// recreating the connection from stored credentials.
|
|
5513
|
+
if (data.sessionId && data.message === 'Session not found' && data.closed) {
|
|
5514
|
+
console.log('[SSHIFT] Session was closed while disconnected, removing tab:', data.sessionId);
|
|
5515
|
+
this.handleTabClosed(data.sessionId);
|
|
5516
|
+
return;
|
|
5517
|
+
}
|
|
5463
5518
|
// If session not found and we're restoring, try to reconnect
|
|
5464
5519
|
if (data.sessionId && data.message === 'Session not found') {
|
|
5465
5520
|
const session = this.sessions.get(data.sessionId);
|
|
@@ -5616,6 +5671,11 @@ const wheelHandler = (e) => {
|
|
|
5616
5671
|
this._dismissConnectingToasts();
|
|
5617
5672
|
console.error('[SSHIFT] SFTP Error:', data.message, 'sessionId:', data?.sessionId);
|
|
5618
5673
|
|
|
5674
|
+
if (data?.sessionId && data.message === 'Session not found' && data.closed) {
|
|
5675
|
+
console.log('[SFTP] Session was closed while disconnected, removing tab:', data.sessionId);
|
|
5676
|
+
this.handleTabClosed(data.sessionId);
|
|
5677
|
+
return;
|
|
5678
|
+
}
|
|
5619
5679
|
// If session not found and we're restoring, try to reconnect
|
|
5620
5680
|
if (data?.sessionId && data.message === 'Session not found') {
|
|
5621
5681
|
const session = this.sftpSessions.get(data.sessionId);
|
|
@@ -5669,8 +5729,13 @@ const wheelHandler = (e) => {
|
|
|
5669
5729
|
this.showToast(data.message, 'error');
|
|
5670
5730
|
}
|
|
5671
5731
|
|
|
5672
|
-
|
|
5673
|
-
|
|
5732
|
+
// Only an error about the download itself aborts it (errors from
|
|
5733
|
+
// other SFTP tabs or a failed listing used to drop it silently while
|
|
5734
|
+
// the server kept streaming).
|
|
5735
|
+
const dl = this._activeDownload;
|
|
5736
|
+
if (dl && data && data.download && data.sessionId === dl.sessionId &&
|
|
5737
|
+
(!data.path || data.path === dl.path)) {
|
|
5738
|
+
this.hideTransferProgress(dl.sessionId);
|
|
5674
5739
|
this._activeDownload = null;
|
|
5675
5740
|
}
|
|
5676
5741
|
});
|
|
@@ -5689,7 +5754,7 @@ const wheelHandler = (e) => {
|
|
|
5689
5754
|
|
|
5690
5755
|
this.socket.on('sftp-download-chunk', (data) => {
|
|
5691
5756
|
const dl = this._activeDownload;
|
|
5692
|
-
if (dl && dl.path === data.path) {
|
|
5757
|
+
if (dl && dl.path === data.path && dl.sessionId === data.sessionId) {
|
|
5693
5758
|
const binaryStr = atob(data.data);
|
|
5694
5759
|
const bytes = new Uint8Array(binaryStr.length);
|
|
5695
5760
|
for (let i = 0; i < binaryStr.length; i++) {
|
|
@@ -5712,7 +5777,7 @@ const wheelHandler = (e) => {
|
|
|
5712
5777
|
|
|
5713
5778
|
this.socket.on('sftp-download-end', (data) => {
|
|
5714
5779
|
const dl = this._activeDownload;
|
|
5715
|
-
if (dl && dl.path === data.path) {
|
|
5780
|
+
if (dl && dl.path === data.path && dl.sessionId === data.sessionId) {
|
|
5716
5781
|
if (data.success) {
|
|
5717
5782
|
const blob = new Blob(dl.chunks, { type: 'application/octet-stream' });
|
|
5718
5783
|
const url = URL.createObjectURL(blob);
|
|
@@ -5720,7 +5785,8 @@ const wheelHandler = (e) => {
|
|
|
5720
5785
|
a.href = url;
|
|
5721
5786
|
a.download = dl.fileName;
|
|
5722
5787
|
a.click();
|
|
5723
|
-
|
|
5788
|
+
// Revoking synchronously can abort the save in some browsers.
|
|
5789
|
+
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
|
5724
5790
|
this.showToast(`Downloaded: ${dl.fileName}`, 'success');
|
|
5725
5791
|
}
|
|
5726
5792
|
this.hideTransferProgress(dl.sessionId);
|
|
@@ -7667,7 +7733,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7667
7733
|
}
|
|
7668
7734
|
option.innerHTML = `
|
|
7669
7735
|
<i class="fas ${icon} tab-icon ${iconClass}"></i>
|
|
7670
|
-
<span class="tab-name">${displayName}</span>
|
|
7736
|
+
<span class="tab-name">${this.escapeHtml(displayName)}</span>
|
|
7671
7737
|
<button class="tab-rename" data-session-id="${sessionId}" title="Rename">
|
|
7672
7738
|
<i class="fas fa-pen"></i>
|
|
7673
7739
|
</button>
|
|
@@ -7786,7 +7852,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7786
7852
|
: '';
|
|
7787
7853
|
option.innerHTML = `
|
|
7788
7854
|
<i class="fas ${icon} tab-icon ${iconClass}"></i>
|
|
7789
|
-
<span class="tab-name">${name}</span>
|
|
7855
|
+
<span class="tab-name">${this.escapeHtml(name)}</span>
|
|
7790
7856
|
${panelIndicator}
|
|
7791
7857
|
<button class="tab-rename" data-session-id="${sessionId}" title="Rename">
|
|
7792
7858
|
<i class="fas fa-pen"></i>
|
|
@@ -7982,12 +8048,40 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7982
8048
|
this.togglePlugin(pluginName, enabled, e.target);
|
|
7983
8049
|
});
|
|
7984
8050
|
});
|
|
8051
|
+
this._syncAttentionToggles(plugins);
|
|
7985
8052
|
} catch (err) {
|
|
7986
8053
|
console.error('[SSHIFT] Error loading plugins:', err);
|
|
7987
8054
|
pluginsList.innerHTML = '<div class="plugins-loading">Failed to load plugins</div>';
|
|
7988
8055
|
}
|
|
7989
8056
|
}
|
|
7990
8057
|
|
|
8058
|
+
// Settings → Sessions has its own switches for the two tab-flash plugins
|
|
8059
|
+
// (the same setting as their cards in Settings → Plugins). They reflect
|
|
8060
|
+
// the plugin list and stay hidden for a plugin the server doesn't have.
|
|
8061
|
+
_syncAttentionToggles(plugins) {
|
|
8062
|
+
document.querySelectorAll('.attention-plugin-toggle').forEach(toggle => {
|
|
8063
|
+
const plugin = Array.isArray(plugins)
|
|
8064
|
+
? plugins.find(p => p.name === toggle.dataset.plugin && !p.missing)
|
|
8065
|
+
: null;
|
|
8066
|
+
const item = toggle.closest('.setting-item');
|
|
8067
|
+
if (item) item.style.display = plugin ? '' : 'none';
|
|
8068
|
+
toggle.checked = !!(plugin && plugin.enabled);
|
|
8069
|
+
if (!toggle._attentionBound) {
|
|
8070
|
+
toggle._attentionBound = true;
|
|
8071
|
+
toggle.addEventListener('change', (e) => {
|
|
8072
|
+
this.togglePlugin(e.target.dataset.plugin, e.target.checked, e.target);
|
|
8073
|
+
});
|
|
8074
|
+
}
|
|
8075
|
+
});
|
|
8076
|
+
}
|
|
8077
|
+
|
|
8078
|
+
// Keep every switch for one plugin (Sessions + Plugins cards) in step.
|
|
8079
|
+
_setPluginToggleState(name, enabled) {
|
|
8080
|
+
document.querySelectorAll('.plugin-toggle, .attention-plugin-toggle').forEach(toggle => {
|
|
8081
|
+
if (toggle.dataset.plugin === name) toggle.checked = enabled;
|
|
8082
|
+
});
|
|
8083
|
+
}
|
|
8084
|
+
|
|
7991
8085
|
async togglePlugin(name, enabled, toggleEl) {
|
|
7992
8086
|
try {
|
|
7993
8087
|
const headers = { 'Content-Type': 'application/json' };
|
|
@@ -7999,15 +8093,16 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7999
8093
|
});
|
|
8000
8094
|
|
|
8001
8095
|
if (!response.ok) {
|
|
8002
|
-
|
|
8096
|
+
this._setPluginToggleState(name, !enabled);
|
|
8003
8097
|
this.showToast('Failed to update plugin', 'error');
|
|
8004
8098
|
return;
|
|
8005
8099
|
}
|
|
8006
8100
|
|
|
8101
|
+
this._setPluginToggleState(name, enabled);
|
|
8007
8102
|
this.showToast(`Plugin "${name}" ${enabled ? 'enabled' : 'disabled'}`, 'success');
|
|
8008
8103
|
} catch (err) {
|
|
8009
8104
|
console.error('[SSHIFT] Error toggling plugin:', err);
|
|
8010
|
-
|
|
8105
|
+
this._setPluginToggleState(name, !enabled);
|
|
8011
8106
|
this.showToast('Failed to update plugin', 'error');
|
|
8012
8107
|
}
|
|
8013
8108
|
}
|
|
@@ -10447,15 +10542,9 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
10447
10542
|
}
|
|
10448
10543
|
}
|
|
10449
10544
|
|
|
10450
|
-
//
|
|
10451
|
-
|
|
10452
|
-
|
|
10453
|
-
console.log('[SSHIFT] Active wrapper found:', !!activeWrapper);
|
|
10454
|
-
if (activeWrapper) {
|
|
10455
|
-
container = activeWrapper.querySelector('.sftp-file-list');
|
|
10456
|
-
console.log('[SSHIFT] Method 3 (via active wrapper):', !!container);
|
|
10457
|
-
}
|
|
10458
|
-
}
|
|
10545
|
+
// No "active wrapper" fallback: a late result for a closed or not yet
|
|
10546
|
+
// built tab used to render into whatever SFTP pane was active, where
|
|
10547
|
+
// every click then acted on the other session.
|
|
10459
10548
|
|
|
10460
10549
|
if (!container) {
|
|
10461
10550
|
console.error('[SSHIFT] SFTP file list container not found');
|
|
@@ -10775,6 +10864,8 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
10775
10864
|
const download = this._activeDownload;
|
|
10776
10865
|
if (download && download.sessionId === sessionId) {
|
|
10777
10866
|
this._activeDownload = null;
|
|
10867
|
+
// Stop the server reading the rest of the file.
|
|
10868
|
+
this.socket.emit('sftp-download-cancel', { sessionId, path: download.path });
|
|
10778
10869
|
}
|
|
10779
10870
|
|
|
10780
10871
|
this.hideTransferProgress(sessionId);
|
|
@@ -11097,6 +11188,54 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
11097
11188
|
this.saveTabs();
|
|
11098
11189
|
}
|
|
11099
11190
|
|
|
11191
|
+
/**
|
|
11192
|
+
* Release everything a terminal session holds in this page: observers,
|
|
11193
|
+
* timers, frame callbacks, the mobile touch/keyboard handler (window and
|
|
11194
|
+
* document listeners), wheel and OSC 52 listeners, and the xterm
|
|
11195
|
+
* instance. Shared by closeTab, removeTabLocally and handleTabClosed:
|
|
11196
|
+
* the last two used to skip most of it, so every tab closed from another
|
|
11197
|
+
* device left listeners and timers running against a disposed terminal.
|
|
11198
|
+
* Idempotent.
|
|
11199
|
+
*/
|
|
11200
|
+
_releaseSessionResources(session) {
|
|
11201
|
+
if (!session || session._released) return;
|
|
11202
|
+
session._released = true;
|
|
11203
|
+
if (session.type !== 'ssh') return;
|
|
11204
|
+
const clear = (key, fn) => {
|
|
11205
|
+
if (session[key]) {
|
|
11206
|
+
try { fn(session[key]); } catch (_) {}
|
|
11207
|
+
session[key] = null;
|
|
11208
|
+
}
|
|
11209
|
+
};
|
|
11210
|
+
clear('resizeObserver', (o) => o.disconnect());
|
|
11211
|
+
clear('_scrollbarObserver', (o) => o.disconnect());
|
|
11212
|
+
for (const key of ['resizeTimeout', 'roFitTimeout', 'scrollbackRestoreTimer', 'settleRefreshTimer', 'syncTimeout', 'overlayUpdateTimeout', 'scrollTimeout']) {
|
|
11213
|
+
clear(key, clearTimeout);
|
|
11214
|
+
}
|
|
11215
|
+
for (const key of ['writeRAF', 'scrollRAF', 'scrollApplyRAF', 'momentumRAF']) {
|
|
11216
|
+
clear(key, cancelAnimationFrame);
|
|
11217
|
+
}
|
|
11218
|
+
if (session.originalScrollback && session.terminal) {
|
|
11219
|
+
try { session.terminal.options.scrollback = session.originalScrollback; } catch (_) {}
|
|
11220
|
+
}
|
|
11221
|
+
clear('mobileHandler', (h) => h.destroy());
|
|
11222
|
+
if (session.wheelHandler && session.wheelElement) {
|
|
11223
|
+
session.wheelElement.removeEventListener('wheel', session.wheelHandler);
|
|
11224
|
+
}
|
|
11225
|
+
session.wheelHandler = null;
|
|
11226
|
+
session.wheelElement = null;
|
|
11227
|
+
if (session.osc52FlushListener) {
|
|
11228
|
+
document.removeEventListener('click', session.osc52FlushListener, true);
|
|
11229
|
+
document.removeEventListener('keydown', session.osc52FlushListener, true);
|
|
11230
|
+
document.removeEventListener('touchstart', session.osc52FlushListener, true);
|
|
11231
|
+
session.osc52FlushListener = null;
|
|
11232
|
+
}
|
|
11233
|
+
// Keep the (disposed) reference: late callbacks test session.terminal.
|
|
11234
|
+
if (session.terminal) {
|
|
11235
|
+
try { session.terminal.dispose(); } catch (_) {}
|
|
11236
|
+
}
|
|
11237
|
+
}
|
|
11238
|
+
|
|
11100
11239
|
closeTab(sessionId) {
|
|
11101
11240
|
const session = this.sessions.get(sessionId) || this.sftpSessions.get(sessionId);
|
|
11102
11241
|
if (!session) return;
|
|
@@ -11111,66 +11250,8 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
11111
11250
|
this.socket.emit('tab-close', { sessionId });
|
|
11112
11251
|
|
|
11113
11252
|
// Disconnect
|
|
11253
|
+
this._releaseSessionResources(session);
|
|
11114
11254
|
if (session.type === 'ssh') {
|
|
11115
|
-
// Clean up ResizeObserver
|
|
11116
|
-
if (session.resizeObserver) {
|
|
11117
|
-
session.resizeObserver.disconnect();
|
|
11118
|
-
session.resizeObserver = null;
|
|
11119
|
-
}
|
|
11120
|
-
// Clean up resize timeouts (emit debounce + ResizeObserver fit debounce)
|
|
11121
|
-
if (session.resizeTimeout) {
|
|
11122
|
-
clearTimeout(session.resizeTimeout);
|
|
11123
|
-
session.resizeTimeout = null;
|
|
11124
|
-
}
|
|
11125
|
-
if (session.roFitTimeout) {
|
|
11126
|
-
clearTimeout(session.roFitTimeout);
|
|
11127
|
-
session.roFitTimeout = null;
|
|
11128
|
-
}
|
|
11129
|
-
// Clean up scrollbar MutationObserver (mobile-only)
|
|
11130
|
-
if (session._scrollbarObserver) {
|
|
11131
|
-
session._scrollbarObserver.disconnect();
|
|
11132
|
-
session._scrollbarObserver = null;
|
|
11133
|
-
}
|
|
11134
|
-
// Clean up write buffer RAF
|
|
11135
|
-
if (session.writeRAF) {
|
|
11136
|
-
cancelAnimationFrame(session.writeRAF);
|
|
11137
|
-
session.writeRAF = null;
|
|
11138
|
-
}
|
|
11139
|
-
// Clean up scrollback restore timer
|
|
11140
|
-
if (session.scrollbackRestoreTimer) {
|
|
11141
|
-
clearTimeout(session.scrollbackRestoreTimer);
|
|
11142
|
-
session.scrollbackRestoreTimer = null;
|
|
11143
|
-
}
|
|
11144
|
-
// Clean up settle-refresh timer
|
|
11145
|
-
if (session.settleRefreshTimer) {
|
|
11146
|
-
clearTimeout(session.settleRefreshTimer);
|
|
11147
|
-
session.settleRefreshTimer = null;
|
|
11148
|
-
}
|
|
11149
|
-
// Restore scrollback if it was dynamically reduced
|
|
11150
|
-
if (session.originalScrollback && session.terminal) {
|
|
11151
|
-
session.terminal.options.scrollback = session.originalScrollback;
|
|
11152
|
-
}
|
|
11153
|
-
// Clean up mobile handler
|
|
11154
|
-
if (session.mobileHandler) {
|
|
11155
|
-
session.mobileHandler.destroy();
|
|
11156
|
-
session.mobileHandler = null;
|
|
11157
|
-
}
|
|
11158
|
-
// Clean up wheel handler
|
|
11159
|
-
if (session.wheelHandler && session.wheelElement) {
|
|
11160
|
-
session.wheelElement.removeEventListener('wheel', session.wheelHandler);
|
|
11161
|
-
session.wheelHandler = null;
|
|
11162
|
-
session.wheelElement = null;
|
|
11163
|
-
}
|
|
11164
|
-
// Clean up OSC 52 clipboard flush listeners
|
|
11165
|
-
if (session.osc52FlushListener) {
|
|
11166
|
-
document.removeEventListener('click', session.osc52FlushListener, true);
|
|
11167
|
-
document.removeEventListener('keydown', session.osc52FlushListener, true);
|
|
11168
|
-
document.removeEventListener('touchstart', session.osc52FlushListener, true);
|
|
11169
|
-
session.osc52FlushListener = null;
|
|
11170
|
-
}
|
|
11171
|
-
if (session.terminal) {
|
|
11172
|
-
session.terminal.dispose();
|
|
11173
|
-
}
|
|
11174
11255
|
this.sessions.delete(sessionId);
|
|
11175
11256
|
} else {
|
|
11176
11257
|
this.sftpSessions.delete(sessionId);
|
|
@@ -11242,37 +11323,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
11242
11323
|
// Disconnect from server session (without emitting tab-close)
|
|
11243
11324
|
if (session.type === 'ssh') {
|
|
11244
11325
|
this.socket.emit('ssh-disconnect', { sessionId });
|
|
11245
|
-
|
|
11246
|
-
if (session.scrollbackRestoreTimer) clearTimeout(session.scrollbackRestoreTimer);
|
|
11247
|
-
if (session.settleRefreshTimer) clearTimeout(session.settleRefreshTimer);
|
|
11248
|
-
if (session.originalScrollback && session.terminal) {
|
|
11249
|
-
session.terminal.options.scrollback = session.originalScrollback;
|
|
11250
|
-
}
|
|
11251
|
-
if (session.resizeObserver) {
|
|
11252
|
-
session.resizeObserver.disconnect();
|
|
11253
|
-
session.resizeObserver = null;
|
|
11254
|
-
}
|
|
11255
|
-
if (session.resizeTimeout) {
|
|
11256
|
-
clearTimeout(session.resizeTimeout);
|
|
11257
|
-
session.resizeTimeout = null;
|
|
11258
|
-
}
|
|
11259
|
-
if (session.roFitTimeout) {
|
|
11260
|
-
clearTimeout(session.roFitTimeout);
|
|
11261
|
-
session.roFitTimeout = null;
|
|
11262
|
-
}
|
|
11263
|
-
if (session.wheelHandler && session.wheelElement) {
|
|
11264
|
-
session.wheelElement.removeEventListener('wheel', session.wheelHandler);
|
|
11265
|
-
}
|
|
11266
|
-
if (session.osc52FlushListener) {
|
|
11267
|
-
document.removeEventListener('click', session.osc52FlushListener, true);
|
|
11268
|
-
document.removeEventListener('keydown', session.osc52FlushListener, true);
|
|
11269
|
-
document.removeEventListener('touchstart', session.osc52FlushListener, true);
|
|
11270
|
-
}
|
|
11271
|
-
if (session.terminal) session.terminal.dispose();
|
|
11272
|
-
if (session.mobileHandler) {
|
|
11273
|
-
session.mobileHandler.destroy();
|
|
11274
|
-
session.mobileHandler = null;
|
|
11275
|
-
}
|
|
11326
|
+
this._releaseSessionResources(session);
|
|
11276
11327
|
this.sessions.delete(sessionId);
|
|
11277
11328
|
} else {
|
|
11278
11329
|
this.socket.emit('sftp-disconnect', { sessionId });
|
|
@@ -11361,28 +11412,12 @@ handleTabOpened(data) {
|
|
|
11361
11412
|
const panelId = this.getPanelForSession(sessionId);
|
|
11362
11413
|
|
|
11363
11414
|
// Clean up the session locally (don't emit tab-close again)
|
|
11415
|
+
this._serverPanelMap.delete(sessionId);
|
|
11416
|
+
if (this.activeSessionsByPanel.get(panelId) === sessionId) {
|
|
11417
|
+
this.activeSessionsByPanel.delete(panelId);
|
|
11418
|
+
}
|
|
11419
|
+
this._releaseSessionResources(session);
|
|
11364
11420
|
if (session.type === 'ssh') {
|
|
11365
|
-
if (session.writeRAF) {
|
|
11366
|
-
cancelAnimationFrame(session.writeRAF);
|
|
11367
|
-
}
|
|
11368
|
-
if (session.scrollbackRestoreTimer) {
|
|
11369
|
-
clearTimeout(session.scrollbackRestoreTimer);
|
|
11370
|
-
}
|
|
11371
|
-
if (session.originalScrollback && session.terminal) {
|
|
11372
|
-
session.terminal.options.scrollback = session.originalScrollback;
|
|
11373
|
-
}
|
|
11374
|
-
if (session.wheelHandler && session.wheelElement) {
|
|
11375
|
-
session.wheelElement.removeEventListener('wheel', session.wheelHandler);
|
|
11376
|
-
}
|
|
11377
|
-
if (session.osc52FlushListener) {
|
|
11378
|
-
document.removeEventListener('click', session.osc52FlushListener, true);
|
|
11379
|
-
document.removeEventListener('keydown', session.osc52FlushListener, true);
|
|
11380
|
-
document.removeEventListener('touchstart', session.osc52FlushListener, true);
|
|
11381
|
-
session.osc52FlushListener = null;
|
|
11382
|
-
}
|
|
11383
|
-
if (session.terminal) {
|
|
11384
|
-
session.terminal.dispose();
|
|
11385
|
-
}
|
|
11386
11421
|
this.sessions.delete(sessionId);
|
|
11387
11422
|
} else {
|
|
11388
11423
|
this.sftpSessions.delete(sessionId);
|
|
@@ -11423,7 +11458,20 @@ handleTabOpened(data) {
|
|
|
11423
11458
|
}
|
|
11424
11459
|
|
|
11425
11460
|
// Sync tabs from server (called on connect when sticky is enabled)
|
|
11426
|
-
async syncTabsFromServer(
|
|
11461
|
+
async syncTabsFromServer(...args) {
|
|
11462
|
+
// Held across all awaits of the sync: saveTabs calls made while
|
|
11463
|
+
// applying server state must not be broadcast back (echo loops
|
|
11464
|
+
// between clients). The callers' isSyncingTabs flag is reset
|
|
11465
|
+
// synchronously, long before this async body finishes.
|
|
11466
|
+
this._tabSyncDepth = (this._tabSyncDepth || 0) + 1;
|
|
11467
|
+
try {
|
|
11468
|
+
return await this._syncTabsFromServerImpl(...args);
|
|
11469
|
+
} finally {
|
|
11470
|
+
this._tabSyncDepth--;
|
|
11471
|
+
}
|
|
11472
|
+
}
|
|
11473
|
+
|
|
11474
|
+
async _syncTabsFromServerImpl(tabs, isInitialSync = false, activeTabsByPanel = null, activeSessionId = null) {
|
|
11427
11475
|
// Wait for any in-progress restoration to complete before syncing
|
|
11428
11476
|
// This prevents the race condition where restoreTabs starts first,
|
|
11429
11477
|
// sets isRestoring=true, and then this function returns early, missing
|
|
@@ -11846,19 +11894,19 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
11846
11894
|
let iconClass, details;
|
|
11847
11895
|
if (bookmark.type === 'url') {
|
|
11848
11896
|
iconClass = 'fa-globe';
|
|
11849
|
-
details = bookmark.url || '';
|
|
11897
|
+
details = this.escapeHtml(bookmark.url || '');
|
|
11850
11898
|
} else if (bookmark.type === 'sftp') {
|
|
11851
11899
|
iconClass = 'fa-folder-open';
|
|
11852
|
-
details = `${this.escapeHtml(bookmark.username)}@${this.escapeHtml(bookmark.host)}:${bookmark.port}`;
|
|
11900
|
+
details = `${this.escapeHtml(bookmark.username)}@${this.escapeHtml(bookmark.host)}:${this.escapeHtml(bookmark.port)}`;
|
|
11853
11901
|
} else {
|
|
11854
11902
|
iconClass = 'fa-terminal';
|
|
11855
|
-
details = `${this.escapeHtml(bookmark.username)}@${this.escapeHtml(bookmark.host)}:${bookmark.port}`;
|
|
11903
|
+
details = `${this.escapeHtml(bookmark.username)}@${this.escapeHtml(bookmark.host)}:${this.escapeHtml(bookmark.port)}`;
|
|
11856
11904
|
}
|
|
11857
11905
|
|
|
11858
11906
|
item.innerHTML = `
|
|
11859
11907
|
<div class="bookmark-icon ${bookmark.type}">
|
|
11860
11908
|
<i class="fas ${iconClass}"></i>
|
|
11861
|
-
<span class="bookmark-letter">${firstLetter}</span>
|
|
11909
|
+
<span class="bookmark-letter">${this.escapeHtml(firstLetter)}</span>
|
|
11862
11910
|
</div>
|
|
11863
11911
|
<div class="bookmark-info">
|
|
11864
11912
|
<div class="bookmark-name">${this.escapeHtml(bookmark.name)}</div>
|
|
@@ -12460,26 +12508,30 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
12460
12508
|
pathParts.pop();
|
|
12461
12509
|
const newPath = pathParts.join('/') + '/' + newName;
|
|
12462
12510
|
|
|
12463
|
-
this.
|
|
12464
|
-
sessionId,
|
|
12465
|
-
oldPath: oldPath,
|
|
12466
|
-
newPath: newPath
|
|
12467
|
-
});
|
|
12468
|
-
|
|
12469
|
-
// Listen for result
|
|
12470
|
-
this.socket.once('sftp-rename-result', (data) => {
|
|
12511
|
+
this._sftpRequest('sftp-rename', { sessionId, oldPath, newPath }).then((data) => {
|
|
12471
12512
|
if (data.success) {
|
|
12472
|
-
// Get current path and refresh
|
|
12473
12513
|
const sftpSession = this.sftpSessions.get(sessionId);
|
|
12474
12514
|
if (sftpSession) {
|
|
12475
12515
|
this.navigateSFTPPath(sftpSession.currentPath, sessionId);
|
|
12476
12516
|
}
|
|
12517
|
+
} else {
|
|
12518
|
+
this.showToast('Error renaming: ' + data.error, 'error');
|
|
12477
12519
|
}
|
|
12478
12520
|
});
|
|
12521
|
+
}
|
|
12479
12522
|
|
|
12480
|
-
|
|
12481
|
-
|
|
12482
|
-
|
|
12523
|
+
/**
|
|
12524
|
+
* SFTP request answered through a Socket.IO ack, so the reply belongs to
|
|
12525
|
+
* this request only. (The previous once('sftp-error') listeners stayed
|
|
12526
|
+
* registered after a success and later fired for unrelated errors from
|
|
12527
|
+
* any SFTP tab.) Resolves to { success, error? }.
|
|
12528
|
+
*/
|
|
12529
|
+
_sftpRequest(event, payload, timeoutMs = 60000) {
|
|
12530
|
+
return new Promise((resolve) => {
|
|
12531
|
+
this.socket.timeout(timeoutMs).emit(event, payload, (err, data) => {
|
|
12532
|
+
if (err) return resolve({ success: false, error: 'No response from server' });
|
|
12533
|
+
resolve(data || { success: false, error: 'Empty response' });
|
|
12534
|
+
});
|
|
12483
12535
|
});
|
|
12484
12536
|
}
|
|
12485
12537
|
|
|
@@ -12921,26 +12973,16 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
12921
12973
|
|
|
12922
12974
|
if (!confirm(confirmMsg)) return;
|
|
12923
12975
|
|
|
12924
|
-
this.
|
|
12925
|
-
sessionId,
|
|
12926
|
-
path: filePath
|
|
12927
|
-
});
|
|
12928
|
-
|
|
12929
|
-
// Listen for result
|
|
12930
|
-
this.socket.once('sftp-delete-result', (data) => {
|
|
12976
|
+
this._sftpRequest('sftp-delete', { sessionId, path: filePath }).then((data) => {
|
|
12931
12977
|
if (data.success) {
|
|
12932
|
-
// Get current path and refresh
|
|
12933
12978
|
const sftpSession = this.sftpSessions.get(sessionId);
|
|
12934
12979
|
if (sftpSession) {
|
|
12935
12980
|
this.navigateSFTPPath(sftpSession.currentPath, sessionId);
|
|
12936
12981
|
}
|
|
12982
|
+
} else {
|
|
12983
|
+
this.showToast('Error deleting: ' + data.error, 'error');
|
|
12937
12984
|
}
|
|
12938
12985
|
});
|
|
12939
|
-
|
|
12940
|
-
// Listen for errors
|
|
12941
|
-
this.socket.once('sftp-error', (data) => {
|
|
12942
|
-
alert('Error deleting: ' + data.message);
|
|
12943
|
-
});
|
|
12944
12986
|
}
|
|
12945
12987
|
|
|
12946
12988
|
cutSFTPItem(fileName, filePath, sessionId) {
|
|
@@ -12996,24 +13038,16 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
12996
13038
|
|
|
12997
13039
|
if (this.sftpClipboard.action === 'cut') {
|
|
12998
13040
|
// Move (rename) the file
|
|
12999
|
-
this.
|
|
13000
|
-
sessionId,
|
|
13001
|
-
oldPath: sourcePath,
|
|
13002
|
-
newPath: destPath
|
|
13003
|
-
});
|
|
13004
|
-
|
|
13005
|
-
this.socket.once('sftp-rename-result', (data) => {
|
|
13041
|
+
this._sftpRequest('sftp-rename', { sessionId, oldPath: sourcePath, newPath: destPath }).then((data) => {
|
|
13006
13042
|
if (data.success) {
|
|
13007
13043
|
this.showToast(`Moved ${sourceName}`, 'success');
|
|
13008
13044
|
this.navigateSFTPPath(currentPath, sessionId);
|
|
13009
13045
|
// Clear clipboard after successful cut
|
|
13010
13046
|
this.sftpClipboard = null;
|
|
13047
|
+
} else {
|
|
13048
|
+
this.showToast('Error moving: ' + data.error, 'error');
|
|
13011
13049
|
}
|
|
13012
13050
|
});
|
|
13013
|
-
|
|
13014
|
-
this.socket.once('sftp-error', (data) => {
|
|
13015
|
-
this.showToast('Error moving: ' + data.message, 'error');
|
|
13016
|
-
});
|
|
13017
13051
|
} else {
|
|
13018
13052
|
// Copy operation - need to download and re-upload
|
|
13019
13053
|
this.showToast('Copy operation requires download/re-upload. Use download button instead.', 'info');
|
|
@@ -13272,7 +13306,15 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
13272
13306
|
// Handle URL type - open in new tab
|
|
13273
13307
|
if (bookmark.type === 'url') {
|
|
13274
13308
|
if (bookmark.url) {
|
|
13275
|
-
|
|
13309
|
+
// Only web links, and without handing the opened page a handle
|
|
13310
|
+
// on this window (window.opener).
|
|
13311
|
+
let parsed = null;
|
|
13312
|
+
try { parsed = new URL(bookmark.url, window.location.href); } catch (_) {}
|
|
13313
|
+
if (parsed && (parsed.protocol === 'http:' || parsed.protocol === 'https:')) {
|
|
13314
|
+
window.open(parsed.href, '_blank', 'noopener,noreferrer');
|
|
13315
|
+
} else {
|
|
13316
|
+
this.showToast('Only http(s) links can be opened', 'error');
|
|
13317
|
+
}
|
|
13276
13318
|
}
|
|
13277
13319
|
return;
|
|
13278
13320
|
}
|
|
@@ -13405,8 +13447,12 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
13405
13447
|
console.error('Failed to load folder order from server:', err);
|
|
13406
13448
|
}
|
|
13407
13449
|
// Fall back to localStorage
|
|
13408
|
-
|
|
13409
|
-
|
|
13450
|
+
try {
|
|
13451
|
+
const saved = localStorage.getItem('folderOrder');
|
|
13452
|
+
return saved ? JSON.parse(saved) : null;
|
|
13453
|
+
} catch (_) {
|
|
13454
|
+
return null;
|
|
13455
|
+
}
|
|
13410
13456
|
}
|
|
13411
13457
|
|
|
13412
13458
|
async saveFolderOrder() {
|
|
@@ -13438,8 +13484,12 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
13438
13484
|
console.error('Failed to load folder expanded states from server:', err);
|
|
13439
13485
|
}
|
|
13440
13486
|
// Fall back to localStorage
|
|
13441
|
-
|
|
13442
|
-
|
|
13487
|
+
try {
|
|
13488
|
+
const saved = localStorage.getItem('folderExpandedStates');
|
|
13489
|
+
return saved ? JSON.parse(saved) : {};
|
|
13490
|
+
} catch (_) {
|
|
13491
|
+
return {};
|
|
13492
|
+
}
|
|
13443
13493
|
}
|
|
13444
13494
|
|
|
13445
13495
|
async saveFolderExpandedStates() {
|
|
@@ -13706,6 +13756,113 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
13706
13756
|
}, this.DISCONNECT_TOAST_GRACE_MS);
|
|
13707
13757
|
}
|
|
13708
13758
|
|
|
13759
|
+
/**
|
|
13760
|
+
* Keep the socket alive across laptop sleep, network changes and
|
|
13761
|
+
* background freezes (v1.9.9). Socket.IO alone recovers too slowly:
|
|
13762
|
+
* - a socket that died while the machine slept still reports
|
|
13763
|
+
* "connected" until its 85 s heartbeat timer fires, and timers do
|
|
13764
|
+
* not advance during suspend, so that can be well over a minute
|
|
13765
|
+
* after the lid opens (or minutes when the network changed and no
|
|
13766
|
+
* TCP reset ever arrives);
|
|
13767
|
+
* - while disconnected, socket.connect() does not cut short a pending
|
|
13768
|
+
* reconnect backoff (up to 30 s), so the old visibilitychange kick
|
|
13769
|
+
* did nothing.
|
|
13770
|
+
* Wake-ups are detected by a timer gap, `online`, `pageshow`, focus and
|
|
13771
|
+
* visibility; each one probes a connected socket with an acked ping and
|
|
13772
|
+
* forces a fresh connection when the probe fails, and makes a
|
|
13773
|
+
* disconnected socket retry immediately.
|
|
13774
|
+
*/
|
|
13775
|
+
_installConnectionWatchdog() {
|
|
13776
|
+
if (this._connectionWatchdogInstalled) return;
|
|
13777
|
+
this._connectionWatchdogInstalled = true;
|
|
13778
|
+
this._lastWatchdogTick = Date.now();
|
|
13779
|
+
const timer = setInterval(() => {
|
|
13780
|
+
const now = Date.now();
|
|
13781
|
+
const gap = now - this._lastWatchdogTick;
|
|
13782
|
+
this._lastWatchdogTick = now;
|
|
13783
|
+
if (gap > this.WAKE_GAP_MS) {
|
|
13784
|
+
console.log('[SSHIFT] Resumed after', Math.round(gap / 1000), 's pause, checking connection');
|
|
13785
|
+
this._ensureConnection('wake', { force: true });
|
|
13786
|
+
} else if (!this.socket.connected && !this.socket.active && !this._authRejected) {
|
|
13787
|
+
// Nothing is retrying (server-side disconnect, manual close):
|
|
13788
|
+
// keep trying in the background.
|
|
13789
|
+
this._ensureConnection('idle');
|
|
13790
|
+
}
|
|
13791
|
+
}, 5000);
|
|
13792
|
+
// Node (unit tests) only: don't keep the process alive.
|
|
13793
|
+
if (timer && typeof timer.unref === 'function') timer.unref();
|
|
13794
|
+
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return;
|
|
13795
|
+
window.addEventListener('online', () => this._ensureConnection('online', { force: true }));
|
|
13796
|
+
window.addEventListener('pageshow', (e) => {
|
|
13797
|
+
if (e.persisted) this._ensureConnection('pageshow', { force: true });
|
|
13798
|
+
});
|
|
13799
|
+
window.addEventListener('focus', () => this._ensureConnection('focus'));
|
|
13800
|
+
}
|
|
13801
|
+
|
|
13802
|
+
_ensureConnection(reason, opts) {
|
|
13803
|
+
const socket = this.socket;
|
|
13804
|
+
if (!socket || this.isUpdating || this._authRejected || this._lockScreenPromise) return;
|
|
13805
|
+
const force = !!(opts && opts.force);
|
|
13806
|
+
if (!socket.connected) {
|
|
13807
|
+
// Skip a pending backoff and dial now. disconnect() resets the
|
|
13808
|
+
// manager (and its backoff); connect() opens a new transport, and
|
|
13809
|
+
// a failure there resumes the normal automatic retries.
|
|
13810
|
+
const now = Date.now();
|
|
13811
|
+
if (!force && this._lastKickAt && now - this._lastKickAt < 3000) return;
|
|
13812
|
+
this._lastKickAt = now;
|
|
13813
|
+
console.log('[SSHIFT] Reconnecting now (' + reason + ')');
|
|
13814
|
+
socket.disconnect();
|
|
13815
|
+
socket.connect();
|
|
13816
|
+
this._armDisconnectToast();
|
|
13817
|
+
return;
|
|
13818
|
+
}
|
|
13819
|
+
const engine = socket.io && socket.io.engine;
|
|
13820
|
+
// "Connected" on top of a transport that is already closing or closed
|
|
13821
|
+
// is dead: nothing will ever arrive on it.
|
|
13822
|
+
if (engine && engine.readyState !== 'open') {
|
|
13823
|
+
this._forceReconnect(reason + ', transport ' + engine.readyState);
|
|
13824
|
+
return;
|
|
13825
|
+
}
|
|
13826
|
+
// Connected on paper: prove it. Throttled unless this is a real wake.
|
|
13827
|
+
const now = Date.now();
|
|
13828
|
+
if (this._probeInFlight) return;
|
|
13829
|
+
if (!force && this._lastProbeAt && now - this._lastProbeAt < 15000) return;
|
|
13830
|
+
this._lastProbeAt = now;
|
|
13831
|
+
this._probeInFlight = true;
|
|
13832
|
+
socket.timeout(this.PROBE_TIMEOUT_MS).emit('sshift-ping', (err) => {
|
|
13833
|
+
this._probeInFlight = false;
|
|
13834
|
+
if (!err) return;
|
|
13835
|
+
// Only tear down the transport the probe was sent on.
|
|
13836
|
+
if (socket.connected && socket.io && socket.io.engine === engine) {
|
|
13837
|
+
this._forceReconnect('probe timed out, ' + reason);
|
|
13838
|
+
}
|
|
13839
|
+
});
|
|
13840
|
+
}
|
|
13841
|
+
|
|
13842
|
+
/**
|
|
13843
|
+
* Drop the current connection and dial a new one, without relying on the
|
|
13844
|
+
* dead transport to cooperate. engine.close() alone is NOT enough: with
|
|
13845
|
+
* packets queued (the probe itself, keystrokes typed after waking) it
|
|
13846
|
+
* waits for a "drain" that a dead socket never emits, leaving the engine
|
|
13847
|
+
* stuck in "closing" — the socket then claims to be connected forever and
|
|
13848
|
+
* every later probe is silently dropped (v1.9.9 bug: wake was detected but
|
|
13849
|
+
* the page only recovered with F5). socket.disconnect() closes the
|
|
13850
|
+
* manager regardless of the engine, and connect() opens a new engine.
|
|
13851
|
+
*/
|
|
13852
|
+
_forceReconnect(reason) {
|
|
13853
|
+
const socket = this.socket;
|
|
13854
|
+
if (!socket) return;
|
|
13855
|
+
console.warn('[SSHIFT] Forcing a new connection (' + reason + ')');
|
|
13856
|
+
const engine = socket.io && socket.io.engine;
|
|
13857
|
+
this._lastKickAt = Date.now();
|
|
13858
|
+
this._probeInFlight = false;
|
|
13859
|
+
try { socket.disconnect(); } catch (_) {}
|
|
13860
|
+
// Make sure the old transport is really gone (no stray events/timers).
|
|
13861
|
+
try { if (engine && engine.transport) engine.transport.close(); } catch (_) {}
|
|
13862
|
+
socket.connect();
|
|
13863
|
+
this._armDisconnectToast();
|
|
13864
|
+
}
|
|
13865
|
+
|
|
13709
13866
|
_cancelDisconnectToast() {
|
|
13710
13867
|
if (this._disconnectToastTimer) {
|
|
13711
13868
|
clearTimeout(this._disconnectToastTimer);
|
|
@@ -13832,9 +13989,13 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null,
|
|
|
13832
13989
|
|
|
13833
13990
|
// Utility Functions
|
|
13834
13991
|
escapeHtml(text) {
|
|
13835
|
-
|
|
13836
|
-
|
|
13837
|
-
|
|
13992
|
+
// Also safe inside quoted attributes (tab names, URLs, ids).
|
|
13993
|
+
return String(text == null ? '' : text)
|
|
13994
|
+
.replace(/&/g, '&')
|
|
13995
|
+
.replace(/</g, '<')
|
|
13996
|
+
.replace(/>/g, '>')
|
|
13997
|
+
.replace(/"/g, '"')
|
|
13998
|
+
.replace(/'/g, ''');
|
|
13838
13999
|
}
|
|
13839
14000
|
|
|
13840
14001
|
formatSize(bytes) {
|