fluffychat/lib/main.dart

52 lines
1.6 KiB
Dart
Raw Normal View History

2020-01-01 18:10:13 +00:00
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
2022-11-13 11:40:10 +00:00
import 'package:collection/collection.dart';
2021-01-18 07:38:19 +00:00
import 'package:flutter_app_lock/flutter_app_lock.dart';
2023-08-07 16:40:02 +00:00
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
2022-11-02 08:57:06 +00:00
import 'package:matrix/matrix.dart';
2020-01-01 18:10:13 +00:00
2021-10-26 16:50:34 +00:00
import 'package:fluffychat/utils/client_manager.dart';
import 'package:fluffychat/utils/platform_infos.dart';
2023-08-07 16:40:02 +00:00
import 'config/setting_keys.dart';
2021-02-07 16:18:38 +00:00
import 'utils/background_push.dart';
2022-08-25 16:31:30 +00:00
import 'widgets/fluffy_chat_app.dart';
2021-10-26 16:50:34 +00:00
import 'widgets/lock_screen.dart';
2020-09-08 08:55:32 +00:00
2020-12-11 13:14:33 +00:00
void main() async {
2023-08-07 16:40:02 +00:00
Logs().i('Welcome to FluffyChat');
2021-02-07 16:18:38 +00:00
// Our background push shared isolate accesses flutter-internal things very early in the startup proccess
// To make sure that the parts of flutter needed are started up already, we need to ensure that the
// widget bindings are initialized already.
WidgetsFlutterBinding.ensureInitialized();
2022-11-02 08:57:06 +00:00
Logs().nativeColors = !PlatformInfos.isIOS;
final clients = await ClientManager.getClients();
2022-11-13 11:40:10 +00:00
// Preload first client
final firstClient = clients.firstOrNull;
await firstClient?.roomsLoading;
await firstClient?.accountDataLoading;
2023-08-07 16:40:02 +00:00
String? pin;
2021-02-07 16:18:38 +00:00
if (PlatformInfos.isMobile) {
BackgroundPush.clientOnly(clients.first);
2023-08-07 16:40:02 +00:00
try {
pin =
await const FlutterSecureStorage().read(key: SettingKeys.appLockKey);
} catch (e, s) {
Logs().d('Unable to read PIN from Secure storage', e, s);
}
2021-07-08 16:42:46 +00:00
}
runApp(
PlatformInfos.isMobile
2021-01-18 07:38:19 +00:00
? AppLock(
2023-08-07 16:40:02 +00:00
builder: (args) => FluffyChatApp(clients: clients),
2021-10-14 16:09:30 +00:00
lockScreen: const LockScreen(),
2023-08-07 16:40:02 +00:00
enabled: pin?.isNotEmpty ?? false,
2021-01-18 07:38:19 +00:00
)
2023-08-07 16:40:02 +00:00
: FluffyChatApp(clients: clients),
2020-09-08 08:55:32 +00:00
);
2020-01-02 21:31:39 +00:00
}