diff --git a/core/client.js b/core/client.js index 62acaf76..3327a58f 100644 --- a/core/client.js +++ b/core/client.js @@ -8,6 +8,7 @@ let gFiles = {}; let gApp = {files: {}, emoji: '📦'}; let gEditor; let gOriginalInput; +let gUnloading; let kErrorColor = '#dc322f'; let kDisconnectColor = '#f00'; @@ -1560,27 +1561,31 @@ function connectSocket(path) { _receive_websocket_message(JSON.parse(event.data)); }; gSocket.onclose = function (event) { - const k_codes = { - 1000: 'Normal closure', - 1001: 'Going away', - 1002: 'Protocol error', - 1003: 'Unsupported data', - 1005: 'No status received', - 1006: 'Abnormal closure', - 1007: 'Invalid frame payload data', - 1008: 'Policy violation', - 1009: 'Message too big', - 1010: 'Missing extension', - 1011: 'Internal error', - 1012: 'Service restart', - 1013: 'Try again later', - 1014: 'Bad gateway', - 1015: 'TLS handshake', - }; - setStatusMessage( - '🔴 Closed: ' + (k_codes[event.code] || event.code), - kDisconnectColor - ); + if (gUnloading) { + setStatusMessage('⚪ Closing...', kStatusColor); + } else { + const k_codes = { + 1000: 'Normal closure', + 1001: 'Going away', + 1002: 'Protocol error', + 1003: 'Unsupported data', + 1005: 'No status received', + 1006: 'Abnormal closure', + 1007: 'Invalid frame payload data', + 1008: 'Policy violation', + 1009: 'Message too big', + 1010: 'Missing extension', + 1011: 'Internal error', + 1012: 'Service restart', + 1013: 'Try again later', + 1014: 'Bad gateway', + 1015: 'TLS handshake', + }; + setStatusMessage( + '🔴 Closed: ' + (k_codes[event.code] || event.code), + kDisconnectColor + ); + } }; } } @@ -1854,6 +1859,9 @@ window.addEventListener('load', function () { window.addEventListener('blur', blur); window.addEventListener('message', message, false); window.addEventListener('online', connectSocket); + window.addEventListener('beforeunload', function () { + gUnloading = true; + }); document.getElementById('name').value = window.location.pathname; document .getElementById('closeEditor')