diff --git a/whisper_local/__main__.py b/whisper_local/__main__.py index 3e7d242..f45a938 100644 --- a/whisper_local/__main__.py +++ b/whisper_local/__main__.py @@ -22,6 +22,7 @@ class App: self._config = config self._loop: asyncio.AbstractEventLoop | None = None self._hotkey_task: asyncio.Task | None = None + self._quit_event: asyncio.Event | None = None self.recorder = Recorder( sample_rate=config.sample_rate, @@ -63,8 +64,8 @@ class App: def _quit(self) -> None: """Beendet die Anwendung sauber.""" - if self._loop is not None: - self._loop.call_soon_threadsafe(self._loop.stop) + if self._loop is not None and self._quit_event is not None: + self._loop.call_soon_threadsafe(self._quit_event.set) def _open_settings(self) -> None: """Öffnet den Einstellungs-Dialog.""" @@ -97,10 +98,11 @@ class App: async def run(self) -> None: """Startet den Hauptloop.""" self._loop = asyncio.get_running_loop() + self._quit_event = asyncio.Event() logger.info("whisper-local gestartet, warte auf Hotkey...") self.tray.start() self._hotkey_task = asyncio.create_task(self.hotkey.listen()) - await self._hotkey_task + await self._quit_event.wait() def main():