Merge branch 'krille/applock' into 'main'
feat: Implement app lock Closes #223 See merge request famedly/fluffychat!343
This commit is contained in:
commit
691db4187b
8 changed files with 129 additions and 7 deletions
|
|
@ -9,10 +9,6 @@ class LoadingView extends StatelessWidget {
|
|||
WidgetsBinding.instance.addPostFrameCallback((_) =>
|
||||
AdaptivePageLayout.of(context).pushNamedAndRemoveAllOthers('/'));
|
||||
}
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
return Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
35
lib/views/lock_screen.dart
Normal file
35
lib/views/lock_screen.dart
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_app_lock/flutter_app_lock.dart';
|
||||
import 'package:flutter_screen_lock/lock_screen.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class LockScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<String>(
|
||||
future: FlutterSecureStorage().read(key: SettingKeys.appLockKey),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Scaffold(body: Center(child: Text(snapshot.error.toString())));
|
||||
}
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (snapshot.data?.isNotEmpty ?? false) {
|
||||
showLockScreen(
|
||||
context: context,
|
||||
correctString: snapshot.data,
|
||||
onUnlocked: () => AppLock.of(context).didUnlock(),
|
||||
canBiometric: true,
|
||||
canCancel: false,
|
||||
);
|
||||
} else {
|
||||
AppLock.of(context).didUnlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
return Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,8 @@ import 'package:fluffychat/utils/platform_infos.dart';
|
|||
import 'package:fluffychat/utils/sentry_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_screen_lock/lock_screen.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
|
|
@ -254,6 +256,44 @@ class _SettingsState extends State<Settings> {
|
|||
}
|
||||
}
|
||||
|
||||
void _setAppLockAction(BuildContext context) async {
|
||||
final currentLock =
|
||||
await FlutterSecureStorage().read(key: SettingKeys.appLockKey);
|
||||
if (currentLock?.isNotEmpty ?? false) {
|
||||
var unlocked = false;
|
||||
await showLockScreen(
|
||||
context: context,
|
||||
correctString: currentLock,
|
||||
onUnlocked: () => unlocked = true,
|
||||
canBiometric: true,
|
||||
);
|
||||
if (unlocked != true) return;
|
||||
}
|
||||
final newLock = await showTextInputDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).pleaseChooseAPasscode,
|
||||
message: L10n.of(context).pleaseEnter4Digits,
|
||||
textFields: [
|
||||
DialogTextField(
|
||||
validator: (text) {
|
||||
if (text.length != 4 && text.isNotEmpty) {
|
||||
return L10n.of(context).pleaseEnter4Digits;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
keyboardType: TextInputType.number,
|
||||
obscureText: true,
|
||||
maxLines: 1,
|
||||
minLines: 1,
|
||||
)
|
||||
],
|
||||
);
|
||||
if (newLock != null) {
|
||||
await FlutterSecureStorage()
|
||||
.write(key: SettingKeys.appLockKey, value: newLock.first);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final client = Matrix.of(context).client;
|
||||
|
|
@ -439,13 +479,19 @@ class _SettingsState extends State<Settings> {
|
|||
Divider(thickness: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context).encryption,
|
||||
L10n.of(context).security,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (PlatformInfos.isMobile)
|
||||
ListTile(
|
||||
trailing: Icon(Icons.lock_outlined),
|
||||
title: Text(L10n.of(context).appLock),
|
||||
onTap: () => _setAppLockAction(context),
|
||||
),
|
||||
ListTile(
|
||||
trailing: Icon(Icons.compare_arrows_outlined),
|
||||
title: Text(client.encryption.crossSigning.enabled
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue