@lethevimlet/sshift 1.8.0 → 1.8.2
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 +7 -5
- package/package.json +1 -1
- package/src/server/endpoints/rest/system.js +17 -12
- package/src/server/index.js +26 -140
- package/src/server/utils/certs.js +314 -0
- package/src/webapp/css/style.css +52 -18
- package/src/webapp/index.html +184 -142
- package/src/webapp/js/app.js +251 -18
- package/src/webapp/js/mobile-terminal.js +495 -77
- package/src/webapp/sw.js +65 -38
package/src/webapp/js/app.js
CHANGED
|
@@ -20,6 +20,16 @@ class SSHIFTClient {
|
|
|
20
20
|
this.activeSessionId = null; // Global active session (for backwards compatibility)
|
|
21
21
|
this.activeSessionsByPanel = new Map(); // Per-panel active sessions: Map<panelId, sessionId>
|
|
22
22
|
this._wasDisconnected = false; // Track reconnection state for toast messages
|
|
23
|
+
// Connection toasts (v1.8.2): a disconnect is only announced when it
|
|
24
|
+
// lasts longer than the grace period below while the page is visible;
|
|
25
|
+
// "Reconnected" only follows an announced disconnect; deliberate
|
|
26
|
+
// reconnects (auth token swap) are silent; the initial connect is the
|
|
27
|
+
// normal state and says nothing.
|
|
28
|
+
this._silentReconnect = false;
|
|
29
|
+
this._disconnectToastTimer = null;
|
|
30
|
+
this._disconnectToastShown = false;
|
|
31
|
+
this.DISCONNECT_TOAST_GRACE_MS = 2500;
|
|
32
|
+
this._staleReloadFor = null;
|
|
23
33
|
this._initReady = false; // Set true once init() completes
|
|
24
34
|
this._pendingOpenTabs = null; // Deferred open-tabs data
|
|
25
35
|
this._pendingOpenTabsIsInitial = false;
|
|
@@ -269,6 +279,8 @@ class SSHIFTClient {
|
|
|
269
279
|
updateSocketAuth() {
|
|
270
280
|
if (this.socket && this.authToken) {
|
|
271
281
|
this.socket.auth = { token: this.authToken };
|
|
282
|
+
// Deliberate reconnect: no Disconnected/Reconnected toasts for it.
|
|
283
|
+
this._silentReconnect = true;
|
|
272
284
|
this.socket.disconnect().connect();
|
|
273
285
|
}
|
|
274
286
|
}
|
|
@@ -2143,7 +2155,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2143
2155
|
|
|
2144
2156
|
// Fallback to layouts.json
|
|
2145
2157
|
try {
|
|
2146
|
-
const layoutsResponse = await fetch('/layouts.json');
|
|
2158
|
+
const layoutsResponse = await fetch('/layouts.json?v=' + encodeURIComponent((typeof window !== 'undefined' && window.SSHIFT_VERSION) || ''));
|
|
2147
2159
|
if (layoutsResponse.ok) {
|
|
2148
2160
|
const data = await layoutsResponse.json();
|
|
2149
2161
|
if (data.layouts && Array.isArray(data.layouts)) {
|
|
@@ -2325,12 +2337,47 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2325
2337
|
});
|
|
2326
2338
|
}
|
|
2327
2339
|
|
|
2340
|
+
/**
|
|
2341
|
+
* The mobile top bar hosts two singleton controls (bookmarks button and
|
|
2342
|
+
* the "..." overflow menu with its big dropdown + listeners). They must
|
|
2343
|
+
* survive layout rebuilds (which recreate every tabs-container), so they
|
|
2344
|
+
* are moved, never recreated: parked in a hidden holder while the layout
|
|
2345
|
+
* is torn down, then mounted into the single panel's tabs-container.
|
|
2346
|
+
*/
|
|
2347
|
+
_parkMobileBarSingletons() {
|
|
2348
|
+
let parking = document.getElementById('mobileBarParking');
|
|
2349
|
+
if (!parking) {
|
|
2350
|
+
parking = document.createElement('div');
|
|
2351
|
+
parking.id = 'mobileBarParking';
|
|
2352
|
+
parking.style.display = 'none';
|
|
2353
|
+
document.body.appendChild(parking);
|
|
2354
|
+
}
|
|
2355
|
+
['mobileBookmarksBtn', 'mobileOverflowMenu'].forEach(id => {
|
|
2356
|
+
const el = document.getElementById(id);
|
|
2357
|
+
if (el && el.parentElement !== parking) parking.appendChild(el);
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
_mountMobileBarSingletons(tabsContainer) {
|
|
2362
|
+
if (!tabsContainer) return;
|
|
2363
|
+
const bookmarks = document.getElementById('mobileBookmarksBtn');
|
|
2364
|
+
if (bookmarks && bookmarks.parentElement !== tabsContainer) {
|
|
2365
|
+
tabsContainer.insertBefore(bookmarks, tabsContainer.firstChild);
|
|
2366
|
+
}
|
|
2367
|
+
const overflow = document.getElementById('mobileOverflowMenu');
|
|
2368
|
+
const actions = tabsContainer.querySelector('.tabs-actions');
|
|
2369
|
+
if (overflow && actions && overflow.parentElement !== actions) {
|
|
2370
|
+
actions.appendChild(overflow);
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2328
2374
|
applyLayout(layout, syncedTabs = null) {
|
|
2329
2375
|
const layoutContainer = document.getElementById('layoutContainer');
|
|
2330
2376
|
if (!layoutContainer) {
|
|
2331
2377
|
console.error('[SSHIFT] Layout container not found');
|
|
2332
2378
|
return;
|
|
2333
2379
|
}
|
|
2380
|
+
this._parkMobileBarSingletons();
|
|
2334
2381
|
|
|
2335
2382
|
// On mobile, always force single panel mode
|
|
2336
2383
|
const effectiveLayout = this.isMobile
|
|
@@ -2367,6 +2414,8 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2367
2414
|
// Clear and recreate single panel
|
|
2368
2415
|
layoutContainer.innerHTML = '';
|
|
2369
2416
|
this.createSinglePanel(layoutContainer, 0);
|
|
2417
|
+
} else {
|
|
2418
|
+
this._mountMobileBarSingletons(existingPanel.querySelector('.tabs-container'));
|
|
2370
2419
|
}
|
|
2371
2420
|
|
|
2372
2421
|
this.currentLayout = layout;
|
|
@@ -2744,6 +2793,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
|
|
|
2744
2793
|
actions.appendChild(speechToTextBtn);
|
|
2745
2794
|
|
|
2746
2795
|
container.appendChild(actions);
|
|
2796
|
+
if (isSingle) this._mountMobileBarSingletons(container);
|
|
2747
2797
|
|
|
2748
2798
|
return container;
|
|
2749
2799
|
}
|
|
@@ -4064,6 +4114,7 @@ const wheelHandler = (e) => {
|
|
|
4064
4114
|
if (!element) return defaultHeight;
|
|
4065
4115
|
|
|
4066
4116
|
const style = window.getComputedStyle(element);
|
|
4117
|
+
if (style.display === 'none') return 0;
|
|
4067
4118
|
const height = parseFloat(style.height) || 0;
|
|
4068
4119
|
const marginTop = parseFloat(style.marginTop) || 0;
|
|
4069
4120
|
const marginBottom = parseFloat(style.marginBottom) || 0;
|
|
@@ -4544,6 +4595,10 @@ const wheelHandler = (e) => {
|
|
|
4544
4595
|
// the rejoin completes (consumed by the ssh-joined handler; guarded
|
|
4545
4596
|
// there so we never steal control another client acquired meanwhile).
|
|
4546
4597
|
session._retakeControlOnRejoin = !!session.isController;
|
|
4598
|
+
// Remembered until we hold control again: getting it back (by
|
|
4599
|
+
// retake, or because the server reassigned it to us when our old
|
|
4600
|
+
// socket timed out) is not news worth a toast.
|
|
4601
|
+
session._heldControlBeforeDrop = !!session.isController;
|
|
4547
4602
|
|
|
4548
4603
|
// Mark as restoring so a "Session not found" reply routes into the
|
|
4549
4604
|
// credential-based auto-reconnect path instead of closing the tab.
|
|
@@ -4584,15 +4639,20 @@ const wheelHandler = (e) => {
|
|
|
4584
4639
|
console.log('[SSHIFT] Connected to server, socket ID:', this.socket.id);
|
|
4585
4640
|
const wasDisconnected = this._wasDisconnected;
|
|
4586
4641
|
this._wasDisconnected = false;
|
|
4587
|
-
|
|
4588
|
-
|
|
4642
|
+
this._silentReconnect = false;
|
|
4643
|
+
this._cancelDisconnectToast();
|
|
4644
|
+
if (wasDisconnected) {
|
|
4645
|
+
// Only announce the recovery of an outage that was announced.
|
|
4646
|
+
if (this._disconnectToastShown && !this.isUpdating) {
|
|
4647
|
+
this.showToast('Reconnected to server', 'success');
|
|
4648
|
+
}
|
|
4649
|
+
this._disconnectToastShown = false;
|
|
4589
4650
|
// The new socket must re-join its sessions (rooms + controller
|
|
4590
4651
|
// state are keyed by socket.id and were lost with the old socket).
|
|
4591
4652
|
this.rejoinActiveSessions();
|
|
4592
|
-
} else if (!this.isUpdating) {
|
|
4593
|
-
this.showToast('Connected to server', 'success');
|
|
4594
4653
|
}
|
|
4595
4654
|
this.loadBookmarks();
|
|
4655
|
+
this._checkServerVersion();
|
|
4596
4656
|
});
|
|
4597
4657
|
|
|
4598
4658
|
this.socket.on('disconnect', (reason) => {
|
|
@@ -4601,8 +4661,8 @@ const wheelHandler = (e) => {
|
|
|
4601
4661
|
if (reason === 'io server disconnect') {
|
|
4602
4662
|
// Server intentionally disconnected us (e.g. auth failure) — don't auto-reconnect
|
|
4603
4663
|
// Socket.IO won't retry after server-initiated disconnect anyway
|
|
4604
|
-
} else if (!this.isUpdating) {
|
|
4605
|
-
this.
|
|
4664
|
+
} else if (!this.isUpdating && !this._silentReconnect) {
|
|
4665
|
+
this._armDisconnectToast();
|
|
4606
4666
|
}
|
|
4607
4667
|
});
|
|
4608
4668
|
|
|
@@ -4614,6 +4674,10 @@ const wheelHandler = (e) => {
|
|
|
4614
4674
|
if (!this.socket.connected) {
|
|
4615
4675
|
console.log('[SSHIFT] Tab visible and socket disconnected, triggering reconnect');
|
|
4616
4676
|
this.socket.connect();
|
|
4677
|
+
// Give the reconnect the same grace period before complaining.
|
|
4678
|
+
this._armDisconnectToast();
|
|
4679
|
+
} else {
|
|
4680
|
+
this._checkServerVersion();
|
|
4617
4681
|
}
|
|
4618
4682
|
this.clearFlashesForVisibleSessions();
|
|
4619
4683
|
this._refreshAllWebGLSessions();
|
|
@@ -4636,6 +4700,10 @@ const wheelHandler = (e) => {
|
|
|
4636
4700
|
localStorage.removeItem('sshift_auth_token');
|
|
4637
4701
|
this.showLockScreen();
|
|
4638
4702
|
}
|
|
4703
|
+
// A rejected handshake after a server restart is also the first
|
|
4704
|
+
// moment we can learn that the server was updated (the version
|
|
4705
|
+
// check normally runs on connect, which never comes here).
|
|
4706
|
+
this._checkServerVersion();
|
|
4639
4707
|
// Don't show generic connection error toasts during reconnection —
|
|
4640
4708
|
// the user already sees "Disconnected" and the auto-reconnect handles it.
|
|
4641
4709
|
// Only show for explicit user actions (not isUpdating suppresses during update).
|
|
@@ -4842,7 +4910,7 @@ const wheelHandler = (e) => {
|
|
|
4842
4910
|
// Delay to ensure the session is fully set up
|
|
4843
4911
|
const delay = 100 + Math.random() * 200; // 100-300ms
|
|
4844
4912
|
setTimeout(() => {
|
|
4845
|
-
this.requestTakeControl(data.sessionId);
|
|
4913
|
+
this.requestTakeControl(data.sessionId, { announce: false });
|
|
4846
4914
|
}, delay);
|
|
4847
4915
|
} else {
|
|
4848
4916
|
console.log('[SSHIFT] Not taking control - another client is already in control');
|
|
@@ -5128,8 +5196,14 @@ const wheelHandler = (e) => {
|
|
|
5128
5196
|
});
|
|
5129
5197
|
});
|
|
5130
5198
|
}
|
|
5131
|
-
|
|
5132
|
-
|
|
5199
|
+
// Silent when we are only getting our own control back after a
|
|
5200
|
+
// reconnect (the "previous controller" was this device's old
|
|
5201
|
+
// socket, which the server timed out).
|
|
5202
|
+
if (!session._heldControlBeforeDrop) {
|
|
5203
|
+
this.showToast('You are now in control (previous controller left)', 'info');
|
|
5204
|
+
}
|
|
5205
|
+
session._heldControlBeforeDrop = false;
|
|
5206
|
+
} else if (!session.isController && wasController) {
|
|
5133
5207
|
this.showToast('Another device took control', 'info');
|
|
5134
5208
|
}
|
|
5135
5209
|
}
|
|
@@ -5234,7 +5308,14 @@ const wheelHandler = (e) => {
|
|
|
5234
5308
|
});
|
|
5235
5309
|
}
|
|
5236
5310
|
|
|
5237
|
-
|
|
5311
|
+
// Automatic take-control (session join, rejoin after a reconnect,
|
|
5312
|
+
// tab restore) is the normal state and stays silent; only an
|
|
5313
|
+
// explicit "Take Control" tap is confirmed.
|
|
5314
|
+
if (session._announceControl) {
|
|
5315
|
+
this.showToast('You are now in control', 'success');
|
|
5316
|
+
}
|
|
5317
|
+
session._announceControl = false;
|
|
5318
|
+
session._heldControlBeforeDrop = false;
|
|
5238
5319
|
}
|
|
5239
5320
|
});
|
|
5240
5321
|
|
|
@@ -5764,6 +5845,16 @@ const wheelHandler = (e) => {
|
|
|
5764
5845
|
document.getElementById('menuBtn').addEventListener('click', () => {
|
|
5765
5846
|
this.toggleSidebar();
|
|
5766
5847
|
});
|
|
5848
|
+
// Mobile top bar (replaces the mobile header): bookmarks button in the
|
|
5849
|
+
// tabs bar, close button inside the sidebar (the sidebar covers the bar).
|
|
5850
|
+
['mobileBookmarksBtn', 'sidebarCloseBtn'].forEach(id => {
|
|
5851
|
+
const el = document.getElementById(id);
|
|
5852
|
+
if (el) el.addEventListener('click', () => this.toggleSidebar());
|
|
5853
|
+
});
|
|
5854
|
+
const copyInputTraceBtn = document.getElementById('copyInputTraceBtn');
|
|
5855
|
+
if (copyInputTraceBtn) {
|
|
5856
|
+
copyInputTraceBtn.addEventListener('click', () => this.copyInputTrace());
|
|
5857
|
+
}
|
|
5767
5858
|
|
|
5768
5859
|
// Sidebar overlay click to close
|
|
5769
5860
|
const sidebarOverlay = document.getElementById('sidebarOverlay');
|
|
@@ -6866,10 +6957,18 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
6866
6957
|
if (dontShow === 'true') return;
|
|
6867
6958
|
|
|
6868
6959
|
const isLocalhost = ['localhost', '127.0.0.1', '::1'].includes(window.location.hostname);
|
|
6869
|
-
const
|
|
6870
|
-
|
|
6960
|
+
const swOk = () => {
|
|
6961
|
+
if (navigator.serviceWorker && navigator.serviceWorker.controller) return true;
|
|
6962
|
+
// First visit: the worker is still installing/activating (the page
|
|
6963
|
+
// no longer reloads on first install), which is just as healthy.
|
|
6964
|
+
return ['active', 'installing', 'registered'].includes(window._swStatus);
|
|
6965
|
+
};
|
|
6966
|
+
if (isLocalhost || swOk()) return;
|
|
6871
6967
|
|
|
6872
|
-
setTimeout(() =>
|
|
6968
|
+
setTimeout(() => {
|
|
6969
|
+
if (swOk()) return;
|
|
6970
|
+
this.openSecurityInfoDialog();
|
|
6971
|
+
}, 1500);
|
|
6873
6972
|
}
|
|
6874
6973
|
|
|
6875
6974
|
openSecurityInfoDialog() {
|
|
@@ -6984,14 +7083,16 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
6984
7083
|
const certPathEl = document.getElementById('debugCertPath');
|
|
6985
7084
|
const keyPathEl = document.getElementById('debugKeyPath');
|
|
6986
7085
|
const certTypeEl = document.getElementById('debugCertType');
|
|
7086
|
+
const caCertPathEl = document.getElementById('debugCaCertPath');
|
|
6987
7087
|
|
|
6988
7088
|
if (configPathEl) configPathEl.textContent = info.configPath || 'N/A';
|
|
6989
7089
|
if (dataDirEl) dataDirEl.textContent = info.dataDir || 'N/A';
|
|
6990
7090
|
if (certPathEl) certPathEl.textContent = info.certPath || 'N/A';
|
|
6991
7091
|
if (keyPathEl) keyPathEl.textContent = info.keyPath || 'N/A';
|
|
6992
|
-
if (
|
|
7092
|
+
if (caCertPathEl) caCertPathEl.textContent = info.caCertPath || 'N/A';
|
|
7093
|
+
if (certTypeEl) certTypeEl.textContent = info.certType || (info.usesCustomCert ? 'Custom' : 'Local CA-signed');
|
|
6993
7094
|
}).catch(() => {
|
|
6994
|
-
const ids = ['debugConfigPath', 'debugDataDir', 'debugCertPath', 'debugKeyPath', 'debugCertType'];
|
|
7095
|
+
const ids = ['debugConfigPath', 'debugDataDir', 'debugCertPath', 'debugKeyPath', 'debugCaCertPath', 'debugCertType'];
|
|
6995
7096
|
ids.forEach(id => {
|
|
6996
7097
|
const el = document.getElementById(id);
|
|
6997
7098
|
if (el) el.textContent = 'Error loading';
|
|
@@ -7001,6 +7102,49 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
7001
7102
|
this.openModal('debugInfoModal');
|
|
7002
7103
|
}
|
|
7003
7104
|
|
|
7105
|
+
/**
|
|
7106
|
+
* Copy the mobile handlers' keyboard/IME event trace to the clipboard
|
|
7107
|
+
* (Debug Info dialog). This is the data needed to diagnose Gboard
|
|
7108
|
+
* autocomplete/duplication reports — it records every input,
|
|
7109
|
+
* composition, focus, sync and reset on the hidden textarea.
|
|
7110
|
+
*/
|
|
7111
|
+
async copyInputTrace() {
|
|
7112
|
+
const trace = {};
|
|
7113
|
+
this.sessions.forEach((session, id) => {
|
|
7114
|
+
if (session.mobileHandler && typeof session.mobileHandler.getInputTrace === 'function') {
|
|
7115
|
+
trace[id] = session.mobileHandler.getInputTrace();
|
|
7116
|
+
}
|
|
7117
|
+
});
|
|
7118
|
+
const text = JSON.stringify({
|
|
7119
|
+
version: (window.SSHIFT_VERSION || document.getElementById('versionNumber')?.textContent || '').trim(),
|
|
7120
|
+
userAgent: navigator.userAgent,
|
|
7121
|
+
isMobile: this.isMobile,
|
|
7122
|
+
activeSessionId: this.activeSessionId,
|
|
7123
|
+
trace
|
|
7124
|
+
}, null, 1);
|
|
7125
|
+
console.log('[SSHIFT] Input trace:\n' + text);
|
|
7126
|
+
try {
|
|
7127
|
+
await navigator.clipboard.writeText(text);
|
|
7128
|
+
this.showToast('Input trace copied to clipboard', 'success');
|
|
7129
|
+
} catch (err) {
|
|
7130
|
+
// Clipboard API can be unavailable (insecure context, no gesture).
|
|
7131
|
+
// Fall back to a selectable textarea inside the dialog.
|
|
7132
|
+
let box = document.getElementById('inputTraceFallback');
|
|
7133
|
+
if (!box) {
|
|
7134
|
+
box = document.createElement('textarea');
|
|
7135
|
+
box.id = 'inputTraceFallback';
|
|
7136
|
+
box.readOnly = true;
|
|
7137
|
+
box.style.cssText = 'width:100%;height:160px;margin-top:8px;font-size:11px;font-family:monospace;';
|
|
7138
|
+
const body = document.querySelector('#debugInfoModal .modal-body') || document.getElementById('debugInfoModal');
|
|
7139
|
+
if (body) body.appendChild(box);
|
|
7140
|
+
}
|
|
7141
|
+
box.value = text;
|
|
7142
|
+
box.focus();
|
|
7143
|
+
box.select();
|
|
7144
|
+
this.showToast('Clipboard unavailable — trace shown below, long-press to copy', 'info');
|
|
7145
|
+
}
|
|
7146
|
+
}
|
|
7147
|
+
|
|
7004
7148
|
// Sessions Modal
|
|
7005
7149
|
async openSessionsModal() {
|
|
7006
7150
|
this.openModal('manageSessionsModal');
|
|
@@ -8538,7 +8682,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8538
8682
|
takeControlBtn.addEventListener('click', (e) => {
|
|
8539
8683
|
e.preventDefault();
|
|
8540
8684
|
e.stopPropagation();
|
|
8541
|
-
this.requestTakeControl(sessionId);
|
|
8685
|
+
this.requestTakeControl(sessionId, { announce: true });
|
|
8542
8686
|
});
|
|
8543
8687
|
|
|
8544
8688
|
controlContent.appendChild(controlIcon);
|
|
@@ -8640,6 +8784,11 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
8640
8784
|
letterSpacing: 0,
|
|
8641
8785
|
cursorBlink: false,
|
|
8642
8786
|
cursorStyle: 'block',
|
|
8787
|
+
// On mobile xterm's own textarea never has focus (the mobile
|
|
8788
|
+
// handler owns keyboard input, see MobileTerminalHandler.
|
|
8789
|
+
// _captureTerminalFocus), so the "inactive" cursor must look like
|
|
8790
|
+
// the active one or the terminal always shows a hollow cursor.
|
|
8791
|
+
cursorInactiveStyle: this.isMobile ? 'block' : 'outline',
|
|
8643
8792
|
scrollback: this.scrollback || 10000,
|
|
8644
8793
|
allowProposedApi: true,
|
|
8645
8794
|
convertEol: true,
|
|
@@ -13353,17 +13502,101 @@ async syncTabsFromServer(tabs, isInitialSync = false, activeTabsByPanel = null)
|
|
|
13353
13502
|
}, 50); // 50ms debounce to prevent flashing
|
|
13354
13503
|
}
|
|
13355
13504
|
|
|
13356
|
-
requestTakeControl(sessionId) {
|
|
13505
|
+
requestTakeControl(sessionId, opts) {
|
|
13357
13506
|
const session = this.sessions.get(sessionId);
|
|
13358
13507
|
if (!session || !session.connected) {
|
|
13359
13508
|
this.showToast('Session not connected', 'error');
|
|
13360
13509
|
return;
|
|
13361
13510
|
}
|
|
13362
13511
|
|
|
13512
|
+
session._announceControl = !!(opts && opts.announce);
|
|
13363
13513
|
console.log('[SSHIFT] Requesting control for session:', sessionId);
|
|
13364
13514
|
this.socket.emit('ssh-take-control', { sessionId });
|
|
13365
13515
|
}
|
|
13366
13516
|
|
|
13517
|
+
/**
|
|
13518
|
+
* Start the grace timer for the "Disconnected" toast. Socket drops on a
|
|
13519
|
+
* phone are routine (the OS freezes the page, the PWA is reopened, the
|
|
13520
|
+
* auth token is swapped in) and recover within a second or two; only a
|
|
13521
|
+
* lasting, visible outage is worth a toast.
|
|
13522
|
+
*/
|
|
13523
|
+
_armDisconnectToast() {
|
|
13524
|
+
this._cancelDisconnectToast();
|
|
13525
|
+
this._disconnectToastTimer = setTimeout(() => {
|
|
13526
|
+
this._disconnectToastTimer = null;
|
|
13527
|
+
if (!this.socket || this.socket.connected) return;
|
|
13528
|
+
if (this.isUpdating || this._silentReconnect) return;
|
|
13529
|
+
// Nobody is looking: the visibilitychange handler re-arms this.
|
|
13530
|
+
if (typeof document !== 'undefined' && document.hidden) return;
|
|
13531
|
+
this._disconnectToastShown = true;
|
|
13532
|
+
this.showToast('Disconnected from server — will reconnect automatically', 'warning');
|
|
13533
|
+
}, this.DISCONNECT_TOAST_GRACE_MS);
|
|
13534
|
+
}
|
|
13535
|
+
|
|
13536
|
+
_cancelDisconnectToast() {
|
|
13537
|
+
if (this._disconnectToastTimer) {
|
|
13538
|
+
clearTimeout(this._disconnectToastTimer);
|
|
13539
|
+
this._disconnectToastTimer = null;
|
|
13540
|
+
}
|
|
13541
|
+
}
|
|
13542
|
+
|
|
13543
|
+
/**
|
|
13544
|
+
* Stale-page detection: compare the version baked into this page
|
|
13545
|
+
* (window.SSHIFT_VERSION, rendered into index.html) with the version
|
|
13546
|
+
* the server reports now. They diverge when the server was updated
|
|
13547
|
+
* while this page stayed open (a PWA can live for days without a
|
|
13548
|
+
* navigation, so the service worker never gets an update check).
|
|
13549
|
+
* Runs after every (re)connect and whenever the page becomes visible.
|
|
13550
|
+
*/
|
|
13551
|
+
async _checkServerVersion() {
|
|
13552
|
+
let mine = null;
|
|
13553
|
+
try { mine = typeof window !== 'undefined' ? window.SSHIFT_VERSION : null; } catch (_) {}
|
|
13554
|
+
if (!mine || typeof fetch !== 'function') return;
|
|
13555
|
+
let serverVersion = null;
|
|
13556
|
+
try {
|
|
13557
|
+
const response = await fetch('/api/version', { cache: 'no-store' });
|
|
13558
|
+
if (!response || !response.ok) return;
|
|
13559
|
+
const data = await response.json();
|
|
13560
|
+
serverVersion = data && data.version;
|
|
13561
|
+
} catch (_) {
|
|
13562
|
+
return;
|
|
13563
|
+
}
|
|
13564
|
+
if (!serverVersion || serverVersion === mine) return;
|
|
13565
|
+
this._handleStaleClient(serverVersion, mine);
|
|
13566
|
+
}
|
|
13567
|
+
|
|
13568
|
+
_handleStaleClient(serverVersion, mine) {
|
|
13569
|
+
if (this._staleReloadFor === serverVersion) return;
|
|
13570
|
+
this._staleReloadFor = serverVersion;
|
|
13571
|
+
// One reload per server version per tab: if the page still comes back
|
|
13572
|
+
// with the old version (a proxy caching index.html), stop instead of
|
|
13573
|
+
// reloading forever.
|
|
13574
|
+
try {
|
|
13575
|
+
if (sessionStorage.getItem('sshift_reloaded_for') === serverVersion) {
|
|
13576
|
+
console.warn('[SSHIFT] Already reloaded for', serverVersion, 'but the page is still', mine);
|
|
13577
|
+
return;
|
|
13578
|
+
}
|
|
13579
|
+
sessionStorage.setItem('sshift_reloaded_for', serverVersion);
|
|
13580
|
+
} catch (_) {}
|
|
13581
|
+
console.log('[SSHIFT] Server runs', serverVersion, 'but this page is', mine, '— reloading');
|
|
13582
|
+
if (this.isUpdating) return; // the update flow reloads on its own
|
|
13583
|
+
this.showToast(`Updating to v${serverVersion}…`, 'info');
|
|
13584
|
+
// Let the new service worker install first (it takes over with
|
|
13585
|
+
// skipWaiting + clients.claim and the registration script reloads on
|
|
13586
|
+
// controllerchange); the timer is the fallback when there is no
|
|
13587
|
+
// service worker or the update check is slow.
|
|
13588
|
+
try {
|
|
13589
|
+
if (navigator.serviceWorker && navigator.serviceWorker.getRegistration) {
|
|
13590
|
+
navigator.serviceWorker.getRegistration().then((reg) => reg && reg.update()).catch(() => {});
|
|
13591
|
+
}
|
|
13592
|
+
} catch (_) {}
|
|
13593
|
+
setTimeout(() => {
|
|
13594
|
+
if (typeof window !== 'undefined' && window.location && typeof window.location.reload === 'function') {
|
|
13595
|
+
window.location.reload();
|
|
13596
|
+
}
|
|
13597
|
+
}, 4000);
|
|
13598
|
+
}
|
|
13599
|
+
|
|
13367
13600
|
// Toast Notifications
|
|
13368
13601
|
showToast(message, type = 'info') {
|
|
13369
13602
|
const MAX_TOASTS = 5;
|