From f54075b7e0b15d8ef1629fd7fb16b6b0f52a36e4 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 21 Mar 2020 23:39:57 -0400 Subject: [PATCH] Improve default device name The number returned by platform.version() is only meaningful in a long-time scenario on Windows. Also make the function clearer. --- src/backend/matrix_client.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index cf9ad185..e36115aa 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -154,19 +154,27 @@ class MatrixClient(nio.AsyncClient): return response - @property - def default_device_name(self) -> str: + @staticmethod + def default_device_name() -> str: """Device name to set at login if the user hasn't set a custom one.""" - os_ = f" on {platform.system()}".rstrip() - os_ = f"{os_} {platform.release()}".rstrip() if os_ != " on" else "" - return f"{__display_name__}{os_}" + os_name = platform.system() + + if not os_name: # unknown OS + return __display_name__ + + # On Linux, the kernel version is returned, so for a one-time-set + # device name it would quickly be outdated. + os_ver = platform.release() if os_name == "Windows" else "" + return f"{__display_name__} on {os_name} {os_ver}".rstrip() async def login(self, password: str, device_name: str = "") -> None: """Login to the server using the account's password.""" - await super().login(password, device_name or self.default_device_name) + await super().login( + password, device_name or self.default_device_name(), + ) asyncio.ensure_future(self._start())