Skip to content

Commit 44fb655

Browse files
committed
Disconnect toast added with colour green(white text)
1 parent 409ea22 commit 44fb655

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ async def scan_ble_devices():
6363

6464
@app.route('/check_stream')
6565
def check_stream():
66-
if connection_manager and connection_manager.stream_active:
67-
return jsonify({'connected': True})
68-
return jsonify({'connected': False})
66+
is_connected = connection_manager.stream_active if hasattr(connection_manager, 'stream_active') else False
67+
return jsonify({'connected': is_connected})
6968

7069
@app.route('/check_connection')
7170
def check_connection():

connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def cleanup(self):
237237

238238
if self.lsl_connection:
239239
self.lsl_connection = None
240+
self.stream_active = False
240241
print("LSL stream stopped")
241242

242243
if self.usb_connection:

static/script.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ function handleConnectionSuccess() {
608608
btn.disabled = true;
609609
});
610610

611-
showStatus(`Connected via ${selectedProtocol.toUpperCase()}`, 'fa-check-circle', 'text-green-500');
611+
showStatus(`Connected via ${selectedProtocol.toUpperCase()}`, 'fa-check-circle');
612612

613613
// Start console updates
614614
startConsoleUpdates();
@@ -793,7 +793,7 @@ initializeFilename(); // Set default filename with timestamp
793793
function showStatus(text, icon, colorClass) {
794794
const statusDiv = document.getElementById('connection-status');
795795
statusText.textContent = text;
796-
statusIcon.innerHTML = `<i class="fas ${icon} ${colorClass}"></i>`;
796+
statusIcon.innerHTML = `<i class="fas ${icon} text-white"></i>`;
797797
statusDiv.classList.remove('hidden');
798798
setTimeout(() => {
799799
statusDiv.classList.add('hidden');
@@ -811,6 +811,7 @@ function checkStreamStatus() {
811811
if (data.connected) {
812812
// If connected, update the frontend
813813
if (!isConnected) {
814+
handleConnectionSuccess();
814815
isConnected = true;
815816
connectBtn.classList.add('hidden');
816817
connectingBtn.classList.add('hidden');
@@ -822,6 +823,7 @@ function checkStreamStatus() {
822823
} else {
823824
// If not connected, update the frontend
824825
if (isConnected) {
826+
handleDisconnection();
825827
isConnected = false;
826828
disconnectBtn.classList.add('hidden');
827829
disconnectingBtn.classList.add('hidden');
@@ -860,6 +862,38 @@ function checkStreamStatus() {
860862
});
861863
}
862864

865+
function handleDisconnection() {
866+
isConnected = false;
867+
disconnectBtn.classList.add('hidden');
868+
disconnectingBtn.classList.add('hidden');
869+
connectingBtn.classList.add('hidden');
870+
connectBtn.classList.remove('hidden');
871+
showStatus('Stream disconnected!', 'fa-times-circle', 'text-red-500');
872+
873+
// Reset protocol buttons
874+
connectionBtns.forEach(btn => {
875+
btn.disabled = false;
876+
btn.classList.remove('bg-cyan-600', 'dark:bg-cyan-700', 'cursor-default');
877+
btn.classList.add('hover:bg-cyan-500', 'hover:text-white');
878+
});
879+
880+
// Handle recording state
881+
if (isRecording) {
882+
isRecording = false;
883+
recordBtn.innerHTML = 'Start Recording';
884+
recordBtn.classList.remove('bg-gray-500');
885+
recordBtn.classList.add('bg-red-500', 'hover:bg-red-600');
886+
recordingStatus.classList.add('hidden');
887+
filenameInput.disabled = false;
888+
showStatus('Recording stopped (stream lost)', 'fa-stop-circle', 'text-red-500');
889+
}
890+
891+
if (eventSource) {
892+
eventSource.close();
893+
eventSource = null;
894+
}
895+
}
896+
863897
// Call the checkStreamStatus function every 1 second
864898
setInterval(checkStreamStatus, 1000);
865899

templates/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
<div id="recording-status" class="flex items-center hidden">
7575
</div>
7676
</div>
77-
<div id="connection-status" class="fixed bottom-[3rem] right-1 bg-white dark:bg-gray-800 shadow-lg rounded-lg p-3 text-sm hidden z-50 border border-gray-200 dark:border-gray-700 min-w-[200px] flex items-center">
77+
<div id="connection-status" class="fixed bottom-[3rem] right-1 bg-[#001F0E] shadow-lg rounded-lg p-3 text-sm hidden z-50 border border-gray-200 dark:border-gray-700 min-w-[200px] flex items-center text-white">
7878
<span id="status-icon" class="mr-2"></span>
79-
<span id="status-text" class="text-gray-700 dark:text-gray-300">Connecting...</span>
79+
<span id="status-text" class="text-white">Connecting...</span>
8080
</div>
8181
</section>
8282

0 commit comments

Comments
 (0)