Import/export keys improvements
This commit is contained in:
parent
1d3ca08957
commit
2b288bdfc6
|
@ -7,7 +7,6 @@ import re
|
||||||
import traceback
|
import traceback
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partial
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, DefaultDict, Dict, NamedTuple, Optional, Set, Tuple, Type, Union,
|
Any, DefaultDict, Dict, NamedTuple, Optional, Set, Tuple, Type, Union,
|
||||||
|
@ -606,35 +605,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
|
|
||||||
async def import_keys(self, infile: str, passphrase: str) -> None:
|
async def import_keys(self, infile: str, passphrase: str) -> None:
|
||||||
# Reimplemented until better solutions are worked on in nio
|
await super().import_keys(infile, passphrase)
|
||||||
await self.clear_import_error()
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
|
|
||||||
account = self.models[Account][self.user_id]
|
|
||||||
import_keys = partial(self.olm.import_keys_static, infile, passphrase)
|
|
||||||
|
|
||||||
account.importing_key = 0
|
|
||||||
account.total_keys_to_import = -1 # preparing
|
|
||||||
|
|
||||||
try:
|
|
||||||
sessions = await loop.run_in_executor(None, import_keys)
|
|
||||||
except nio.EncryptionError as err: # XXX raise
|
|
||||||
account.import_error = (infile, passphrase, str(err))
|
|
||||||
return
|
|
||||||
|
|
||||||
account.total_keys_to_import = len(sessions)
|
|
||||||
|
|
||||||
for session in sessions:
|
|
||||||
if self.olm.inbound_group_store.add(session):
|
|
||||||
await loop.run_in_executor(
|
|
||||||
None, self.store.save_inbound_group_session, session,
|
|
||||||
)
|
|
||||||
account.importing_key += 1
|
|
||||||
|
|
||||||
account.importing_key = 0
|
|
||||||
account.total_keys_to_import = 0
|
|
||||||
|
|
||||||
await self.retry_decrypting_events()
|
await self.retry_decrypting_events()
|
||||||
|
|
||||||
|
|
||||||
|
@ -649,10 +620,6 @@ class MatrixClient(nio.AsyncClient):
|
||||||
await super().export_keys(outfile, passphrase)
|
await super().export_keys(outfile, passphrase)
|
||||||
|
|
||||||
|
|
||||||
async def clear_import_error(self) -> None:
|
|
||||||
self.models[Account][self.user_id].import_error = ("", "", "")
|
|
||||||
|
|
||||||
|
|
||||||
async def retry_decrypting_events(self) -> None:
|
async def retry_decrypting_events(self) -> None:
|
||||||
for sync_id, model in self.models.items():
|
for sync_id, model in self.models.items():
|
||||||
if not (isinstance(sync_id, tuple) and
|
if not (isinstance(sync_id, tuple) and
|
||||||
|
|
|
@ -11,12 +11,21 @@ HFileDialogOpener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
signal done()
|
||||||
|
|
||||||
|
|
||||||
property string userId: ""
|
property string userId: ""
|
||||||
|
property bool importing: false
|
||||||
|
|
||||||
|
|
||||||
function importKeys(file, passphrase) {
|
function importKeys(file, passphrase) {
|
||||||
|
importing = true
|
||||||
|
|
||||||
let path = file.toString().replace(/^file:\/\//, "")
|
let path = file.toString().replace(/^file:\/\//, "")
|
||||||
py.callClientCoro(userId, "import_keys", [path, passphrase])
|
py.callClientCoro(userId, "import_keys", [path, passphrase], () => {
|
||||||
|
importing = false
|
||||||
|
done()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ HPage {
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
id: repeater
|
id: repeater
|
||||||
model: ["Profile.qml", "Encryption.qml"]
|
model: ["Profile.qml", "ImportExportKeys.qml"]
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
color: ready ? theme.controls.box.background : "transparent"
|
color: ready ? theme.controls.box.background : "transparent"
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
import QtQuick 2.12
|
|
||||||
import "../../Base"
|
|
||||||
|
|
||||||
HLoader {
|
|
||||||
id: encryptionUI
|
|
||||||
source:
|
|
||||||
accountInfo.import_error[0] ? "ImportError.qml" :
|
|
||||||
accountInfo.total_keys_to_import ? "ImportingKeys.qml" :
|
|
||||||
"ImportExportKeys.qml"
|
|
||||||
|
|
||||||
onSourceChanged: animation.running = true
|
|
||||||
|
|
||||||
|
|
||||||
SequentialAnimation {
|
|
||||||
id: animation
|
|
||||||
HNumberAnimation {
|
|
||||||
target: encryptionUI; property: "scale"; to: 0;
|
|
||||||
}
|
|
||||||
HNumberAnimation {
|
|
||||||
target: encryptionUI; property: "scale"; to: 1; overshoot: 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user