Merge branch 'krille/bootstrap' into 'main'

chore: Simplify bootstrap

See merge request famedly/fluffychat!358
This commit is contained in:
Krille Fear 2021-01-23 18:37:31 +00:00
commit d673e0ea36
4 changed files with 36 additions and 120 deletions

View File

@ -1,6 +1,7 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/encryption.dart';
import 'package:famedlysdk/encryption/utils/bootstrap.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/adaptive_flat_button.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/utils/platform_infos.dart';
@ -8,16 +9,21 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../matrix.dart';
class BootstrapDialog extends StatefulWidget {
const BootstrapDialog({Key key, @required this.l10n}) : super(key: key);
const BootstrapDialog({
Key key,
@required this.l10n,
@required this.client,
this.easyMode = false,
}) : super(key: key);
Future<bool> show(BuildContext context) => PlatformInfos.isCupertinoStyle
? showCupertinoDialog(context: context, builder: (context) => this)
: showDialog(context: context, builder: (context) => this);
final L10n l10n;
final Client client;
final bool easyMode;
@override
_BootstrapDialogState createState() => _BootstrapDialogState();
@ -28,17 +34,17 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
@override
Widget build(BuildContext context) {
bootstrap ??= Matrix.of(context)
.client
.encryption
bootstrap ??= widget.client.encryption
.bootstrap(onUpdate: () => setState(() => null));
final buttons = <AdaptiveFlatButton>[];
Widget body;
var titleText = widget.l10n.cachedKeys;
switch (bootstrap.state) {
case BootstrapState.loading:
body = LinearProgressIndicator();
titleText = widget.l10n.loadingPleaseWait;
break;
case BootstrapState.askWipeSsss:
body = Text('Wipe chat backup?');
@ -208,7 +214,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
break;
}
final title = Text('Chat backup');
final title = Text(titleText);
if (PlatformInfos.isCupertinoStyle) {
return CupertinoAlertDialog(
title: title,

View File

@ -139,13 +139,18 @@ class MatrixState extends State<Matrix> {
final stage = uiaRequest.nextStages.first;
switch (stage) {
case AuthenticationTypes.password:
final input = await showTextInputDialog(context: context, textFields: [
DialogTextField(
minLines: 1,
maxLines: 1,
obscureText: true,
)
]);
final input = await showTextInputDialog(
context: context,
title: L10n.of(context).pleaseEnterYourPassword,
textFields: [
DialogTextField(
minLines: 1,
maxLines: 1,
obscureText: true,
hintText: '******',
)
],
);
if (input?.isEmpty ?? true) return;
return uiaRequest.completeStage(
AuthenticationPassword(

View File

@ -78,9 +78,7 @@ class _InvitationSelectionState extends State<InvitationSelection> {
void searchUser(BuildContext context, String text) async {
coolDown?.cancel();
if (text.isEmpty) {
setState(() {
foundProfiles = [];
});
setState(() => foundProfiles = []);
}
currentSearchTerm = text;
if (currentSearchTerm.isEmpty) return;

View File

@ -486,109 +486,6 @@ class _SettingsState extends State<Settings> {
title: Text(L10n.of(context).appLock),
onTap: () => _setAppLockAction(context),
),
ListTile(
trailing: Icon(Icons.compare_arrows_outlined),
title: Text(client.encryption.crossSigning.enabled
? L10n.of(context).crossSigningEnabled
: L10n.of(context).crossSigningDisabled),
subtitle: client.encryption.crossSigning.enabled
? Text(client.isUnknownSession
? L10n.of(context).unknownSessionVerify
: L10n.of(context).sessionVerified +
', ' +
(crossSigningCached == null
? ''
: (crossSigningCached
? L10n.of(context).keysCached
: L10n.of(context).keysMissing)))
: null,
onTap: () async {
if (!client.encryption.crossSigning.enabled) {
return BootstrapDialog(l10n: L10n.of(context))
.show(context);
}
if (client.isUnknownSession) {
final input = await showTextInputDialog(
context: context,
title: L10n.of(context).askSSSSVerify,
textFields: [
DialogTextField(
hintText: L10n.of(context).passphraseOrKey,
obscureText: true,
minLines: 1,
maxLines: 1,
)
],
);
if (input != null) {
final valid = await showFutureLoadingDialog(
context: context,
future: () async {
// make sure the loading spinner shows before we test the keys
await Future.delayed(Duration(milliseconds: 100));
var valid = false;
try {
await client.encryption.crossSigning
.selfSign(recoveryKey: input.single);
valid = true;
} catch (_) {
try {
await client.encryption.crossSigning
.selfSign(passphrase: input.single);
valid = true;
} catch (_) {
valid = false;
}
}
return valid;
});
if (valid.result == true) {
await showOkAlertDialog(
context: context,
message: L10n.of(context).verifiedSession,
);
setState(() {
crossSigningCachedFuture = null;
crossSigningCached = null;
megolmBackupCachedFuture = null;
megolmBackupCached = null;
});
} else {
await showOkAlertDialog(
context: context,
message: L10n.of(context).incorrectPassphraseOrKey,
);
}
}
}
if (!(await client.encryption.crossSigning.isCached())) {
await requestSSSSCache(context);
}
},
),
ListTile(
trailing: Icon(Icons.wb_cloudy_outlined),
title: Text(client.encryption.keyManager.enabled
? L10n.of(context).onlineKeyBackupEnabled
: L10n.of(context).onlineKeyBackupDisabled),
subtitle: client.encryption.keyManager.enabled
? Text(megolmBackupCached == null
? ''
: (megolmBackupCached
? L10n.of(context).keysCached
: L10n.of(context).keysMissing))
: null,
onTap: () async {
if (!client.encryption.keyManager.enabled) {
return BootstrapDialog(l10n: L10n.of(context))
.show(context);
}
if (!(await client.encryption.keyManager.isCached())) {
await requestSSSSCache(context);
}
},
),
ListTile(
title: Text(L10n.of(context).yourPublicKey),
onTap: () => showOkAlertDialog(
@ -598,6 +495,16 @@ class _SettingsState extends State<Settings> {
),
trailing: Icon(Icons.vpn_key_outlined),
),
ListTile(
title: Text(L10n.of(context).cachedKeys),
trailing: Icon(Icons.wb_cloudy_outlined),
subtitle: Text(
'${client.encryption.keyManager.enabled ? L10n.of(context).onlineKeyBackupEnabled : L10n.of(context).onlineKeyBackupDisabled}\n${client.encryption.crossSigning.enabled ? L10n.of(context).crossSigningEnabled : L10n.of(context).crossSigningDisabled}'),
onTap: () => BootstrapDialog(
l10n: L10n.of(context),
client: Matrix.of(context).client,
).show(context),
),
},
Divider(thickness: 1),
ListTile(