feat: Show the error screen when libsecret fails
This commit is contained in:
parent
11d0e58334
commit
4930fc2387
|
@ -1,6 +1,6 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
||||||
|
@ -28,6 +28,7 @@ class HiveConfig {
|
||||||
|
|
||||||
await Hive.openBox(BNames.appSettingsBox);
|
await Hive.openBox(BNames.appSettingsBox);
|
||||||
|
|
||||||
|
try {
|
||||||
final HiveAesCipher cipher = HiveAesCipher(
|
final HiveAesCipher cipher = HiveAesCipher(
|
||||||
await getEncryptedKey(BNames.serverInstallationEncryptionKey),
|
await getEncryptedKey(BNames.serverInstallationEncryptionKey),
|
||||||
);
|
);
|
||||||
|
@ -42,12 +43,21 @@ class HiveConfig {
|
||||||
await deprecatedUsers.clear();
|
await deprecatedUsers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
await Hive.openBox(BNames.serverInstallationBox, encryptionCipher: cipher);
|
await Hive.openBox(
|
||||||
|
BNames.serverInstallationBox,
|
||||||
|
encryptionCipher: cipher,
|
||||||
|
);
|
||||||
|
} on PlatformException catch (e) {
|
||||||
|
print('HiveConfig: Error while opening boxes: $e');
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Uint8List> getEncryptedKey(final String encKey) async {
|
static Future<Uint8List> getEncryptedKey(final String encKey) async {
|
||||||
const FlutterSecureStorage secureStorage = FlutterSecureStorage();
|
const FlutterSecureStorage secureStorage = FlutterSecureStorage();
|
||||||
final bool hasEncryptionKey = await secureStorage.containsKey(key: encKey);
|
try {
|
||||||
|
final bool hasEncryptionKey =
|
||||||
|
await secureStorage.containsKey(key: encKey);
|
||||||
if (!hasEncryptionKey) {
|
if (!hasEncryptionKey) {
|
||||||
final List<int> key = Hive.generateSecureKey();
|
final List<int> key = Hive.generateSecureKey();
|
||||||
await secureStorage.write(key: encKey, value: base64UrlEncode(key));
|
await secureStorage.write(key: encKey, value: base64UrlEncode(key));
|
||||||
|
@ -55,6 +65,10 @@ class HiveConfig {
|
||||||
|
|
||||||
final String? string = await secureStorage.read(key: encKey);
|
final String? string = await secureStorage.read(key: encKey);
|
||||||
return base64Url.decode(string!);
|
return base64Url.decode(string!);
|
||||||
|
} on PlatformException catch (e) {
|
||||||
|
print('HiveConfig: Error while getting encryption key: $e');
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:selfprivacy/config/bloc_config.dart';
|
import 'package:selfprivacy/config/bloc_config.dart';
|
||||||
import 'package:selfprivacy/config/bloc_observer.dart';
|
import 'package:selfprivacy/config/bloc_observer.dart';
|
||||||
|
@ -9,13 +10,20 @@ import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/config/localization.dart';
|
import 'package:selfprivacy/config/localization.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.dart';
|
||||||
import 'package:selfprivacy/theming/factory/app_theme_factory.dart';
|
import 'package:selfprivacy/theming/factory/app_theme_factory.dart';
|
||||||
|
import 'package:selfprivacy/ui/pages/errors/failed_to_init_secure_storage.dart';
|
||||||
import 'package:selfprivacy/ui/router/router.dart';
|
import 'package:selfprivacy/ui/router/router.dart';
|
||||||
// import 'package:wakelock/wakelock.dart';
|
// import 'package:wakelock/wakelock.dart';
|
||||||
import 'package:timezone/data/latest.dart' as tz;
|
import 'package:timezone/data/latest.dart' as tz;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
try {
|
||||||
await HiveConfig.init();
|
await HiveConfig.init();
|
||||||
|
} on PlatformException catch (e) {
|
||||||
|
runApp(
|
||||||
|
FailedToInitSecureStorageScreen(e: e),
|
||||||
|
);
|
||||||
|
}
|
||||||
// await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
// await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
|
|
|
@ -127,7 +127,9 @@ class _HeroSliverAppBarState extends State<HeroSliverAppBar> {
|
||||||
Widget build(final BuildContext context) {
|
Widget build(final BuildContext context) {
|
||||||
final isMobile =
|
final isMobile =
|
||||||
widget.ignoreBreakpoints ? true : Breakpoints.small.isActive(context);
|
widget.ignoreBreakpoints ? true : Breakpoints.small.isActive(context);
|
||||||
final isJobsListEmpty = context.watch<JobsCubit>().state is JobsStateEmpty;
|
final isJobsListEmpty = widget.hasFlashButton
|
||||||
|
? context.watch<JobsCubit>().state is JobsStateEmpty
|
||||||
|
: true;
|
||||||
return SliverAppBar(
|
return SliverAppBar(
|
||||||
expandedHeight:
|
expandedHeight:
|
||||||
widget.hasHeroIcon ? 148.0 + _size.height : 72.0 + _size.height,
|
widget.hasHeroIcon ? 148.0 + _size.height : 72.0 + _size.height,
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:gap/gap.dart';
|
||||||
|
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
|
||||||
|
import 'package:selfprivacy/ui/pages/more/about_application.dart';
|
||||||
|
|
||||||
|
class FailedToInitSecureStorageScreen extends StatelessWidget {
|
||||||
|
const FailedToInitSecureStorageScreen({
|
||||||
|
required this.e,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final PlatformException e;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(final BuildContext context) => MaterialApp(
|
||||||
|
home: BrandHeroScreen(
|
||||||
|
heroIcon: Icons.error_outline,
|
||||||
|
heroTitle: 'Failed to initialize secure storage',
|
||||||
|
hasBackButton: false,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'SelfPrivacy requires a secure storage provided by your operating system to encrypt sensitive data, but it failed to initialize.',
|
||||||
|
),
|
||||||
|
if (Platform.isLinux)
|
||||||
|
const Text(
|
||||||
|
'Please make sure that the libsecret library is installed.',
|
||||||
|
),
|
||||||
|
const Gap(16),
|
||||||
|
Text('Error: ${e.message}'),
|
||||||
|
const Gap(16),
|
||||||
|
const Divider(),
|
||||||
|
const Gap(16),
|
||||||
|
const LinkListTile(
|
||||||
|
title: 'Our website',
|
||||||
|
subtitle: 'selfprivacy.org',
|
||||||
|
uri: 'https://selfprivacy.org/',
|
||||||
|
icon: Icons.language_outlined,
|
||||||
|
),
|
||||||
|
const LinkListTile(
|
||||||
|
title: 'Documentation',
|
||||||
|
subtitle: 'selfprivacy.org/docs',
|
||||||
|
uri: 'https://selfprivacy.org/docs/',
|
||||||
|
icon: Icons.library_books_outlined,
|
||||||
|
),
|
||||||
|
const LinkListTile(
|
||||||
|
title: 'Privacy Policy',
|
||||||
|
subtitle: 'selfprivacy.org/privacy-policy',
|
||||||
|
uri: 'https://selfprivacy.org/privacy-policy/',
|
||||||
|
icon: Icons.policy_outlined,
|
||||||
|
),
|
||||||
|
const LinkListTile(
|
||||||
|
title: 'Matrix support chat',
|
||||||
|
subtitle: '#chat:selfprivacy.org',
|
||||||
|
uri: 'https://matrix.to/#/#chat:selfprivacy.org',
|
||||||
|
icon: Icons.question_answer_outlined,
|
||||||
|
longPressText: '#chat:selfprivacy.org',
|
||||||
|
),
|
||||||
|
const LinkListTile(
|
||||||
|
title: 'Telegram support chat',
|
||||||
|
subtitle: '@selfprivacy_chat',
|
||||||
|
uri: 'https://t.me/selfprivacy_chat',
|
||||||
|
icon: Icons.question_answer_outlined,
|
||||||
|
longPressText: '@selfprivacy_chat',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue