mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-17 09:35:12 +00:00
feat: Display migration notification
This commit is contained in:
parent
8797ff0b51
commit
a190f7de08
2 changed files with 58 additions and 2 deletions
|
@ -2549,5 +2549,7 @@
|
||||||
"groupCanBeFoundViaSearch": "Group can be found via search",
|
"groupCanBeFoundViaSearch": "Group can be found via search",
|
||||||
"wrongRecoveryKey": "Sorry... this does not seem to be the correct recovery key.",
|
"wrongRecoveryKey": "Sorry... this does not seem to be the correct recovery key.",
|
||||||
"startConversation": "Start conversation",
|
"startConversation": "Start conversation",
|
||||||
"commandHint_sendraw": "Send raw json"
|
"commandHint_sendraw": "Send raw json",
|
||||||
|
"databaseMigrationTitle": "Database is optimized",
|
||||||
|
"databaseMigrationBody": "Please wait. This may take a moment."
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'dart:io';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:matrix/encryption/utils/key_verification.dart';
|
import 'package:matrix/encryption/utils/key_verification.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:universal_html/html.dart' as html;
|
||||||
|
|
||||||
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/utils/custom_http_client.dart';
|
import 'package:fluffychat/utils/custom_http_client.dart';
|
||||||
import 'package:fluffychat/utils/custom_image_resizer.dart';
|
import 'package:fluffychat/utils/custom_image_resizer.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart';
|
||||||
|
@ -37,18 +45,26 @@ abstract class ClientManager {
|
||||||
}
|
}
|
||||||
final clients = clientNames.map(createClient).toList();
|
final clients = clientNames.map(createClient).toList();
|
||||||
if (initialize) {
|
if (initialize) {
|
||||||
|
FlutterLocalNotificationsPlugin? flutterLocalNotificationsPlugin;
|
||||||
await Future.wait(
|
await Future.wait(
|
||||||
clients.map(
|
clients.map(
|
||||||
(client) => client
|
(client) => client
|
||||||
.init(
|
.init(
|
||||||
waitForFirstSync: false,
|
waitForFirstSync: false,
|
||||||
waitUntilLoadCompletedLoaded: false,
|
waitUntilLoadCompletedLoaded: false,
|
||||||
|
onMigration: () {
|
||||||
|
sendMigrationNotification(
|
||||||
|
flutterLocalNotificationsPlugin ??=
|
||||||
|
FlutterLocalNotificationsPlugin(),
|
||||||
|
);
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.catchError(
|
.catchError(
|
||||||
(e, s) => Logs().e('Unable to initialize client', e, s),
|
(e, s) => Logs().e('Unable to initialize client', e, s),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
flutterLocalNotificationsPlugin?.cancel(0);
|
||||||
}
|
}
|
||||||
if (clients.length > 1 && clients.any((c) => !c.isLogged())) {
|
if (clients.length > 1 && clients.any((c) => !c.isLogged())) {
|
||||||
final loggedOutClients = clients.where((c) => !c.isLogged()).toList();
|
final loggedOutClients = clients.where((c) => !c.isLogged()).toList();
|
||||||
|
@ -114,4 +130,42 @@ abstract class ClientManager {
|
||||||
enableDehydratedDevices: true,
|
enableDehydratedDevices: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sendMigrationNotification(
|
||||||
|
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin,
|
||||||
|
) async {
|
||||||
|
final l10n = lookupL10n(Locale(Platform.localeName));
|
||||||
|
|
||||||
|
if (kIsWeb) {
|
||||||
|
html.Notification(
|
||||||
|
l10n.databaseMigrationTitle,
|
||||||
|
body: l10n.databaseMigrationBody,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await flutterLocalNotificationsPlugin.initialize(
|
||||||
|
const InitializationSettings(
|
||||||
|
android: AndroidInitializationSettings('notifications_icon'),
|
||||||
|
iOS: DarwinInitializationSettings(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
flutterLocalNotificationsPlugin.show(
|
||||||
|
0,
|
||||||
|
l10n.databaseMigrationTitle,
|
||||||
|
l10n.databaseMigrationBody,
|
||||||
|
const NotificationDetails(
|
||||||
|
android: AndroidNotificationDetails(
|
||||||
|
AppConfig.pushNotificationsChannelId,
|
||||||
|
AppConfig.pushNotificationsChannelName,
|
||||||
|
channelDescription: AppConfig.pushNotificationsChannelDescription,
|
||||||
|
importance: Importance.max,
|
||||||
|
priority: Priority.max,
|
||||||
|
fullScreenIntent: true, // To show notification popup
|
||||||
|
showProgress: true,
|
||||||
|
),
|
||||||
|
iOS: DarwinNotificationDetails(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue