mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-17 08:15:09 +00:00
chore: Use legacy database if database build fails
This commit is contained in:
parent
be6165f422
commit
ac5bd56c03
3 changed files with 39 additions and 22 deletions
|
@ -2384,5 +2384,13 @@
|
||||||
"addChatOrSubSpace": "Add chat or sub space",
|
"addChatOrSubSpace": "Add chat or sub space",
|
||||||
"subspace": "Subspace",
|
"subspace": "Subspace",
|
||||||
"decline": "Decline",
|
"decline": "Decline",
|
||||||
"thisDevice": "This device:"
|
"thisDevice": "This device:",
|
||||||
|
"initAppError": "An error occured while init the app",
|
||||||
|
"databaseBuildErrorBody": "Unable to build the SQlite database. The app tries to use the legacy database for now. Please report this error to the developers at {url}",
|
||||||
|
"@databaseBuildErrorBody": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders": {
|
||||||
|
"url": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -44,7 +44,6 @@ 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
|
||||||
|
@ -52,9 +51,10 @@ abstract class ClientManager {
|
||||||
waitForFirstSync: false,
|
waitForFirstSync: false,
|
||||||
waitUntilLoadCompletedLoaded: false,
|
waitUntilLoadCompletedLoaded: false,
|
||||||
onMigration: () {
|
onMigration: () {
|
||||||
sendMigrationNotification(
|
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
||||||
flutterLocalNotificationsPlugin ??=
|
sendInitNotification(
|
||||||
FlutterLocalNotificationsPlugin(),
|
l10n.databaseMigrationTitle,
|
||||||
|
l10n.databaseMigrationBody,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,6 @@ abstract class ClientManager {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
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();
|
||||||
|
@ -128,22 +127,18 @@ abstract class ClientManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendMigrationNotification(
|
static void sendInitNotification(String title, String body) async {
|
||||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin,
|
|
||||||
) async {
|
|
||||||
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
|
||||||
|
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
html.Notification(
|
html.Notification(
|
||||||
l10n.databaseMigrationTitle,
|
title,
|
||||||
body: l10n.databaseMigrationBody,
|
body: body,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Platform.isLinux) {
|
if (Platform.isLinux) {
|
||||||
await NotificationsClient().notify(
|
await NotificationsClient().notify(
|
||||||
l10n.databaseMigrationTitle,
|
title,
|
||||||
body: l10n.databaseMigrationBody,
|
body: body,
|
||||||
appName: AppConfig.applicationName,
|
appName: AppConfig.applicationName,
|
||||||
hints: [
|
hints: [
|
||||||
NotificationHint.soundName('message-new-instant'),
|
NotificationHint.soundName('message-new-instant'),
|
||||||
|
@ -152,6 +147,8 @@ abstract class ClientManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
await flutterLocalNotificationsPlugin.initialize(
|
await flutterLocalNotificationsPlugin.initialize(
|
||||||
const InitializationSettings(
|
const InitializationSettings(
|
||||||
android: AndroidInitializationSettings('notifications_icon'),
|
android: AndroidInitializationSettings('notifications_icon'),
|
||||||
|
@ -161,8 +158,8 @@ abstract class ClientManager {
|
||||||
|
|
||||||
flutterLocalNotificationsPlugin.show(
|
flutterLocalNotificationsPlugin.show(
|
||||||
0,
|
0,
|
||||||
l10n.databaseMigrationTitle,
|
title,
|
||||||
l10n.databaseMigrationBody,
|
body,
|
||||||
const NotificationDetails(
|
const NotificationDetails(
|
||||||
android: AndroidNotificationDetails(
|
android: AndroidNotificationDetails(
|
||||||
AppConfig.pushNotificationsChannelId,
|
AppConfig.pushNotificationsChannelId,
|
||||||
|
@ -171,7 +168,6 @@ abstract class ClientManager {
|
||||||
importance: Importance.max,
|
importance: Importance.max,
|
||||||
priority: Priority.max,
|
priority: Priority.max,
|
||||||
fullScreenIntent: true, // To show notification popup
|
fullScreenIntent: true, // To show notification popup
|
||||||
showProgress: true,
|
|
||||||
),
|
),
|
||||||
iOS: DarwinNotificationDetails(sound: 'notification.caf'),
|
iOS: DarwinNotificationDetails(sound: 'notification.caf'),
|
||||||
),
|
),
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'dart:math';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.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';
|
||||||
|
@ -11,12 +12,24 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart' as ffi;
|
||||||
import 'package:sqflite_sqlcipher/sqflite.dart';
|
import 'package:sqflite_sqlcipher/sqflite.dart';
|
||||||
import 'package:universal_html/html.dart' as html;
|
import 'package:universal_html/html.dart' as html;
|
||||||
|
|
||||||
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
|
import 'package:fluffychat/utils/client_manager.dart';
|
||||||
|
import 'package:fluffychat/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
|
||||||
Future<MatrixSdkDatabase> flutterMatrixSdkDatabaseBuilder(Client client) async {
|
Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
|
||||||
|
try {
|
||||||
final database = await _constructDatabase(client);
|
final database = await _constructDatabase(client);
|
||||||
await database.open();
|
await database.open();
|
||||||
return database;
|
return database;
|
||||||
|
} catch (e) {
|
||||||
|
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
||||||
|
ClientManager.sendInitNotification(
|
||||||
|
l10n.initAppError,
|
||||||
|
l10n.databaseBuildErrorBody(AppConfig.newIssueUrl.toString()),
|
||||||
|
);
|
||||||
|
return FlutterHiveCollectionsDatabase.databaseBuilder(client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
|
Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
|
||||||
|
|
Loading…
Reference in a new issue