Add account logout feature via context menu

This commit is contained in:
miruka 2019-08-21 17:45:05 -04:00
parent 7331c1fa1c
commit b8d43ecfec
7 changed files with 47 additions and 15 deletions

View File

@ -18,7 +18,10 @@
- When qml syntax highlighting supports ES6 string interpolation, use them - When qml syntax highlighting supports ES6 string interpolation, use them
- Fixes - Fixes
- Restore previous focus after right click - Button loading icon with only text
- Highlight when adding new account
- Restore previous focus after closing right click context menu
- Reloading config files (cache) - Reloading config files (cache)
- Run import in thread and AsyncClient.olm functions, they block async loop - Run import in thread and AsyncClient.olm functions, they block async loop
@ -82,6 +85,7 @@
blank space blank space
- Sidepane - Sidepane
- Animate when logging out last account and sidepane turns invisible
- Header back button when reduced - Header back button when reduced
- Better look for arrows and option button when collapsed - Better look for arrows and option button when collapsed
- Show it when hovering/hitting focus keybind on the left when collapsed - Show it when hovering/hitting focus keybind on the left when collapsed
@ -91,7 +95,7 @@
- Server selection - Server selection
- Register/Forgot? for SignIn dialog - Register/Forgot? for SignIn dialog
- Add room - Add room
- Leave/forget room warning popup - Logout & leave/forget room warning popup
- Prevent using the SendBox if no permission (power levels) - Prevent using the SendBox if no permission (power levels)
- Prevent using an alias if that user is not in the room or no permission - Prevent using an alias if that user is not in the room or no permission
- Spinner when loading account, past room events, images or clicking buttons - Spinner when loading account, past room events, images or clicking buttons

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M9.602 3.7c-1.154 1.937-.635 5.227 1.424 9.025.93 1.712.697 3.02.338 3.815-.982 2.178-3.675 2.799-6.525 3.456-1.964.454-1.839.87-1.839 4.004h-1.995l-.005-1.241c0-2.52.199-3.975 3.178-4.663 3.365-.777 6.688-1.473 5.09-4.418-4.733-8.729-1.35-13.678 3.732-13.678 3.321 0 5.97 2.117 5.97 6.167 0 3.555-1.949 6.833-2.383 7.833h-2.115c.392-1.536 2.499-4.366 2.499-7.842 0-5.153-5.867-4.985-7.369-2.458zm13.398 15.3h-8v2h8v-2z"/></svg>

After

Width:  |  Height:  |  Size: 520 B

View File

@ -99,14 +99,10 @@ class Backend:
async def logout_client(self, user_id: str) -> None: async def logout_client(self, user_id: str) -> None:
client = self.clients.pop(user_id, None) client = self.clients.pop(user_id, None)
if client: if client:
self.models[Account].pop(client.user_id, None) self.models[Account].pop(user_id, None)
await client.logout() await client.logout()
await self.saved_accounts.delete(user_id)
async def logout_all_clients(self) -> None:
await asyncio.gather(*(
self.logout_client(user_id) for user_id in self.clients.copy()
))
async def wait_until_client_exists(self, user_id: str = "") -> None: async def wait_until_client_exists(self, user_id: str = "") -> None:

View File

@ -131,6 +131,7 @@ class MatrixClient(nio.AsyncClient):
with suppress(asyncio.CancelledError): with suppress(asyncio.CancelledError):
await self.sync_task await self.sync_task
await super().logout()
await self.close() await self.close()
@ -146,13 +147,14 @@ class MatrixClient(nio.AsyncClient):
ft = asyncio.ensure_future(self.backend.get_profile(self.user_id)) ft = asyncio.ensure_future(self.backend.get_profile(self.user_id))
ft.add_done_callback(on_profile_response) ft.add_done_callback(on_profile_response)
def on_unexpected_sync_stop(future) -> None: def on_sync_stop(future) -> None:
raise future.exception() if isinstance(future.exception(), BaseException):
raise future.exception()
self.sync_task = asyncio.ensure_future( self.sync_task = asyncio.ensure_future(
self.sync_forever(timeout=10_000), self.sync_forever(timeout=10_000),
) )
self.sync_task.add_done_callback(on_unexpected_sync_stop) self.sync_task.add_done_callback(on_sync_stop)
@property @property

View File

@ -21,7 +21,7 @@ HPage {
onRoomInfoChanged: { onRoomInfoChanged: {
if (roomInfo.left) { if (roomInfo.left) {
// The room will most likely be gone on client restart // If left, the room will most likely be gone on client restart
window.uiState.page = "Pages/Default.qml" window.uiState.page = "Pages/Default.qml"
window.uiState.pageProperties = {} window.uiState.pageProperties = {}
window.uiStateChanged() window.uiStateChanged()

View File

@ -25,6 +25,7 @@ HPage {
Utils.coloredNameHtml(headerName, userId) Utils.coloredNameHtml(headerName, userId)
) )
HSpacer {} HSpacer {}
Repeater { Repeater {

View File

@ -19,6 +19,7 @@ HTileDelegate {
Behavior on opacity { HNumberAnimation {} } Behavior on opacity { HNumberAnimation {} }
property bool disconnecting: false
readonly property bool forceExpand: Boolean(accountRoomList.filter) readonly property bool forceExpand: Boolean(accountRoomList.filter)
// Hide harmless error when a filter matches nothing // Hide harmless error when a filter matches nothing
@ -27,9 +28,11 @@ HTileDelegate {
} catch (err) {} } catch (err) {}
onActivated: pageLoader.showPage( onActivated: if (! disconnecting) {
"EditAccount/EditAccount", { "userId": model.data.user_id } pageLoader.showPage(
) "EditAccount/EditAccount", { "userId": model.data.user_id }
)
}
function toggleCollapse() { function toggleCollapse() {
@ -70,4 +73,29 @@ HTileDelegate {
Behavior on opacity { HNumberAnimation {} } Behavior on opacity { HNumberAnimation {} }
} }
contextMenu: HMenu {
HMenuItem {
icon.name: "logout"
text: qsTr("Logout")
onTriggered: {
disconnecting = true
let page = window.uiState.page
let userId = model.data.user_id
if ((modelSources["Account"] || []).length < 2) {
pageLoader.showPage("SignIn")
}
else if ((page == "Pages/EditAccount/EditAccount.qml" ||
page == "Chat/Chat.qml") &&
window.uiState.pageProperties.userId == userId)
{
pageLoader.showPage("Default")
}
py.callCoro("logout_client", [userId])
}
}
}
} }