Set users to offline before exiting Mirage

This commit is contained in:
vslg 2020-07-16 22:19:20 -03:00 committed by miruka
parent 189b325a2b
commit b69cbf9d14
2 changed files with 26 additions and 0 deletions

View File

@ -198,6 +198,16 @@ class Backend:
)) ))
async def logoff_all(self) -> None:
"""Stop syncing and end all clients registered."""
await asyncio.gather(*[
client.set_presence("offline", save=False)
for client in self.clients.values()
if client._presence != "offline"
])
async def logout_client(self, user_id: str) -> None: async def logout_client(self, user_id: str) -> None:
"""Log a `MatrixClient` out and unregister it from our models.""" """Log a `MatrixClient` out and unregister it from our models."""

View File

@ -16,6 +16,7 @@ class.
import asyncio import asyncio
import logging as log import logging as log
import os import os
import pyotherside
import signal import signal
import traceback import traceback
from concurrent.futures import Future from concurrent.futures import Future
@ -143,6 +144,19 @@ class QMLBridge:
remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace() remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace()
def exit_mirage(self) -> None:
"""Used to end some tasks before closing"""
try:
# Set accounts presence to offline
asyncio.run_coroutine_threadsafe(
self.backend.logoff_all(),
self._loop,
).result()
except Exception as e:
print(e)
# The AppImage AppRun script overwrites some environment path variables to # The AppImage AppRun script overwrites some environment path variables to
# correctly work, and sets RESTORE_<name> equivalents with the original values. # correctly work, and sets RESTORE_<name> equivalents with the original values.
# If the app is launched from an AppImage, now restore the original values # If the app is launched from an AppImage, now restore the original values
@ -162,3 +176,5 @@ except ValueError:
pass pass
BRIDGE = QMLBridge() BRIDGE = QMLBridge()
pyotherside.atexit(BRIDGE.exit_mirage)