mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-23 18:44:10 +01:00
chore: Simplify bootstrap
This commit is contained in:
parent
3f14d5ed07
commit
2df4a78c7d
@ -1,6 +1,7 @@
|
|||||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
import 'package:famedlysdk/encryption.dart';
|
import 'package:famedlysdk/encryption.dart';
|
||||||
import 'package:famedlysdk/encryption/utils/bootstrap.dart';
|
import 'package:famedlysdk/encryption/utils/bootstrap.dart';
|
||||||
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:fluffychat/components/dialogs/adaptive_flat_button.dart';
|
import 'package:fluffychat/components/dialogs/adaptive_flat_button.dart';
|
||||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.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/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
import '../matrix.dart';
|
|
||||||
|
|
||||||
class BootstrapDialog extends StatefulWidget {
|
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
|
Future<bool> show(BuildContext context) => PlatformInfos.isCupertinoStyle
|
||||||
? showCupertinoDialog(context: context, builder: (context) => this)
|
? showCupertinoDialog(context: context, builder: (context) => this)
|
||||||
: showDialog(context: context, builder: (context) => this);
|
: showDialog(context: context, builder: (context) => this);
|
||||||
|
|
||||||
final L10n l10n;
|
final L10n l10n;
|
||||||
|
final Client client;
|
||||||
|
final bool easyMode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_BootstrapDialogState createState() => _BootstrapDialogState();
|
_BootstrapDialogState createState() => _BootstrapDialogState();
|
||||||
@ -28,17 +34,17 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
bootstrap ??= Matrix.of(context)
|
bootstrap ??= widget.client.encryption
|
||||||
.client
|
|
||||||
.encryption
|
|
||||||
.bootstrap(onUpdate: () => setState(() => null));
|
.bootstrap(onUpdate: () => setState(() => null));
|
||||||
|
|
||||||
final buttons = <AdaptiveFlatButton>[];
|
final buttons = <AdaptiveFlatButton>[];
|
||||||
Widget body;
|
Widget body;
|
||||||
|
var titleText = widget.l10n.cachedKeys;
|
||||||
|
|
||||||
switch (bootstrap.state) {
|
switch (bootstrap.state) {
|
||||||
case BootstrapState.loading:
|
case BootstrapState.loading:
|
||||||
body = LinearProgressIndicator();
|
body = LinearProgressIndicator();
|
||||||
|
titleText = widget.l10n.loadingPleaseWait;
|
||||||
break;
|
break;
|
||||||
case BootstrapState.askWipeSsss:
|
case BootstrapState.askWipeSsss:
|
||||||
body = Text('Wipe chat backup?');
|
body = Text('Wipe chat backup?');
|
||||||
@ -208,7 +214,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
final title = Text('Chat backup');
|
final title = Text(titleText);
|
||||||
if (PlatformInfos.isCupertinoStyle) {
|
if (PlatformInfos.isCupertinoStyle) {
|
||||||
return CupertinoAlertDialog(
|
return CupertinoAlertDialog(
|
||||||
title: title,
|
title: title,
|
||||||
|
@ -139,13 +139,18 @@ class MatrixState extends State<Matrix> {
|
|||||||
final stage = uiaRequest.nextStages.first;
|
final stage = uiaRequest.nextStages.first;
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
case AuthenticationTypes.password:
|
case AuthenticationTypes.password:
|
||||||
final input = await showTextInputDialog(context: context, textFields: [
|
final input = await showTextInputDialog(
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).pleaseEnterYourPassword,
|
||||||
|
textFields: [
|
||||||
DialogTextField(
|
DialogTextField(
|
||||||
minLines: 1,
|
minLines: 1,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
|
hintText: '******',
|
||||||
)
|
)
|
||||||
]);
|
],
|
||||||
|
);
|
||||||
if (input?.isEmpty ?? true) return;
|
if (input?.isEmpty ?? true) return;
|
||||||
return uiaRequest.completeStage(
|
return uiaRequest.completeStage(
|
||||||
AuthenticationPassword(
|
AuthenticationPassword(
|
||||||
|
@ -78,9 +78,7 @@ class _InvitationSelectionState extends State<InvitationSelection> {
|
|||||||
void searchUser(BuildContext context, String text) async {
|
void searchUser(BuildContext context, String text) async {
|
||||||
coolDown?.cancel();
|
coolDown?.cancel();
|
||||||
if (text.isEmpty) {
|
if (text.isEmpty) {
|
||||||
setState(() {
|
setState(() => foundProfiles = []);
|
||||||
foundProfiles = [];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
currentSearchTerm = text;
|
currentSearchTerm = text;
|
||||||
if (currentSearchTerm.isEmpty) return;
|
if (currentSearchTerm.isEmpty) return;
|
||||||
|
@ -486,109 +486,6 @@ class _SettingsState extends State<Settings> {
|
|||||||
title: Text(L10n.of(context).appLock),
|
title: Text(L10n.of(context).appLock),
|
||||||
onTap: () => _setAppLockAction(context),
|
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(
|
ListTile(
|
||||||
title: Text(L10n.of(context).yourPublicKey),
|
title: Text(L10n.of(context).yourPublicKey),
|
||||||
onTap: () => showOkAlertDialog(
|
onTap: () => showOkAlertDialog(
|
||||||
@ -598,6 +495,16 @@ class _SettingsState extends State<Settings> {
|
|||||||
),
|
),
|
||||||
trailing: Icon(Icons.vpn_key_outlined),
|
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),
|
Divider(thickness: 1),
|
||||||
ListTile(
|
ListTile(
|
||||||
|
Loading…
Reference in New Issue
Block a user