mirror of
https://github.com/mitchell/selfpass.git
synced 2025-12-15 21:47:23 +00:00
Add automatic background lock to home screen; refactor repo names
This commit is contained in:
parent
27215e6596
commit
474f0c056b
10 changed files with 74 additions and 44 deletions
|
|
@ -22,7 +22,7 @@ class _AuthenticationState extends State<Authentication> {
|
|||
didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_config = Provider.of<ConfigRepo>(context);
|
||||
_passwordIsSet = _config.passwordSet;
|
||||
_passwordIsSet = _config.passwordIsSet;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
|
@ -8,32 +10,56 @@ import '../types/screen_arguments.dart';
|
|||
import '../widgets/tappable_text_list.dart';
|
||||
|
||||
class Home extends StatefulWidget {
|
||||
const Home({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State createState() => _HomeState();
|
||||
}
|
||||
|
||||
class _HomeState extends State<Home> {
|
||||
class _HomeState extends State<Home> with WidgetsBindingObserver {
|
||||
CredentialsRepo _client;
|
||||
ConfigRepo _config;
|
||||
Future<List<Metadata>> _metadatas;
|
||||
bool _stateIsPaused = false;
|
||||
Timer _pausedStateTimer;
|
||||
|
||||
@override
|
||||
didChangeDependencies() {
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
_config = Provider.of<ConfigRepo>(context);
|
||||
|
||||
_client = Provider.of<CredentialsRepo>(context);
|
||||
|
||||
_metadatas = _client.getAllMetadata('').toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
_stateIsPaused = state == AppLifecycleState.paused;
|
||||
|
||||
if (_stateIsPaused) {
|
||||
_pausedStateTimer = _newPausedStateTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_pausedStateTimer != null) _pausedStateTimer.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
child: FutureBuilder<List<Metadata>>(
|
||||
future: _metadatas,
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<List<Metadata>> snapshot) =>
|
||||
builder: (
|
||||
BuildContext context,
|
||||
AsyncSnapshot<List<Metadata>> snapshot,
|
||||
) =>
|
||||
(snapshot.connectionState == ConnectionState.done)
|
||||
? TappableTextList(
|
||||
tappableText: _buildTappableText(context, snapshot.data))
|
||||
|
|
@ -55,6 +81,22 @@ class _HomeState extends State<Home> {
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
if (_pausedStateTimer != null) _pausedStateTimer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Timer _newPausedStateTimer() {
|
||||
const checkPeriod = 30;
|
||||
|
||||
return Timer(Duration(seconds: checkPeriod), () {
|
||||
Navigator.of(context)
|
||||
.pushNamedAndRemoveUntil('/', ModalRoute.withName('/home'));
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, GestureTapCallback> _buildTappableText(
|
||||
BuildContext context,
|
||||
List<Metadata> metadatas,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue