From 3db9ce34f5c84613d7c41ae9cf867fa2332cb21e Mon Sep 17 00:00:00 2001 From: Andreas Fruhwirt Date: Sat, 5 Apr 2025 19:29:54 +0200 Subject: [PATCH] fixed context menu long press open --- application.py | 22 +++++++++++----------- static/record.js | 7 +++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/application.py b/application.py index 274c7bc..a886cd2 100644 --- a/application.py +++ b/application.py @@ -74,16 +74,16 @@ def is_authorized(credentials: Annotated[HTTPBasicCredentials, Depends(security) def refresh_ui_enabled(client_id): global client_data - with client_data[client_id].container: - if client_data[client_id].websocket.generating: - enable_ui(client_id, 2) - return - if client_data[client_id].websocket.stopped.is_set(): - enable_ui(client_id, 1) - stop_recording(client_id) - return - enable_ui(client_id, 0) - return + if client_id in client_data: + with client_data[client_id].container: + if client_data[client_id].websocket.generating: + enable_ui(client_id, 2) + return + if client_data[client_id].websocket.stopped.is_set(): + enable_ui(client_id, 1) + stop_recording(client_id) + return + enable_ui(client_id, 0) def after_websocket_init(client_id): if hasattr(client_data[client_id], "websocket") and not client_data[client_id].websocket.stopped.is_set(): @@ -224,7 +224,7 @@ async def main_page(credentials: Annotated[HTTPBasicCredentials, Depends(securit label = ui.label('Checking if the server is online...').classes('text-xl mb-20 whitespace-nowrap text-[3vw]') cd.text_above = label with ui.element().classes('w-[50vw] max-h-[75%] aspect-square rounded-full bg-grey text-white flex items-center justify-center whitespace-nowrap text-[3vw] active:scale-95 transition-transform').props("id=recordbutton disabled") as button: - ui.image('/static/microphone.png').classes('h-[75%] w-[75%] object-contain') + ui.image('/static/microphone.png').classes('h-[75%] w-[75%] object-contain').props("id=recordbuttonimage") button.on('mousedown', lambda: start_recording(client.id)) button.on('mouseup', lambda: stop_recording(client.id)) button.on('touchstart', lambda: start_recording(client.id)) diff --git a/static/record.js b/static/record.js index 1071ae3..0a88004 100644 --- a/static/record.js +++ b/static/record.js @@ -11,6 +11,13 @@ window.addEventListener("load", async (event) => { await navigator.mediaDevices.getUserMedia({ audio: true }); }); +document.getElementById('recordbuttonimage').oncontextmenu = function(event) { + event.preventDefault(); + event.stopPropagation(); // not necessary in my case, could leave in case stopImmediateProp isn't available? + event.stopImmediatePropagation(); + return false; +}; + function startButtonPulse(analyser) { const button = document.querySelector('#recordbutton');