Skip to content

Commit

Permalink
chore: Follow up fix app lock
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Sep 30, 2023
1 parent 5213b18 commit 73d1b7e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
15 changes: 14 additions & 1 deletion lib/widgets/app_lock.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';

import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:matrix/matrix.dart';
import 'package:provider/provider.dart';

import 'package:fluffychat/config/setting_keys.dart';
Expand All @@ -11,9 +12,11 @@ class AppLockWidget extends StatefulWidget {
const AppLockWidget({
required this.child,
required this.pincode,
required this.clients,
super.key,
});

final List<Client> clients;
final String? pincode;
final Widget child;

Expand All @@ -35,6 +38,16 @@ class AppLock extends State<AppLockWidget> with WidgetsBindingObserver {
_isLocked = isActive;
super.initState();
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance.addPostFrameCallback(_checkLoggedIn);
}

void _checkLoggedIn(_) async {
if (widget.clients.any((client) => client.isLogged())) return;

await changePincode(null);
setState(() {
_isLocked = false;
});
}

@override
Expand All @@ -60,7 +73,7 @@ class AppLock extends State<AppLockWidget> with WidgetsBindingObserver {
return;
}

bool unlock(String? pincode) {
bool unlock(String pincode) {
final isCorrect = pincode == _pincode;
if (isCorrect) {
setState(() {
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/fluffy_chat_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FluffyChatApp extends StatelessWidget {
routerConfig: router,
builder: (context, child) => AppLockWidget(
pincode: pincode,
clients: clients,
child: Matrix(
clients: clients,
child: testWidget ?? child,
Expand Down
15 changes: 0 additions & 15 deletions lib/widgets/lock_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/widgets/app_lock.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/theme_builder.dart';

class LockScreen extends StatefulWidget {
Expand All @@ -23,20 +22,6 @@ class _LockScreenState extends State<LockScreen> {
bool _inputBlocked = false;
final TextEditingController _textEditingController = TextEditingController();

@override
void initState() {
super.initState();
_checkLoggedIn();
}

void _checkLoggedIn() async {
if (Matrix.of(context).client.isLogged()) return;

final appLock = AppLock.of(context);
await appLock.changePincode(null);
appLock.unlock(null);
}

void tryUnlock(BuildContext context) async {
setState(() {
_errorText = null;
Expand Down

0 comments on commit 73d1b7e

Please sign in to comment.