2020-01-03 17:23:40 +01:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
2020-12-18 11:43:13 +01:00
|
|
|
import 'dart:convert';
|
2020-02-16 15:57:50 +01:00
|
|
|
|
2020-11-14 10:08:13 +01:00
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/encryption.dart';
|
|
|
|
import 'package:matrix/matrix.dart';
|
2021-05-22 09:24:39 +02:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart';
|
2020-09-26 20:27:15 +02:00
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
2020-10-28 10:56:24 +01:00
|
|
|
import 'package:fluffychat/utils/sentry_controller.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2021-01-18 17:31:27 +01:00
|
|
|
import 'package:flutter_app_lock/flutter_app_lock.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-01-18 17:31:27 +01:00
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
2021-01-15 19:59:30 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2021-04-21 14:19:54 +02:00
|
|
|
import 'package:universal_html/html.dart' as html;
|
2020-12-18 11:43:13 +01:00
|
|
|
import 'package:http/http.dart' as http;
|
2021-02-01 11:47:33 +01:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2021-05-01 11:52:47 +02:00
|
|
|
import 'package:desktop_notifications/desktop_notifications.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import '../utils/famedlysdk_store.dart';
|
2021-05-22 08:57:49 +02:00
|
|
|
import '../pages/key_verification_dialog.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import '../utils/platform_infos.dart';
|
|
|
|
import '../config/app_config.dart';
|
|
|
|
import '../config/setting_keys.dart';
|
|
|
|
import '../utils/background_push.dart';
|
2021-05-23 13:11:55 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
2020-02-16 15:57:50 +01:00
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
class Matrix extends StatefulWidget {
|
2020-04-08 17:43:07 +02:00
|
|
|
static const String callNamespace = 'chat.fluffy.jitsi_call';
|
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
final Widget child;
|
|
|
|
|
2021-05-23 13:11:55 +02:00
|
|
|
final GlobalKey<VRouterState> router;
|
2021-01-16 12:46:38 +01:00
|
|
|
|
|
|
|
final BuildContext context;
|
|
|
|
|
2021-06-23 15:35:23 +02:00
|
|
|
final Client client;
|
2021-04-12 17:31:53 +02:00
|
|
|
|
2021-07-08 18:42:46 +02:00
|
|
|
final Map<String, String> queryParameters;
|
|
|
|
|
2021-01-16 12:46:38 +01:00
|
|
|
Matrix({
|
|
|
|
this.child,
|
2021-05-23 13:11:55 +02:00
|
|
|
@required this.router,
|
2021-01-16 12:46:38 +01:00
|
|
|
@required this.context,
|
2021-06-23 15:35:23 +02:00
|
|
|
@required this.client,
|
2021-07-08 18:42:46 +02:00
|
|
|
this.queryParameters,
|
2021-01-16 12:46:38 +01:00
|
|
|
Key key,
|
|
|
|
}) : super(key: key);
|
2020-01-01 19:10:13 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
MatrixState createState() => MatrixState();
|
|
|
|
|
|
|
|
/// Returns the (nearest) Client instance of your application.
|
2021-01-15 19:59:30 +01:00
|
|
|
static MatrixState of(BuildContext context) =>
|
|
|
|
Provider.of<MatrixState>(context, listen: false);
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 17:18:38 +01:00
|
|
|
class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
2021-06-23 15:35:23 +02:00
|
|
|
Client get client => widget.client;
|
2020-12-11 14:14:33 +01:00
|
|
|
Store store = Store();
|
2021-05-23 13:28:55 +02:00
|
|
|
BuildContext navigatorContext;
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2021-02-07 17:18:38 +01:00
|
|
|
BackgroundPush _backgroundPush;
|
|
|
|
|
2020-04-09 09:51:52 +02:00
|
|
|
Map<String, dynamic> get shareContent => _shareContent;
|
|
|
|
set shareContent(Map<String, dynamic> content) {
|
|
|
|
_shareContent = content;
|
|
|
|
onShareContentChanged.add(_shareContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> _shareContent;
|
|
|
|
|
|
|
|
final StreamController<Map<String, dynamic>> onShareContentChanged =
|
|
|
|
StreamController.broadcast();
|
2020-01-08 14:19:15 +01:00
|
|
|
|
2020-04-03 20:24:25 +02:00
|
|
|
File wallpaper;
|
2020-01-01 19:10:13 +01:00
|
|
|
|
2021-03-12 09:30:10 +01:00
|
|
|
void _initWithStore() async {
|
2020-10-04 11:52:06 +02:00
|
|
|
try {
|
2021-06-23 15:35:23 +02:00
|
|
|
await client.init();
|
2021-03-12 09:30:10 +01:00
|
|
|
if (client.isLogged()) {
|
|
|
|
final statusMsg = await store.getItem(SettingKeys.ownStatusMessage);
|
|
|
|
if (statusMsg?.isNotEmpty ?? false) {
|
|
|
|
Logs().v('Send cached status message: "$statusMsg"');
|
2021-05-20 13:59:55 +02:00
|
|
|
await client.setPresence(
|
2021-03-12 09:30:10 +01:00
|
|
|
client.userID,
|
|
|
|
PresenceType.online,
|
|
|
|
statusMsg: statusMsg,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 11:52:06 +02:00
|
|
|
} catch (e, s) {
|
|
|
|
client.onLoginStateChanged.sink.addError(e, s);
|
2020-10-28 10:56:24 +01:00
|
|
|
SentryController.captureException(e, s);
|
2020-10-04 12:32:29 +02:00
|
|
|
rethrow;
|
2020-01-08 14:19:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 08:27:08 +01:00
|
|
|
StreamSubscription onRoomKeyRequestSub;
|
2020-06-25 16:29:06 +02:00
|
|
|
StreamSubscription onKeyVerificationRequestSub;
|
2020-04-08 17:43:07 +02:00
|
|
|
StreamSubscription onJitsiCallSub;
|
2020-06-27 10:15:37 +02:00
|
|
|
StreamSubscription onNotification;
|
2021-01-16 12:46:38 +01:00
|
|
|
StreamSubscription<LoginState> onLoginStateChanged;
|
2020-12-10 15:06:02 +01:00
|
|
|
StreamSubscription<UiaRequest> onUiaRequest;
|
2020-08-22 15:20:07 +02:00
|
|
|
StreamSubscription<html.Event> onFocusSub;
|
|
|
|
StreamSubscription<html.Event> onBlurSub;
|
2021-02-27 14:25:55 +01:00
|
|
|
StreamSubscription<Presence> onOwnPresence;
|
2020-04-08 17:43:07 +02:00
|
|
|
|
2021-02-27 09:10:08 +01:00
|
|
|
String _cachedPassword;
|
|
|
|
String get cachedPassword {
|
|
|
|
final tmp = _cachedPassword;
|
|
|
|
_cachedPassword = null;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
set cachedPassword(String p) => _cachedPassword = p;
|
|
|
|
|
2021-05-13 12:18:50 +02:00
|
|
|
String currentClientSecret;
|
|
|
|
RequestTokenResponse currentThreepidCreds;
|
|
|
|
|
2020-12-10 15:06:02 +01:00
|
|
|
void _onUiaRequest(UiaRequest uiaRequest) async {
|
2021-05-13 12:18:50 +02:00
|
|
|
try {
|
|
|
|
if (uiaRequest.state != UiaRequestState.waitForUser ||
|
|
|
|
uiaRequest.nextStages.isEmpty) return;
|
|
|
|
final stage = uiaRequest.nextStages.first;
|
|
|
|
switch (stage) {
|
|
|
|
case AuthenticationTypes.password:
|
|
|
|
final input = cachedPassword ??
|
|
|
|
(await showTextInputDialog(
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-05-23 13:28:55 +02:00
|
|
|
context: navigatorContext,
|
|
|
|
title: L10n.of(widget.context).pleaseEnterYourPassword,
|
|
|
|
okLabel: L10n.of(widget.context).ok,
|
|
|
|
cancelLabel: L10n.of(widget.context).cancel,
|
2021-05-13 12:18:50 +02:00
|
|
|
textFields: [
|
|
|
|
DialogTextField(
|
|
|
|
minLines: 1,
|
|
|
|
maxLines: 1,
|
|
|
|
obscureText: true,
|
|
|
|
hintText: '******',
|
|
|
|
)
|
|
|
|
],
|
|
|
|
))
|
|
|
|
?.single;
|
|
|
|
if (input?.isEmpty ?? true) return;
|
|
|
|
return uiaRequest.completeStage(
|
|
|
|
AuthenticationPassword(
|
|
|
|
session: uiaRequest.session,
|
|
|
|
password: input,
|
|
|
|
identifier: AuthenticationUserIdentifier(user: client.userID),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
case AuthenticationTypes.emailIdentity:
|
|
|
|
if (currentClientSecret == null || currentThreepidCreds == null) {
|
|
|
|
return uiaRequest
|
|
|
|
.cancel(Exception('This server requires an email address'));
|
|
|
|
}
|
|
|
|
final auth = AuthenticationThreePidCreds(
|
2020-12-11 10:27:38 +01:00
|
|
|
session: uiaRequest.session,
|
2021-05-13 12:18:50 +02:00
|
|
|
type: AuthenticationTypes.emailIdentity,
|
|
|
|
threepidCreds: [
|
|
|
|
ThreepidCreds(
|
|
|
|
sid: currentThreepidCreds.sid,
|
|
|
|
clientSecret: currentClientSecret,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
currentThreepidCreds = currentClientSecret = null;
|
|
|
|
return uiaRequest.completeStage(auth);
|
|
|
|
case AuthenticationTypes.dummy:
|
2021-02-01 11:47:33 +01:00
|
|
|
return uiaRequest.completeStage(
|
2021-05-13 12:18:50 +02:00
|
|
|
AuthenticationData(
|
|
|
|
type: AuthenticationTypes.dummy,
|
|
|
|
session: uiaRequest.session,
|
|
|
|
),
|
2021-02-01 11:47:33 +01:00
|
|
|
);
|
2021-05-13 12:18:50 +02:00
|
|
|
default:
|
|
|
|
await launch(
|
|
|
|
client.homeserver.toString() +
|
|
|
|
'/_matrix/client/r0/auth/$stage/fallback/web?session=${uiaRequest.session}',
|
|
|
|
);
|
|
|
|
if (OkCancelResult.ok ==
|
|
|
|
await showOkCancelAlertDialog(
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-05-23 13:28:55 +02:00
|
|
|
message: L10n.of(widget.context).pleaseFollowInstructionsOnWeb,
|
|
|
|
context: navigatorContext,
|
|
|
|
okLabel: L10n.of(widget.context).next,
|
|
|
|
cancelLabel: L10n.of(widget.context).cancel,
|
2021-05-13 12:18:50 +02:00
|
|
|
)) {
|
|
|
|
return uiaRequest.completeStage(
|
2021-08-18 17:24:59 +02:00
|
|
|
AuthenticationData(
|
|
|
|
session: uiaRequest.session,
|
|
|
|
type: AuthenticationTypes.token,
|
|
|
|
),
|
2021-05-13 12:18:50 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return uiaRequest.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e, s) {
|
|
|
|
Logs().e('Error while background UIA', e, s);
|
|
|
|
return uiaRequest.cancel(e);
|
2020-12-10 15:06:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-22 15:20:07 +02:00
|
|
|
bool webHasFocus = true;
|
|
|
|
|
2021-06-06 10:00:52 +02:00
|
|
|
String get activeRoomId =>
|
|
|
|
VRouter.of(navigatorContext).pathParameters['roomid'];
|
|
|
|
|
2020-10-17 09:29:27 +02:00
|
|
|
void _showLocalNotification(EventUpdate eventUpdate) async {
|
|
|
|
final roomId = eventUpdate.roomID;
|
2021-06-06 10:00:52 +02:00
|
|
|
if (webHasFocus && activeRoomId == roomId) return;
|
2020-10-17 09:29:27 +02:00
|
|
|
final room = client.getRoomById(roomId);
|
2020-06-27 11:08:05 +02:00
|
|
|
if (room.notificationCount == 0) return;
|
2020-06-27 10:15:37 +02:00
|
|
|
final event = Event.fromJson(eventUpdate.content, room);
|
2021-05-23 13:28:55 +02:00
|
|
|
final title =
|
|
|
|
room.getLocalizedDisplayname(MatrixLocals(L10n.of(widget.context)));
|
2020-06-27 10:15:37 +02:00
|
|
|
final body = event.getLocalizedBody(
|
2021-05-23 13:28:55 +02:00
|
|
|
MatrixLocals(L10n.of(widget.context)),
|
2020-06-27 10:15:37 +02:00
|
|
|
withSenderNamePrefix:
|
|
|
|
!room.isDirectChat || room.lastEvent.senderId == client.userID,
|
|
|
|
);
|
2020-10-17 09:29:27 +02:00
|
|
|
final icon = event.sender.avatarUrl?.getThumbnail(client,
|
|
|
|
width: 64, height: 64, method: ThumbnailMethod.crop) ??
|
|
|
|
room.avatar?.getThumbnail(client,
|
|
|
|
width: 64, height: 64, method: ThumbnailMethod.crop);
|
|
|
|
if (kIsWeb) {
|
|
|
|
html.AudioElement()
|
|
|
|
..src = 'assets/assets/sounds/notification.wav'
|
|
|
|
..autoplay = true
|
|
|
|
..load();
|
|
|
|
html.Notification(
|
2021-05-01 11:52:47 +02:00
|
|
|
title,
|
2020-10-17 09:29:27 +02:00
|
|
|
body: body,
|
2021-04-21 14:19:54 +02:00
|
|
|
icon: icon.toString(),
|
2020-10-17 09:29:27 +02:00
|
|
|
);
|
|
|
|
} else if (Platform.isLinux) {
|
2021-05-01 11:52:47 +02:00
|
|
|
await linuxNotifications.notify(
|
|
|
|
title,
|
2020-10-17 09:29:27 +02:00
|
|
|
body: body,
|
2021-05-01 11:52:47 +02:00
|
|
|
replacesId: _linuxNotificationIds[roomId] ?? -1,
|
2020-10-17 09:29:27 +02:00
|
|
|
appName: AppConfig.applicationName,
|
|
|
|
);
|
|
|
|
}
|
2020-06-27 10:15:37 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 15:42:23 +02:00
|
|
|
final linuxNotifications =
|
|
|
|
PlatformInfos.isLinux ? NotificationsClient() : null;
|
2021-05-01 11:52:47 +02:00
|
|
|
final Map<String, int> _linuxNotificationIds = {};
|
2020-10-17 09:29:27 +02:00
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
2020-11-08 20:42:35 +01:00
|
|
|
super.initState();
|
2021-02-07 17:18:38 +01:00
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2020-11-08 20:42:35 +01:00
|
|
|
initMatrix();
|
2021-01-19 16:58:30 +01:00
|
|
|
if (PlatformInfos.isWeb) {
|
|
|
|
initConfig().then((_) => initSettings());
|
|
|
|
} else {
|
|
|
|
initSettings();
|
|
|
|
}
|
2020-12-18 11:43:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> initConfig() async {
|
|
|
|
try {
|
2021-04-14 10:37:15 +02:00
|
|
|
final configJsonString =
|
2021-04-21 14:19:54 +02:00
|
|
|
utf8.decode((await http.get(Uri.parse('config.json'))).bodyBytes);
|
2020-12-18 11:43:13 +01:00
|
|
|
final configJson = json.decode(configJsonString);
|
|
|
|
AppConfig.loadFromJson(configJson);
|
2021-06-10 10:20:00 +02:00
|
|
|
} catch (e, _) {
|
|
|
|
Logs().v('[ConfigLoader] config.json not found', e);
|
2020-12-18 11:43:13 +01:00
|
|
|
}
|
2020-11-08 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
2021-01-16 12:46:38 +01:00
|
|
|
LoginState loginState;
|
|
|
|
|
2020-11-08 20:42:35 +01:00
|
|
|
void initMatrix() {
|
2021-01-18 17:31:27 +01:00
|
|
|
// Display the app lock
|
|
|
|
if (PlatformInfos.isMobile) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
FlutterSecureStorage().read(key: SettingKeys.appLockKey).then((lock) {
|
|
|
|
if (lock?.isNotEmpty ?? false) {
|
2021-05-23 13:28:55 +02:00
|
|
|
AppLock.of(widget.context).enable();
|
|
|
|
AppLock.of(widget.context).showLockScreen();
|
2021-01-18 17:31:27 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-11-21 09:22:35 +01:00
|
|
|
onKeyVerificationRequestSub ??= client.onKeyVerificationRequest.stream
|
|
|
|
.listen((KeyVerification request) async {
|
|
|
|
var hidPopup = false;
|
|
|
|
request.onUpdate = () {
|
|
|
|
if (!hidPopup &&
|
|
|
|
{KeyVerificationState.done, KeyVerificationState.error}
|
|
|
|
.contains(request.state)) {
|
2021-05-23 13:28:55 +02:00
|
|
|
Navigator.of(navigatorContext).pop('dialog');
|
2020-06-25 16:29:06 +02:00
|
|
|
}
|
2020-11-21 09:22:35 +01:00
|
|
|
hidPopup = true;
|
|
|
|
};
|
|
|
|
if (await showOkCancelAlertDialog(
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-05-23 13:28:55 +02:00
|
|
|
context: navigatorContext,
|
|
|
|
title: L10n.of(widget.context).newVerificationRequest,
|
|
|
|
message:
|
|
|
|
L10n.of(widget.context).askVerificationRequest(request.userId),
|
|
|
|
okLabel: L10n.of(widget.context).ok,
|
|
|
|
cancelLabel: L10n.of(widget.context).cancel,
|
2020-11-21 09:22:35 +01:00
|
|
|
) ==
|
|
|
|
OkCancelResult.ok) {
|
|
|
|
request.onUpdate = null;
|
|
|
|
hidPopup = true;
|
|
|
|
await request.acceptVerification();
|
2021-05-23 13:28:55 +02:00
|
|
|
await KeyVerificationDialog(request: request).show(navigatorContext);
|
2020-11-21 09:22:35 +01:00
|
|
|
} else {
|
|
|
|
request.onUpdate = null;
|
|
|
|
hidPopup = true;
|
|
|
|
await request.rejectVerification();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_initWithStore();
|
|
|
|
|
2020-11-08 20:42:35 +01:00
|
|
|
if (kIsWeb) {
|
|
|
|
onFocusSub = html.window.onFocus.listen((_) => webHasFocus = true);
|
|
|
|
onBlurSub = html.window.onBlur.listen((_) => webHasFocus = false);
|
|
|
|
}
|
2021-01-16 12:46:38 +01:00
|
|
|
onLoginStateChanged ??= client.onLoginStateChanged.stream.listen((state) {
|
|
|
|
if (loginState != state) {
|
|
|
|
loginState = state;
|
2021-06-10 10:20:00 +02:00
|
|
|
final isInLoginRoutes = {'/home', '/login', '/signup'}
|
|
|
|
.contains(widget.router.currentState.url);
|
|
|
|
if (widget.router.currentState.url == '/' ||
|
|
|
|
(state == LoginState.logged) == isInLoginRoutes) {
|
2021-07-08 17:10:20 +02:00
|
|
|
widget.router.currentState.to(
|
2021-06-18 16:15:11 +02:00
|
|
|
loginState == LoginState.logged ? '/rooms' : '/home',
|
|
|
|
queryParameters: widget.router.currentState.queryParameters,
|
|
|
|
);
|
2021-06-10 10:20:00 +02:00
|
|
|
}
|
2021-01-16 12:46:38 +01:00
|
|
|
}
|
|
|
|
});
|
2021-02-27 14:25:55 +01:00
|
|
|
|
|
|
|
// Cache and resend status message
|
|
|
|
onOwnPresence ??= client.onPresence.stream.listen((presence) {
|
|
|
|
if (client.isLogged() &&
|
|
|
|
client.userID == presence.senderId &&
|
|
|
|
presence.presence?.statusMsg != null) {
|
|
|
|
Logs().v('Update status message: "${presence.presence.statusMsg}"');
|
|
|
|
store.setItem(
|
|
|
|
SettingKeys.ownStatusMessage, presence.presence.statusMsg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-10 15:06:02 +01:00
|
|
|
onUiaRequest ??= client.onUiaRequest.stream.listen(_onUiaRequest);
|
2021-02-07 17:18:38 +01:00
|
|
|
if (PlatformInfos.isWeb || PlatformInfos.isLinux) {
|
2020-11-08 20:42:35 +01:00
|
|
|
client.onSync.stream.first.then((s) {
|
|
|
|
html.Notification.requestPermission();
|
|
|
|
onNotification ??= client.onEvent.stream
|
|
|
|
.where((e) =>
|
|
|
|
e.type == EventUpdateType.timeline &&
|
|
|
|
[EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted]
|
2021-03-09 19:39:25 +01:00
|
|
|
.contains(e.content['type']) &&
|
2020-11-08 20:42:35 +01:00
|
|
|
e.content['sender'] != client.userID)
|
|
|
|
.listen(_showLocalNotification);
|
|
|
|
});
|
|
|
|
}
|
2021-02-07 17:18:38 +01:00
|
|
|
|
|
|
|
if (PlatformInfos.isMobile) {
|
2021-05-28 20:32:52 +02:00
|
|
|
_backgroundPush = BackgroundPush(
|
|
|
|
client,
|
|
|
|
context,
|
|
|
|
widget.router,
|
|
|
|
onFcmError: (errorMsg) => ScaffoldMessenger.of(context)
|
|
|
|
.showSnackBar(SnackBar(content: Text(errorMsg))),
|
|
|
|
);
|
2021-02-07 17:18:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _firstStartup = true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
Logs().v('AppLifecycleState = $state');
|
|
|
|
final foreground = state != AppLifecycleState.detached &&
|
|
|
|
state != AppLifecycleState.paused;
|
|
|
|
client.backgroundSync = foreground;
|
|
|
|
client.syncPresence = foreground ? null : PresenceType.unavailable;
|
|
|
|
client.requestHistoryOnLimitedTimeline = !foreground;
|
|
|
|
if (_firstStartup) {
|
|
|
|
_firstStartup = false;
|
|
|
|
_backgroundPush?.setupPush();
|
|
|
|
}
|
2020-11-08 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void initSettings() {
|
2020-05-13 15:58:59 +02:00
|
|
|
if (store != null) {
|
2020-12-11 14:14:33 +01:00
|
|
|
store.getItem(SettingKeys.jitsiInstance).then((final instance) =>
|
|
|
|
AppConfig.jitsiInstance = instance ?? AppConfig.jitsiInstance);
|
2020-11-07 12:00:41 +01:00
|
|
|
store.getItem(SettingKeys.wallpaper).then((final path) async {
|
2020-04-08 10:54:17 +02:00
|
|
|
if (path == null) return;
|
2020-04-03 20:24:25 +02:00
|
|
|
final file = File(path);
|
|
|
|
if (await file.exists()) {
|
|
|
|
wallpaper = file;
|
|
|
|
}
|
|
|
|
});
|
2021-02-13 09:56:16 +01:00
|
|
|
store.getItem(SettingKeys.fontSizeFactor).then((value) =>
|
|
|
|
AppConfig.fontSizeFactor =
|
|
|
|
double.tryParse(value ?? '') ?? AppConfig.fontSizeFactor);
|
2020-11-07 12:00:41 +01:00
|
|
|
store
|
|
|
|
.getItemBool(SettingKeys.renderHtml, AppConfig.renderHtml)
|
|
|
|
.then((value) => AppConfig.renderHtml = value);
|
|
|
|
store
|
|
|
|
.getItemBool(
|
|
|
|
SettingKeys.hideRedactedEvents, AppConfig.hideRedactedEvents)
|
|
|
|
.then((value) => AppConfig.hideRedactedEvents = value);
|
|
|
|
store
|
|
|
|
.getItemBool(
|
|
|
|
SettingKeys.hideUnknownEvents, AppConfig.hideUnknownEvents)
|
|
|
|
.then((value) => AppConfig.hideUnknownEvents = value);
|
2021-08-07 19:36:42 +02:00
|
|
|
store
|
|
|
|
.getItemBool(SettingKeys.autoplayImages, AppConfig.autoplayImages)
|
|
|
|
.then((value) => AppConfig.autoplayImages = value);
|
2020-04-03 20:24:25 +02:00
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
2020-01-03 17:23:40 +01:00
|
|
|
@override
|
|
|
|
void dispose() {
|
2021-02-07 17:18:38 +01:00
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
|
2020-02-22 08:27:08 +01:00
|
|
|
onRoomKeyRequestSub?.cancel();
|
2020-06-25 16:29:06 +02:00
|
|
|
onKeyVerificationRequestSub?.cancel();
|
2021-01-16 16:39:07 +01:00
|
|
|
onLoginStateChanged?.cancel();
|
2021-02-27 14:25:55 +01:00
|
|
|
onOwnPresence?.cancel();
|
2020-06-27 10:15:37 +02:00
|
|
|
onNotification?.cancel();
|
2020-08-22 15:20:07 +02:00
|
|
|
onFocusSub?.cancel();
|
|
|
|
onBlurSub?.cancel();
|
2021-02-07 17:18:38 +01:00
|
|
|
_backgroundPush?.onLogin?.cancel();
|
|
|
|
|
2021-06-18 10:29:48 +02:00
|
|
|
linuxNotifications?.close();
|
2021-05-01 11:52:47 +02:00
|
|
|
|
2020-01-03 17:23:40 +01:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-01-01 19:10:13 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-01-15 19:59:30 +01:00
|
|
|
return Provider(
|
|
|
|
create: (_) => this,
|
2020-12-19 16:37:32 +01:00
|
|
|
child: widget.child,
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 12:18:50 +02:00
|
|
|
|
|
|
|
class FixedThreepidCreds extends ThreepidCreds {
|
|
|
|
FixedThreepidCreds({
|
|
|
|
String sid,
|
|
|
|
String clientSecret,
|
|
|
|
String idServer,
|
|
|
|
String idAccessToken,
|
|
|
|
}) : super(
|
|
|
|
sid: sid,
|
|
|
|
clientSecret: clientSecret,
|
|
|
|
idServer: idServer,
|
|
|
|
idAccessToken: idAccessToken,
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
final data = <String, dynamic>{};
|
|
|
|
data['sid'] = sid;
|
|
|
|
data['client_secret'] = clientSecret;
|
|
|
|
if (idServer != null) data['id_server'] = idServer;
|
|
|
|
if (idAccessToken != null) data['id_access_token'] = idAccessToken;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|