refactor: Add reference to itself in bootstrap onUpdate callback

This commit is contained in:
Christian Pauly 2022-08-12 15:23:32 +02:00
parent eed3587cb6
commit 527bcc63ad
4 changed files with 9 additions and 24 deletions

View File

@ -79,7 +79,7 @@ class Encryption {
}
}
Bootstrap bootstrap({void Function()? onUpdate}) => Bootstrap(
Bootstrap bootstrap({void Function(Bootstrap)? onUpdate}) => Bootstrap(
encryption: this,
onUpdate: onUpdate,
);

View File

@ -73,7 +73,7 @@ enum BootstrapState {
class Bootstrap {
final Encryption encryption;
Client get client => encryption.client;
void Function()? onUpdate;
void Function(Bootstrap)? onUpdate;
BootstrapState get state => _state;
BootstrapState _state = BootstrapState.loading;
Map<String, OpenSSSS>? oldSsssKeys;
@ -593,7 +593,7 @@ class Bootstrap {
_state = newState;
}
onUpdate?.call();
onUpdate?.call(this);
}
}

View File

@ -55,7 +55,7 @@ abstract class NativeImplementations {
/// this implementation will catch any non-implemented method
dynamic noSuchMethod(Invocation invocation) {
final dynamic argument = invocation.positionalArguments.single;
final bool retryInDummy = invocation.namedArguments['retryInDummy'] as bool;
final retryInDummy = invocation.namedArguments['retryInDummy'] as bool;
final memberName = invocation.memberName.toString().split('"')[1];
Logs().w(

View File

@ -53,10 +53,7 @@ void main() {
Bootstrap? bootstrap;
bootstrap = client.encryption!.bootstrap(
onUpdate: () async {
while (bootstrap == null) {
await Future.delayed(Duration(milliseconds: 5));
}
onUpdate: (bootstrap) async {
if (bootstrap.state == BootstrapState.askWipeSsss) {
bootstrap.wipeSsss(true);
} else if (bootstrap.state == BootstrapState.askNewSsss) {
@ -111,10 +108,7 @@ void main() {
if (!olmEnabled) return;
Bootstrap? bootstrap;
bootstrap = client.encryption!.bootstrap(
onUpdate: () async {
while (bootstrap == null) {
await Future.delayed(Duration(milliseconds: 5));
}
onUpdate: (bootstrap) async {
if (bootstrap.state == BootstrapState.askWipeSsss) {
bootstrap.wipeSsss(false);
} else if (bootstrap.state == BootstrapState.askUseExistingSsss) {
@ -165,10 +159,7 @@ void main() {
Bootstrap? bootstrap;
bootstrap = client.encryption!.bootstrap(
onUpdate: () async {
while (bootstrap == null) {
await Future.delayed(Duration(milliseconds: 5));
}
onUpdate: (bootstrap) async {
if (bootstrap.state == BootstrapState.askWipeSsss) {
bootstrap.wipeSsss(false);
} else if (bootstrap.state == BootstrapState.askUseExistingSsss) {
@ -219,10 +210,7 @@ void main() {
client.accountData.clear();
Bootstrap? bootstrap;
bootstrap = client.encryption!.bootstrap(
onUpdate: () async {
while (bootstrap == null) {
await Future.delayed(Duration(milliseconds: 5));
}
onUpdate: (bootstrap) async {
if (bootstrap.state == BootstrapState.askNewSsss) {
await bootstrap.newSsss('thenewestfoxies');
} else if (bootstrap.state == BootstrapState.askSetupCrossSigning) {
@ -248,10 +236,7 @@ void main() {
var askedBadSsss = false;
Bootstrap? bootstrap;
bootstrap = client.encryption!.bootstrap(
onUpdate: () async {
while (bootstrap == null) {
await Future.delayed(Duration(milliseconds: 5));
}
onUpdate: (bootstrap) async {
if (bootstrap.state == BootstrapState.askWipeSsss) {
bootstrap.wipeSsss(false);
} else if (bootstrap.state == BootstrapState.askBadSsss) {