Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dreautall committed May 29, 2023
2 parents 6f15808 + 8c88210 commit 0f9a932
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 9 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Expand Up @@ -19,6 +19,7 @@
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>

<!-- Queries, used by url_launcher -->
<queries>
Expand Down
@@ -1,6 +1,6 @@
package com.dreautall.waterflyiii

import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterActivity() {
class MainActivity: FlutterFragmentActivity() {
}
34 changes: 31 additions & 3 deletions lib/app.dart
@@ -1,12 +1,14 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show SystemChannels;
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart';

import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:local_auth/local_auth.dart';

import 'package:waterflyiii/auth.dart';
import 'package:waterflyiii/notificationlistener.dart';
Expand Down Expand Up @@ -84,11 +86,37 @@ class _WaterflyAppState extends State<WaterflyApp> {
} else {
log.finer(() => "Load Step 2: Signin In");
context.read<FireflyService>().signInFromStorage().then(
(_) => setState(() {
(bool success) async {
if (!success || !context.read<SettingsProvider>().lock) {
setState(() {
log.finest(() => "set _startup = false");
_startup = false;
}),
);
});
} else {
// Authentication required
log.fine("awaiting authentication");
final LocalAuthentication auth = LocalAuthentication();
final bool authed = await auth.authenticate(
localizedReason: "Waterfly III",
options: const AuthenticationOptions(
useErrorDialogs: false,
stickyAuth: true,
),
);
log.finest("done authing, $authed");
if (authed) {
setState(() {
log.finest(() => "authentication succeeded");
_startup = false;
});
} else {
log.shout(() => "authentication failed");
// close app
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
}
}
},
);
}
} else {
signedIn = context.select((FireflyService f) => f.signedIn);
Expand Down
3 changes: 1 addition & 2 deletions lib/auth.dart
Expand Up @@ -195,8 +195,7 @@ class FireflyService with ChangeNotifier {
}

try {
final bool success = await signIn(apiHost, apiKey, cert);
return success;
return await signIn(apiHost, apiKey, cert);
} catch (e) {
_storageSignInException = e;
log.finest(() => "notify FireflyService->signInFromStorage");
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_de.arb
Expand Up @@ -93,6 +93,9 @@
"settingsDialogLanguageTitle": "Sprache auswählen",
"settingsDialogThemeTitle": "Erscheinungsbild auswählen",
"settingsLanguage": "Sprache",
"settingsLockscreen": "App-Sperre",
"settingsLockscreenHelp": "Authentifizierung beim Start der App erwzingen.",
"settingsLockscreenInitial": "Bitte authentifiziere dich, um die App-Sperre zu aktivieren.",
"settingsNLAppAccount": "Standard-Konto",
"settingsNLAppAccountDynamic": "<Dynamisch>",
"settingsNLAppAdd": "App hinzufügen",
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_en.arb
Expand Up @@ -489,6 +489,9 @@
"@settingsLanguage": {
"description": "Currently selected language"
},
"settingsLockscreen": "Lockscreen",
"settingsLockscreenHelp": "Require authenticiation on app startup",
"settingsLockscreenInitial": "Please authenticate to enable the lock screen.",
"settingsNLAppAccount": "Default Account",
"@settingsNLAppAccount": {
"description": "Default account which will be used for the transaction."
Expand Down
36 changes: 36 additions & 0 deletions lib/pages/settings.dart
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';

import 'package:local_auth/local_auth.dart';
import 'package:package_info_plus/package_info_plus.dart';

import 'package:waterflyiii/notificationlistener.dart';
Expand Down Expand Up @@ -79,6 +80,41 @@ class SettingsPageState extends State<SettingsPage>
},
),
const Divider(),
SwitchListTile(
title: Text(S.of(context).settingsLockscreen),
subtitle: Text(S.of(context).settingsLockscreenHelp),
value: context.select((SettingsProvider s) => s.lock),
secondary: CircleAvatar(
child: Icon(
context.select((SettingsProvider s) => s.lock)
? Icons.lock
: Icons.lock_outline,
),
),
onChanged: (bool value) async {
final S l10n = S.of(context);
if (value == true) {
final LocalAuthentication auth = LocalAuthentication();
final bool canAuth = await auth.isDeviceSupported() ||
await auth.canCheckBiometrics;
if (!canAuth) {
log.warning("no auth method supported");
return;
}
log.finest("trying authentication");
final bool authed = await auth.authenticate(
localizedReason:
l10n.settingsLockscreenInitial, // :TODO: translate
);
if (!authed) {
log.warning("authentication was cancelled");
return;
}
}
settings.setLock(value);
},
),
const Divider(),
FutureBuilder<NotificationListenerStatus>(
future: nlStatus(),
builder: (BuildContext context,
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/settings/debug.dart
Expand Up @@ -25,14 +25,14 @@ class DebugDialog extends StatelessWidget {
child: Text(S.of(context).settingsDialogDebugInfo),
),
SwitchListTile(
value: context.watch<SettingsProvider>().debug,
value: context.select((SettingsProvider s) => s.debug),
onChanged: (bool value) =>
context.read<SettingsProvider>().setDebug(value),
title: Text(S.of(context).settingsDialogDebugTitle),
secondary: const Icon(Icons.bug_report),
),
ListTile(
enabled: context.watch<SettingsProvider>().debug,
enabled: context.select((SettingsProvider s) => s.debug),
isThreeLine: false,
leading: const Icon(Icons.send),
title: Text(S.of(context).settingsDialogDebugSendButton),
Expand Down
20 changes: 20 additions & 0 deletions lib/settings.dart
Expand Up @@ -35,6 +35,7 @@ class NotificationAppSettings {
class SettingsProvider with ChangeNotifier {
static const String settingDebug = "DEBUG";
static const String settingLocale = "LOCALE";
static const String settingLock = "LOCK";
static const String settingNLKnownApps = "NL_KNOWNAPPS";
static const String settingNLUsedApps = "NL_USEDAPPS";
static const String settingNLAppPrefix = "NL_APP_";
Expand All @@ -53,6 +54,9 @@ class SettingsProvider with ChangeNotifier {
bool get debug => _debug;
StreamSubscription<LogRecord>? _debugLogger;

bool _lock = false;
bool get lock => _lock;

bool _loaded = false;
bool get loaded => _loaded;

Expand Down Expand Up @@ -96,6 +100,9 @@ class SettingsProvider with ChangeNotifier {
Logger.root.level = kDebugMode ? Level.ALL : Level.INFO;
}

_lock = prefs.getBool(settingLock) ?? false;
log.config("read lock $lock");

_notificationApps = prefs.getStringList(settingNLUsedApps) ?? <String>[];

_loaded = true;
Expand Down Expand Up @@ -159,6 +166,19 @@ class SettingsProvider with ChangeNotifier {
notifyListeners();
}

Future<void> setLock(bool lock) async {
if (lock == _lock) {
return;
}

SharedPreferences prefs = await SharedPreferences.getInstance();
_lock = lock;
await prefs.setBool(settingLock, lock);

log.finest(() => "notify SettingsProvider->setLock()");
notifyListeners();
}

Future<bool> notificationAddKnownApp(String packageName) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final List<String> apps =
Expand Down
40 changes: 40 additions & 0 deletions pubspec.lock
Expand Up @@ -544,6 +544,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
local_auth:
dependency: "direct main"
description:
name: local_auth
sha256: "0cf238be2bfa51a6c9e7e9cfc11c05ea39f2a3a4d3e5bb255d0ebc917da24401"
url: "https://pub.dev"
source: hosted
version: "2.1.6"
local_auth_android:
dependency: transitive
description:
name: local_auth_android
sha256: c5e48c4a67fc0e5dd9b5725cc8766b67e2da9a54155c82c6e2ea4a0d1cf9ef93
url: "https://pub.dev"
source: hosted
version: "1.0.28"
local_auth_ios:
dependency: transitive
description:
name: local_auth_ios
sha256: edc2977c5145492f3451db9507a2f2f284ee4f408950b3e16670838726761940
url: "https://pub.dev"
source: hosted
version: "1.1.3"
local_auth_platform_interface:
dependency: transitive
description:
name: local_auth_platform_interface
sha256: "9e160d59ef0743e35f1b50f4fb84dc64f55676b1b8071e319ef35e7f3bc13367"
url: "https://pub.dev"
source: hosted
version: "1.0.7"
local_auth_windows:
dependency: transitive
description:
name: local_auth_windows
sha256: "19323b75ab781d5362dbb15dcb7e0916d2431c7a6dbdda016ec9708689877f73"
url: "https://pub.dev"
source: hosted
version: "1.0.8"
logging:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Expand Up @@ -38,6 +38,7 @@ dependencies:
package_info_plus: ^4.0.0
logging: ^1.1.1
flutter_email_sender: ^5.2.0
local_auth: ^2.1.6

dev_dependencies:
flutter_lints: ^2.0.0
Expand Down

0 comments on commit 0f9a932

Please sign in to comment.