mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 10:25:11 +00:00
refactor: Store and fix missing persistence of some values
This commit is contained in:
parent
c10fe91636
commit
c9c2620ad4
12 changed files with 120 additions and 165 deletions
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.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:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/utils/client_manager.dart';
|
import 'package:fluffychat/utils/client_manager.dart';
|
||||||
|
@ -21,7 +22,8 @@ void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
Logs().nativeColors = !PlatformInfos.isIOS;
|
Logs().nativeColors = !PlatformInfos.isIOS;
|
||||||
final clients = await ClientManager.getClients();
|
final store = await SharedPreferences.getInstance();
|
||||||
|
final clients = await ClientManager.getClients(store: store);
|
||||||
|
|
||||||
// If the app starts in detached mode, we assume that it is in
|
// If the app starts in detached mode, we assume that it is in
|
||||||
// background fetch mode for processing push notifications. This is
|
// background fetch mode for processing push notifications. This is
|
||||||
|
@ -32,7 +34,7 @@ void main() async {
|
||||||
// starting the Flutter engine but process incoming push notifications.
|
// starting the Flutter engine but process incoming push notifications.
|
||||||
BackgroundPush.clientOnly(clients.first);
|
BackgroundPush.clientOnly(clients.first);
|
||||||
// To start the flutter engine afterwards we add an custom observer.
|
// To start the flutter engine afterwards we add an custom observer.
|
||||||
WidgetsBinding.instance.addObserver(AppStarter(clients));
|
WidgetsBinding.instance.addObserver(AppStarter(clients, store));
|
||||||
Logs().i(
|
Logs().i(
|
||||||
'${AppConfig.applicationName} started in background-fetch mode. No GUI will be created unless the app is no longer detached.',
|
'${AppConfig.applicationName} started in background-fetch mode. No GUI will be created unless the app is no longer detached.',
|
||||||
);
|
);
|
||||||
|
@ -43,11 +45,11 @@ void main() async {
|
||||||
Logs().i(
|
Logs().i(
|
||||||
'${AppConfig.applicationName} started in foreground mode. Rendering GUI...',
|
'${AppConfig.applicationName} started in foreground mode. Rendering GUI...',
|
||||||
);
|
);
|
||||||
await startGui(clients);
|
await startGui(clients, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the pincode for the applock and start the flutter engine.
|
/// Fetch the pincode for the applock and start the flutter engine.
|
||||||
Future<void> startGui(List<Client> clients) async {
|
Future<void> startGui(List<Client> clients, SharedPreferences store) async {
|
||||||
// Fetch the pin for the applock if existing for mobile applications.
|
// Fetch the pin for the applock if existing for mobile applications.
|
||||||
String? pin;
|
String? pin;
|
||||||
if (PlatformInfos.isMobile) {
|
if (PlatformInfos.isMobile) {
|
||||||
|
@ -65,16 +67,17 @@ Future<void> startGui(List<Client> clients) async {
|
||||||
await firstClient?.accountDataLoading;
|
await firstClient?.accountDataLoading;
|
||||||
|
|
||||||
ErrorWidget.builder = (details) => FluffyChatErrorWidget(details);
|
ErrorWidget.builder = (details) => FluffyChatErrorWidget(details);
|
||||||
runApp(FluffyChatApp(clients: clients, pincode: pin));
|
runApp(FluffyChatApp(clients: clients, pincode: pin, store: store));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Watches the lifecycle changes to start the application when it
|
/// Watches the lifecycle changes to start the application when it
|
||||||
/// is no longer detached.
|
/// is no longer detached.
|
||||||
class AppStarter with WidgetsBindingObserver {
|
class AppStarter with WidgetsBindingObserver {
|
||||||
final List<Client> clients;
|
final List<Client> clients;
|
||||||
|
final SharedPreferences store;
|
||||||
bool guiStarted = false;
|
bool guiStarted = false;
|
||||||
|
|
||||||
AppStarter(this.clients);
|
AppStarter(this.clients, this.store);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
@ -84,7 +87,7 @@ class AppStarter with WidgetsBindingObserver {
|
||||||
Logs().i(
|
Logs().i(
|
||||||
'${AppConfig.applicationName} switches from the detached background-fetch mode to ${state.name} mode. Rendering GUI...',
|
'${AppConfig.applicationName} switches from the detached background-fetch mode to ${state.name} mode. Rendering GUI...',
|
||||||
);
|
);
|
||||||
startGui(clients);
|
startGui(clients, store);
|
||||||
// We must make sure that the GUI is only started once.
|
// We must make sure that the GUI is only started once.
|
||||||
guiStarted = true;
|
guiStarted = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/config/themes.dart';
|
import 'package:fluffychat/config/themes.dart';
|
||||||
import 'package:fluffychat/pages/chat_list/chat_list_view.dart';
|
import 'package:fluffychat/pages/chat_list/chat_list_view.dart';
|
||||||
import 'package:fluffychat/pages/settings_security/settings_security.dart';
|
import 'package:fluffychat/pages/settings_security/settings_security.dart';
|
||||||
import 'package:fluffychat/utils/famedlysdk_store.dart';
|
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
|
@ -189,7 +188,7 @@ class ChatListController extends State<ChatList>
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
if (newServer == null) return;
|
if (newServer == null) return;
|
||||||
Store().setItem(_serverStoreNamespace, newServer.single);
|
Matrix.of(context).store.setString(_serverStoreNamespace, newServer.single);
|
||||||
setState(() {
|
setState(() {
|
||||||
searchServer = newServer.single;
|
searchServer = newServer.single;
|
||||||
});
|
});
|
||||||
|
@ -382,7 +381,8 @@ class ChatListController extends State<ChatList>
|
||||||
CallKeepManager().initialize();
|
CallKeepManager().initialize();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
searchServer = await Store().getItem(_serverStoreNamespace);
|
searchServer =
|
||||||
|
Matrix.of(context).store.getString(_serverStoreNamespace);
|
||||||
Matrix.of(context).backgroundPush?.setupPush();
|
Matrix.of(context).backgroundPush?.setupPush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ class SettingsStyleController extends State<SettingsStyle> {
|
||||||
if (pickedFile == null) return;
|
if (pickedFile == null) return;
|
||||||
await Matrix.of(context)
|
await Matrix.of(context)
|
||||||
.store
|
.store
|
||||||
.setItem(SettingKeys.wallpaper, pickedFile.path);
|
.setString(SettingKeys.wallpaper, pickedFile.path!);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteWallpaperAction() async {
|
void deleteWallpaperAction() async {
|
||||||
Matrix.of(context).wallpaper = null;
|
Matrix.of(context).wallpaper = null;
|
||||||
await Matrix.of(context).store.deleteItem(SettingKeys.wallpaper);
|
await Matrix.of(context).store.remove(SettingKeys.wallpaper);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class SettingsStyleController extends State<SettingsStyle> {
|
||||||
|
|
||||||
void changeFontSizeFactor(double d) {
|
void changeFontSizeFactor(double d) {
|
||||||
setState(() => AppConfig.fontSizeFactor = d);
|
setState(() => AppConfig.fontSizeFactor = d);
|
||||||
Matrix.of(context).store.setItem(
|
Matrix.of(context).store.setString(
|
||||||
SettingKeys.fontSizeFactor,
|
SettingKeys.fontSizeFactor,
|
||||||
AppConfig.fontSizeFactor.toString(),
|
AppConfig.fontSizeFactor.toString(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,7 +37,6 @@ import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||||
import '../config/app_config.dart';
|
import '../config/app_config.dart';
|
||||||
import '../config/setting_keys.dart';
|
import '../config/setting_keys.dart';
|
||||||
import '../widgets/matrix.dart';
|
import '../widgets/matrix.dart';
|
||||||
import 'famedlysdk_store.dart';
|
|
||||||
import 'platform_infos.dart';
|
import 'platform_infos.dart';
|
||||||
|
|
||||||
//import 'package:fcm_shared_isolate/fcm_shared_isolate.dart';
|
//import 'package:fcm_shared_isolate/fcm_shared_isolate.dart';
|
||||||
|
@ -55,8 +54,7 @@ class BackgroundPush {
|
||||||
String? _fcmToken;
|
String? _fcmToken;
|
||||||
void Function(String errorMsg, {Uri? link})? onFcmError;
|
void Function(String errorMsg, {Uri? link})? onFcmError;
|
||||||
L10n? l10n;
|
L10n? l10n;
|
||||||
Store? _store;
|
|
||||||
Store get store => _store ??= Store();
|
|
||||||
Future<void> loadLocale() async {
|
Future<void> loadLocale() async {
|
||||||
final context = matrix?.context;
|
final context = matrix?.context;
|
||||||
// inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart
|
// inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart
|
||||||
|
@ -271,7 +269,7 @@ class BackgroundPush {
|
||||||
if (matrix == null) {
|
if (matrix == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (await store.getItemBool(SettingKeys.showNoGoogle, false) == true) {
|
if ((matrix?.store.getBool(SettingKeys.showNoGoogle) ?? false) == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await loadLocale();
|
await loadLocale();
|
||||||
|
@ -374,16 +372,17 @@ class BackgroundPush {
|
||||||
oldTokens: oldTokens,
|
oldTokens: oldTokens,
|
||||||
useDeviceSpecificAppId: true,
|
useDeviceSpecificAppId: true,
|
||||||
);
|
);
|
||||||
await store.setItem(SettingKeys.unifiedPushEndpoint, newEndpoint);
|
await matrix?.store.setString(SettingKeys.unifiedPushEndpoint, newEndpoint);
|
||||||
await store.setItemBool(SettingKeys.unifiedPushRegistered, true);
|
await matrix?.store.setBool(SettingKeys.unifiedPushRegistered, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _upUnregistered(String i) async {
|
Future<void> _upUnregistered(String i) async {
|
||||||
upAction = true;
|
upAction = true;
|
||||||
Logs().i('[Push] Removing UnifiedPush endpoint...');
|
Logs().i('[Push] Removing UnifiedPush endpoint...');
|
||||||
final oldEndpoint = await store.getItem(SettingKeys.unifiedPushEndpoint);
|
final oldEndpoint =
|
||||||
await store.setItemBool(SettingKeys.unifiedPushRegistered, false);
|
matrix?.store.getString(SettingKeys.unifiedPushEndpoint);
|
||||||
await store.deleteItem(SettingKeys.unifiedPushEndpoint);
|
await matrix?.store.setBool(SettingKeys.unifiedPushRegistered, false);
|
||||||
|
await matrix?.store.remove(SettingKeys.unifiedPushEndpoint);
|
||||||
if (oldEndpoint?.isNotEmpty ?? false) {
|
if (oldEndpoint?.isNotEmpty ?? false) {
|
||||||
// remove the old pusher
|
// remove the old pusher
|
||||||
await setupPusher(
|
await setupPusher(
|
||||||
|
@ -409,12 +408,12 @@ class BackgroundPush {
|
||||||
|
|
||||||
/// Workaround for the problem that local notification IDs must be int but we
|
/// Workaround for the problem that local notification IDs must be int but we
|
||||||
/// sort by [roomId] which is a String. To make sure that we don't have duplicated
|
/// sort by [roomId] which is a String. To make sure that we don't have duplicated
|
||||||
/// IDs we map the [roomId] to a number and store this number.
|
/// IDs we map the [roomId] to a number and matrix?.store this number.
|
||||||
late Map<String, int> idMap;
|
late Map<String, int> idMap;
|
||||||
Future<void> _loadIdMap() async {
|
Future<void> _loadIdMap() async {
|
||||||
idMap = Map<String, int>.from(
|
idMap = Map<String, int>.from(
|
||||||
json.decode(
|
json.decode(
|
||||||
(await store.getItem(SettingKeys.notificationCurrentIds)) ?? '{}',
|
(matrix?.store.getString(SettingKeys.notificationCurrentIds)) ?? '{}',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -488,7 +487,7 @@ class BackgroundPush {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
await store.setItem(
|
await matrix?.store.setString(
|
||||||
SettingKeys.notificationCurrentIds,
|
SettingKeys.notificationCurrentIds,
|
||||||
json.encode(idMap),
|
json.encode(idMap),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.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: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';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'famedlysdk_store.dart';
|
|
||||||
|
|
||||||
abstract class ClientManager {
|
abstract class ClientManager {
|
||||||
static const String clientNamespace = 'im.fluffychat.store.clients';
|
static const String clientNamespace = 'im.fluffychat.store.clients';
|
||||||
static Future<List<Client>> getClients({bool initialize = true}) async {
|
static Future<List<Client>> getClients({
|
||||||
|
bool initialize = true,
|
||||||
|
required SharedPreferences store,
|
||||||
|
}) async {
|
||||||
if (PlatformInfos.isLinux) {
|
if (PlatformInfos.isLinux) {
|
||||||
Hive.init((await getApplicationSupportDirectory()).path);
|
Hive.init((await getApplicationSupportDirectory()).path);
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,19 +24,15 @@ abstract class ClientManager {
|
||||||
}
|
}
|
||||||
final clientNames = <String>{};
|
final clientNames = <String>{};
|
||||||
try {
|
try {
|
||||||
final rawClientNames = await Store().getItem(clientNamespace);
|
final clientNamesList = store.getStringList(clientNamespace) ?? [];
|
||||||
if (rawClientNames != null) {
|
|
||||||
final clientNamesList =
|
|
||||||
(jsonDecode(rawClientNames) as List).cast<String>();
|
|
||||||
clientNames.addAll(clientNamesList);
|
clientNames.addAll(clientNamesList);
|
||||||
}
|
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().w('Client names in store are corrupted', e, s);
|
Logs().w('Client names in store are corrupted', e, s);
|
||||||
await Store().deleteItem(clientNamespace);
|
await store.remove(clientNamespace);
|
||||||
}
|
}
|
||||||
if (clientNames.isEmpty) {
|
if (clientNames.isEmpty) {
|
||||||
clientNames.add(PlatformInfos.clientName);
|
clientNames.add(PlatformInfos.clientName);
|
||||||
await Store().setItem(clientNamespace, jsonEncode(clientNames.toList()));
|
await store.setStringList(clientNamespace, clientNames.toList());
|
||||||
}
|
}
|
||||||
final clients = clientNames.map(createClient).toList();
|
final clients = clientNames.map(createClient).toList();
|
||||||
if (initialize) {
|
if (initialize) {
|
||||||
|
@ -61,31 +58,27 @@ abstract class ClientManager {
|
||||||
clientNames.remove(client.clientName);
|
clientNames.remove(client.clientName);
|
||||||
clients.remove(client);
|
clients.remove(client);
|
||||||
}
|
}
|
||||||
await Store().setItem(clientNamespace, jsonEncode(clientNames.toList()));
|
await store.setStringList(clientNamespace, clientNames.toList());
|
||||||
}
|
}
|
||||||
return clients;
|
return clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> addClientNameToStore(String clientName) async {
|
static Future<void> addClientNameToStore(
|
||||||
final clientNamesList = <String>[];
|
String clientName,
|
||||||
final rawClientNames = await Store().getItem(clientNamespace);
|
SharedPreferences store,
|
||||||
if (rawClientNames != null) {
|
) async {
|
||||||
final stored = (jsonDecode(rawClientNames) as List).cast<String>();
|
final clientNamesList = store.getStringList(clientNamespace) ?? [];
|
||||||
clientNamesList.addAll(stored);
|
|
||||||
}
|
|
||||||
clientNamesList.add(clientName);
|
clientNamesList.add(clientName);
|
||||||
await Store().setItem(clientNamespace, jsonEncode(clientNamesList));
|
await store.setStringList(clientNamespace, clientNamesList);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> removeClientNameFromStore(String clientName) async {
|
static Future<void> removeClientNameFromStore(
|
||||||
final clientNamesList = <String>[];
|
String clientName,
|
||||||
final rawClientNames = await Store().getItem(clientNamespace);
|
SharedPreferences store,
|
||||||
if (rawClientNames != null) {
|
) async {
|
||||||
final stored = (jsonDecode(rawClientNames) as List).cast<String>();
|
final clientNamesList = store.getStringList(clientNamespace) ?? [];
|
||||||
clientNamesList.addAll(stored);
|
|
||||||
}
|
|
||||||
clientNamesList.remove(clientName);
|
clientNamesList.remove(clientName);
|
||||||
await Store().setItem(clientNamespace, jsonEncode(clientNamesList));
|
await store.setStringList(clientNamespace, clientNamesList);
|
||||||
}
|
}
|
||||||
|
|
||||||
static NativeImplementations get nativeImplementations => kIsWeb
|
static NativeImplementations get nativeImplementations => kIsWeb
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
import 'dart:core';
|
|
||||||
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
|
|
||||||
class Store {
|
|
||||||
SharedPreferences? _prefs;
|
|
||||||
|
|
||||||
Future<void> _setupLocalStorage() async {
|
|
||||||
_prefs ??= await SharedPreferences.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String?> getItem(String key) async {
|
|
||||||
await _setupLocalStorage();
|
|
||||||
return _prefs!.getString(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> getItemBool(String key, [bool? defaultValue]) async {
|
|
||||||
await _setupLocalStorage();
|
|
||||||
return _prefs!.getBool(key) ?? defaultValue ?? true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setItem(String key, String? value) async {
|
|
||||||
await _setupLocalStorage();
|
|
||||||
if (value == null) {
|
|
||||||
await _prefs!.remove(key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await _prefs!.setString(key, value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setItemBool(String key, bool value) async {
|
|
||||||
await _setupLocalStorage();
|
|
||||||
await _prefs!.setBool(key, value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> deleteItem(String key) async {
|
|
||||||
await _setupLocalStorage();
|
|
||||||
await _prefs!.remove(key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -98,7 +98,11 @@ Future<void> _tryPushHelper(
|
||||||
//onDidReceiveBackgroundNotificationResponse: onSelectNotification,
|
//onDidReceiveBackgroundNotificationResponse: onSelectNotification,
|
||||||
);
|
);
|
||||||
|
|
||||||
client ??= (await ClientManager.getClients(initialize: false)).first;
|
client ??= (await ClientManager.getClients(
|
||||||
|
initialize: false,
|
||||||
|
store: await SharedPreferences.getInstance(),
|
||||||
|
))
|
||||||
|
.first;
|
||||||
final event = await client.getEventByPushNotification(
|
final event = await client.getEventByPushNotification(
|
||||||
notification,
|
notification,
|
||||||
storeInDatabase: isBackgroundMessage,
|
storeInDatabase: isBackgroundMessage,
|
||||||
|
|
|
@ -11,7 +11,6 @@ import 'package:webrtc_interface/webrtc_interface.dart' hide Navigator;
|
||||||
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
||||||
import 'package:fluffychat/pages/dialer/dialer.dart';
|
import 'package:fluffychat/pages/dialer/dialer.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import '../../utils/famedlysdk_store.dart';
|
|
||||||
import '../../utils/voip/callkeep_manager.dart';
|
import '../../utils/voip/callkeep_manager.dart';
|
||||||
import '../../utils/voip/user_media_manager.dart';
|
import '../../utils/voip/user_media_manager.dart';
|
||||||
import '../widgets/matrix.dart';
|
import '../widgets/matrix.dart';
|
||||||
|
@ -133,7 +132,8 @@ class VoipPlugin with WidgetsBindingObserver implements WebRTCDelegate {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
final wasForeground = await FlutterForegroundTask.isAppOnForeground;
|
final wasForeground = await FlutterForegroundTask.isAppOnForeground;
|
||||||
await Store().setItem(
|
|
||||||
|
await matrix.store.setString(
|
||||||
'wasForeground',
|
'wasForeground',
|
||||||
wasForeground == true ? 'true' : 'false',
|
wasForeground == true ? 'true' : 'false',
|
||||||
);
|
);
|
||||||
|
@ -172,7 +172,7 @@ class VoipPlugin with WidgetsBindingObserver implements WebRTCDelegate {
|
||||||
if (PlatformInfos.isAndroid) {
|
if (PlatformInfos.isAndroid) {
|
||||||
FlutterForegroundTask.setOnLockScreenVisibility(false);
|
FlutterForegroundTask.setOnLockScreenVisibility(false);
|
||||||
FlutterForegroundTask.stopService();
|
FlutterForegroundTask.stopService();
|
||||||
final wasForeground = await Store().getItem('wasForeground');
|
final wasForeground = matrix.store.getString('wasForeground');
|
||||||
wasForeground == 'false' ? FlutterForegroundTask.minimizeApp() : null;
|
wasForeground == 'false' ? FlutterForegroundTask.minimizeApp() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/routes.dart';
|
import 'package:fluffychat/config/routes.dart';
|
||||||
import 'package:fluffychat/config/themes.dart';
|
import 'package:fluffychat/config/themes.dart';
|
||||||
|
@ -16,11 +17,13 @@ class FluffyChatApp extends StatelessWidget {
|
||||||
final Widget? testWidget;
|
final Widget? testWidget;
|
||||||
final List<Client> clients;
|
final List<Client> clients;
|
||||||
final String? pincode;
|
final String? pincode;
|
||||||
|
final SharedPreferences store;
|
||||||
|
|
||||||
const FluffyChatApp({
|
const FluffyChatApp({
|
||||||
super.key,
|
super.key,
|
||||||
this.testWidget,
|
this.testWidget,
|
||||||
required this.clients,
|
required this.clients,
|
||||||
|
required this.store,
|
||||||
this.pincode,
|
this.pincode,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -55,6 +58,7 @@ class FluffyChatApp extends StatelessWidget {
|
||||||
onGenerateRoute: (_) => MaterialPageRoute(
|
onGenerateRoute: (_) => MaterialPageRoute(
|
||||||
builder: (_) => Matrix(
|
builder: (_) => Matrix(
|
||||||
clients: clients,
|
clients: clients,
|
||||||
|
store: store,
|
||||||
child: testWidget ?? child,
|
child: testWidget ?? child,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -15,6 +15,7 @@ import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:matrix/encryption.dart';
|
import 'package:matrix/encryption.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:universal_html/html.dart' as html;
|
import 'package:universal_html/html.dart' as html;
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
|
@ -29,7 +30,6 @@ import '../config/setting_keys.dart';
|
||||||
import '../pages/key_verification/key_verification_dialog.dart';
|
import '../pages/key_verification/key_verification_dialog.dart';
|
||||||
import '../utils/account_bundles.dart';
|
import '../utils/account_bundles.dart';
|
||||||
import '../utils/background_push.dart';
|
import '../utils/background_push.dart';
|
||||||
import '../utils/famedlysdk_store.dart';
|
|
||||||
import 'local_notifications_extension.dart';
|
import 'local_notifications_extension.dart';
|
||||||
|
|
||||||
// import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
// import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
@ -41,9 +41,12 @@ class Matrix extends StatefulWidget {
|
||||||
|
|
||||||
final Map<String, String>? queryParameters;
|
final Map<String, String>? queryParameters;
|
||||||
|
|
||||||
|
final SharedPreferences store;
|
||||||
|
|
||||||
const Matrix({
|
const Matrix({
|
||||||
this.child,
|
this.child,
|
||||||
required this.clients,
|
required this.clients,
|
||||||
|
required this.store,
|
||||||
this.queryParameters,
|
this.queryParameters,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
@ -59,7 +62,7 @@ class Matrix extends StatefulWidget {
|
||||||
class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
int _activeClient = -1;
|
int _activeClient = -1;
|
||||||
String? activeBundle;
|
String? activeBundle;
|
||||||
Store store = Store();
|
SharedPreferences get store => widget.store;
|
||||||
|
|
||||||
HomeserverSummary? loginHomeserverSummary;
|
HomeserverSummary? loginHomeserverSummary;
|
||||||
XFile? loginAvatar;
|
XFile? loginAvatar;
|
||||||
|
@ -158,7 +161,10 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
if (!widget.clients.contains(_loginClientCandidate)) {
|
if (!widget.clients.contains(_loginClientCandidate)) {
|
||||||
widget.clients.add(_loginClientCandidate!);
|
widget.clients.add(_loginClientCandidate!);
|
||||||
}
|
}
|
||||||
ClientManager.addClientNameToStore(_loginClientCandidate!.clientName);
|
ClientManager.addClientNameToStore(
|
||||||
|
_loginClientCandidate!.clientName,
|
||||||
|
store,
|
||||||
|
);
|
||||||
_registerSubs(_loginClientCandidate!.clientName);
|
_registerSubs(_loginClientCandidate!.clientName);
|
||||||
_loginClientCandidate = null;
|
_loginClientCandidate = null;
|
||||||
FluffyChatApp.router.go('/rooms');
|
FluffyChatApp.router.go('/rooms');
|
||||||
|
@ -187,7 +193,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
try {
|
try {
|
||||||
if (client.isLogged()) {
|
if (client.isLogged()) {
|
||||||
// TODO: Figure out how this works in multi account
|
// TODO: Figure out how this works in multi account
|
||||||
final statusMsg = await store.getItem(SettingKeys.ownStatusMessage);
|
final statusMsg = store.getString(SettingKeys.ownStatusMessage);
|
||||||
if (statusMsg?.isNotEmpty ?? false) {
|
if (statusMsg?.isNotEmpty ?? false) {
|
||||||
Logs().v('Send cached status message: "$statusMsg"');
|
Logs().v('Send cached status message: "$statusMsg"');
|
||||||
await client.setPresence(
|
await client.setPresence(
|
||||||
|
@ -314,7 +320,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
|
if (loggedInWithMultipleClients && state != LoginState.loggedIn) {
|
||||||
_cancelSubs(c.clientName);
|
_cancelSubs(c.clientName);
|
||||||
widget.clients.remove(c);
|
widget.clients.remove(c);
|
||||||
ClientManager.removeClientNameFromStore(c.clientName);
|
ClientManager.removeClientNameFromStore(c.clientName, store);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(L10n.of(context)!.oneClientLoggedOut),
|
content: Text(L10n.of(context)!.oneClientLoggedOut),
|
||||||
|
@ -391,7 +397,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (result == OkCancelResult.cancel) {
|
if (result == OkCancelResult.cancel) {
|
||||||
await store.setItemBool(SettingKeys.showNoGoogle, true);
|
await store.setBool(SettingKeys.showNoGoogle, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -401,7 +407,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
void createVoipPlugin() async {
|
void createVoipPlugin() async {
|
||||||
if (await store.getItemBool(SettingKeys.experimentalVoip) == false) {
|
if (store.getBool(SettingKeys.experimentalVoip) == false) {
|
||||||
voipPlugin = null;
|
voipPlugin = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -419,47 +425,40 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
void initSettings() {
|
void initSettings() {
|
||||||
store.getItem(SettingKeys.wallpaper).then((final path) async {
|
final path = store.getString(SettingKeys.wallpaper);
|
||||||
if (path == null) return;
|
if (path != null) wallpaper = File(path);
|
||||||
final file = File(path);
|
|
||||||
if (await file.exists()) {
|
AppConfig.fontSizeFactor =
|
||||||
wallpaper = file;
|
double.tryParse(store.getString(SettingKeys.fontSizeFactor) ?? '') ??
|
||||||
}
|
AppConfig.fontSizeFactor;
|
||||||
});
|
|
||||||
store.getItem(SettingKeys.fontSizeFactor).then(
|
AppConfig.renderHtml =
|
||||||
(value) => AppConfig.fontSizeFactor =
|
store.getBool(SettingKeys.renderHtml) ?? AppConfig.renderHtml;
|
||||||
double.tryParse(value ?? '') ?? AppConfig.fontSizeFactor,
|
|
||||||
);
|
AppConfig.hideRedactedEvents =
|
||||||
store
|
store.getBool(SettingKeys.hideRedactedEvents) ??
|
||||||
.getItemBool(SettingKeys.renderHtml, AppConfig.renderHtml)
|
AppConfig.hideRedactedEvents;
|
||||||
.then((value) => AppConfig.renderHtml = value);
|
|
||||||
store
|
AppConfig.hideUnknownEvents =
|
||||||
.getItemBool(
|
store.getBool(SettingKeys.hideUnknownEvents) ??
|
||||||
SettingKeys.hideRedactedEvents,
|
AppConfig.hideUnknownEvents;
|
||||||
AppConfig.hideRedactedEvents,
|
|
||||||
)
|
AppConfig.separateChatTypes =
|
||||||
.then((value) => AppConfig.hideRedactedEvents = value);
|
store.getBool(SettingKeys.separateChatTypes) ??
|
||||||
store
|
AppConfig.separateChatTypes;
|
||||||
.getItemBool(SettingKeys.hideUnknownEvents, AppConfig.hideUnknownEvents)
|
|
||||||
.then((value) => AppConfig.hideUnknownEvents = value);
|
AppConfig.autoplayImages =
|
||||||
store
|
store.getBool(SettingKeys.autoplayImages) ?? AppConfig.autoplayImages;
|
||||||
.getItemBool(SettingKeys.separateChatTypes, AppConfig.separateChatTypes)
|
|
||||||
.then((value) => AppConfig.separateChatTypes = value);
|
AppConfig.sendTypingNotifications =
|
||||||
store
|
store.getBool(SettingKeys.sendTypingNotifications) ??
|
||||||
.getItemBool(SettingKeys.autoplayImages, AppConfig.autoplayImages)
|
AppConfig.sendTypingNotifications;
|
||||||
.then((value) => AppConfig.autoplayImages = value);
|
|
||||||
store
|
AppConfig.sendOnEnter =
|
||||||
.getItemBool(
|
store.getBool(SettingKeys.sendOnEnter) ?? AppConfig.sendOnEnter;
|
||||||
SettingKeys.sendTypingNotifications,
|
|
||||||
AppConfig.sendTypingNotifications,
|
AppConfig.experimentalVoip = store.getBool(SettingKeys.experimentalVoip) ??
|
||||||
)
|
AppConfig.experimentalVoip;
|
||||||
.then((value) => AppConfig.sendTypingNotifications = value);
|
|
||||||
store
|
|
||||||
.getItemBool(SettingKeys.sendOnEnter, AppConfig.sendOnEnter)
|
|
||||||
.then((value) => AppConfig.sendOnEnter = value);
|
|
||||||
store
|
|
||||||
.getItemBool(SettingKeys.experimentalVoip, AppConfig.experimentalVoip)
|
|
||||||
.then((value) => AppConfig.experimentalVoip = value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -23,19 +23,15 @@ class SettingsSwitchListTile extends StatefulWidget {
|
||||||
class SettingsSwitchListTileState extends State<SettingsSwitchListTile> {
|
class SettingsSwitchListTileState extends State<SettingsSwitchListTile> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder<bool>(
|
return SwitchListTile.adaptive(
|
||||||
future: Matrix.of(context)
|
value: Matrix.of(context).store.getBool(widget.storeKey) ??
|
||||||
.store
|
widget.defaultValue,
|
||||||
.getItemBool(widget.storeKey, widget.defaultValue),
|
|
||||||
builder: (context, snapshot) => SwitchListTile.adaptive(
|
|
||||||
value: snapshot.data ?? widget.defaultValue,
|
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
onChanged: (bool newValue) async {
|
onChanged: (bool newValue) async {
|
||||||
widget.onChanged?.call(newValue);
|
widget.onChanged?.call(newValue);
|
||||||
await Matrix.of(context).store.setItemBool(widget.storeKey, newValue);
|
await Matrix.of(context).store.setBool(widget.storeKey, newValue);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,11 +123,11 @@ index 85aa8647..3b7e09e7 100644
|
||||||
}
|
}
|
||||||
|
|
||||||
diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart
|
diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart
|
||||||
index cd79b0ab..c2db0f1e 100644
|
index 8e67ae92..da4da5c3 100644
|
||||||
--- a/lib/utils/background_push.dart
|
--- a/lib/utils/background_push.dart
|
||||||
+++ b/lib/utils/background_push.dart
|
+++ b/lib/utils/background_push.dart
|
||||||
@@ -39,7 +39,7 @@ import '../config/setting_keys.dart';
|
@@ -39,7 +39,7 @@ import '../config/setting_keys.dart';
|
||||||
import 'famedlysdk_store.dart';
|
import '../widgets/matrix.dart';
|
||||||
import 'platform_infos.dart';
|
import 'platform_infos.dart';
|
||||||
|
|
||||||
-//import 'package:fcm_shared_isolate/fcm_shared_isolate.dart';
|
-//import 'package:fcm_shared_isolate/fcm_shared_isolate.dart';
|
||||||
|
@ -135,7 +135,7 @@ index cd79b0ab..c2db0f1e 100644
|
||||||
|
|
||||||
class NoTokenException implements Exception {
|
class NoTokenException implements Exception {
|
||||||
String get cause => 'Cannot get firebase token';
|
String get cause => 'Cannot get firebase token';
|
||||||
@@ -65,7 +65,7 @@ class BackgroundPush {
|
@@ -64,7 +64,7 @@ class BackgroundPush {
|
||||||
|
|
||||||
final pendingTests = <String, Completer<void>>{};
|
final pendingTests = <String, Completer<void>>{};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue