refactor: Use AppSettings enum based configuration everywhere and fix load from json on web

This commit is contained in:
Christian Kußowski 2025-10-19 19:36:47 +02:00
commit 4c357f6249
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
46 changed files with 357 additions and 402 deletions

View file

@ -217,8 +217,7 @@ class BackgroundPush {
currentPushers.first.lang == 'en' &&
currentPushers.first.data.url.toString() == gatewayUrl &&
currentPushers.first.data.format ==
AppSettings.pushNotificationsPusherFormat
.getItem(matrix!.store) &&
AppSettings.pushNotificationsPusherFormat.value &&
mapEquals(
currentPushers.single.data.additionalProperties,
{"data_message": pusherDataMessageFormat},
@ -258,8 +257,7 @@ class BackgroundPush {
lang: 'en',
data: PusherData(
url: Uri.parse(gatewayUrl!),
format: AppSettings.pushNotificationsPusherFormat
.getItem(matrix!.store),
format: AppSettings.pushNotificationsPusherFormat.value,
additionalProperties: {"data_message": pusherDataMessageFormat},
),
kind: 'http',
@ -325,7 +323,7 @@ class BackgroundPush {
if (matrix == null) {
return;
}
if ((matrix?.store.getBool(SettingKeys.showNoGoogle) ?? false) == true) {
if (!AppSettings.showNoGoogle.value) {
return;
}
await loadLocale();
@ -356,8 +354,7 @@ class BackgroundPush {
}
}
await setupPusher(
gatewayUrl:
AppSettings.pushNotificationsGatewayUrl.getItem(matrix!.store),
gatewayUrl: AppSettings.pushNotificationsGatewayUrl.value,
token: _fcmToken,
);
}
@ -414,18 +411,18 @@ class BackgroundPush {
oldTokens: oldTokens,
useDeviceSpecificAppId: true,
);
await matrix?.store.setString(SettingKeys.unifiedPushEndpoint, newEndpoint);
await matrix?.store.setBool(SettingKeys.unifiedPushRegistered, true);
await AppSettings.unifiedPushEndpoint.setItem(newEndpoint);
await AppSettings.unifiedPushRegistered.setItem(true);
}
Future<void> _upUnregistered(String i) async {
upAction = true;
Logs().i('[Push] Removing UnifiedPush endpoint...');
final oldEndpoint =
matrix?.store.getString(SettingKeys.unifiedPushEndpoint);
await matrix?.store.setBool(SettingKeys.unifiedPushRegistered, false);
await matrix?.store.remove(SettingKeys.unifiedPushEndpoint);
if (oldEndpoint?.isNotEmpty ?? false) {
final oldEndpoint = AppSettings.unifiedPushEndpoint.value;
await AppSettings.unifiedPushEndpoint
.setItem(AppSettings.unifiedPushEndpoint.defaultValue);
await AppSettings.unifiedPushRegistered.setItem(false);
if (oldEndpoint.isNotEmpty) {
// remove the old pusher
await setupPusher(
oldTokens: {oldEndpoint},

View file

@ -11,7 +11,6 @@ import 'package:matrix/matrix.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/config/setting_keys.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/utils/custom_http_client.dart';
@ -101,8 +100,8 @@ abstract class ClientManager {
String clientName,
SharedPreferences store,
) async {
final shareKeysWith = AppSettings.shareKeysWith.getItem(store);
final enableSoftLogout = AppSettings.enableSoftLogout.getItem(store);
final shareKeysWith = AppSettings.shareKeysWith.value;
final enableSoftLogout = AppSettings.enableSoftLogout.value;
return Client(
clientName,
@ -147,7 +146,7 @@ abstract class ClientManager {
await NotificationsClient().notify(
title,
body: body,
appName: AppConfig.applicationName,
appName: AppSettings.applicationName.value,
hints: [
NotificationHint.soundName('message-new-instant'),
],

View file

@ -5,6 +5,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/utils/client_manager.dart';
import 'package:fluffychat/utils/platform_infos.dart';
@ -57,13 +58,13 @@ extension InitWithRestoreExtension on Client {
? const FlutterSecureStorage()
: null;
await storage?.delete(
key: '${AppConfig.applicationName}_session_backup_$clientName',
key: '${AppSettings.applicationName.value}_session_backup_$clientName',
);
}
Future<void> initWithRestore({void Function()? onMigration}) async {
final storageKey =
'${AppConfig.applicationName}_session_backup_$clientName';
'${AppSettings.applicationName.value}_session_backup_$clientName';
final storage = PlatformInfos.isMobile || PlatformInfos.isLinux
? const FlutterSecureStorage()
: null;

View file

@ -1,9 +1,12 @@
import 'package:matrix/matrix.dart';
import '../../config/app_config.dart';
import 'package:fluffychat/config/setting_keys.dart';
extension VisibleInGuiExtension on List<Event> {
List<Event> filterByVisibleInGui({String? exceptionEventId}) => where(
List<Event> filterByVisibleInGui({
String? exceptionEventId,
}) =>
where(
(event) => event.isVisibleInGui || event.eventId == exceptionEventId,
).toList();
}
@ -19,9 +22,9 @@ extension IsStateExtension on Event {
// if a reaction has been redacted we also want it to be hidden in the timeline
!{EventTypes.Reaction, EventTypes.Redaction}.contains(type) &&
// if we enabled to hide all redacted events, don't show those
(!AppConfig.hideRedactedEvents || !redacted) &&
(!AppSettings.hideRedactedEvents.value || !redacted) &&
// if we enabled to hide all unknown events, don't show those
(!AppConfig.hideUnknownEvents || isEventTypeKnown);
(!AppSettings.hideUnknownEvents.value || isEventTypeKnown);
bool get isState => !{
EventTypes.Message,

View file

@ -6,7 +6,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:matrix/matrix.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/l10n/l10n.dart';
@ -52,8 +51,7 @@ Future<String?> getDatabaseCipher() async {
}
void _sendNoEncryptionWarning(Object exception) async {
final store = await SharedPreferences.getInstance();
final isStored = AppSettings.noEncryptionWarningShown.getItem(store);
final isStored = AppSettings.noEncryptionWarningShown.value;
if (isStored == true) return;
@ -63,5 +61,5 @@ void _sendNoEncryptionWarning(Object exception) async {
exception.toString(),
);
await AppSettings.noEncryptionWarningShown.setItem(store, true);
await AppSettings.noEncryptionWarningShown.setItem(true);
}

View file

@ -6,7 +6,6 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_vodozemac/flutter_vodozemac.dart' as vod;
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/utils/client_download_content_extension.dart';
@ -59,7 +58,7 @@ void notificationTapBackground(
await vod.init();
_vodInitialized = true;
}
final store = await SharedPreferences.getInstance();
final store = await AppSettings.init();
final client = (await ClientManager.getClients(
initialize: false,
store: store,
@ -71,10 +70,6 @@ void notificationTapBackground(
waitUntilLoadCompletedLoaded: false,
);
AppConfig.sendPublicReadReceipts =
store.getBool(SettingKeys.sendPublicReadReceipts) ??
AppConfig.sendPublicReadReceipts;
if (!client.isLogged()) {
throw Exception('Notification tab in background but not logged in!');
}
@ -145,7 +140,7 @@ Future<void> notificationTap(
await room.setReadMarker(
payload.eventId ?? room.lastEvent!.eventId,
mRead: payload.eventId ?? room.lastEvent!.eventId,
public: AppConfig.sendPublicReadReceipts,
public: AppSettings.sendPublicReadReceipts.value,
);
case FluffyChatNotificationActions.reply:
final input = notificationResponse.input;

View file

@ -7,6 +7,7 @@ import 'package:go_router/go_router.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/l10n/l10n.dart';
import '../config/app_config.dart';
@ -36,7 +37,7 @@ abstract class PlatformInfos {
static bool get platformCanRecord => (isMobile || isMacOS);
static String get clientName =>
'${AppConfig.applicationName} ${isWeb ? 'web' : Platform.operatingSystem}${kReleaseMode ? '' : 'Debug'}';
'${AppSettings.applicationName.value} ${isWeb ? 'web' : Platform.operatingSystem}${kReleaseMode ? '' : 'Debug'}';
static Future<String> getVersion() async {
var version = kIsWeb ? 'Web' : 'Unknown';
@ -88,7 +89,7 @@ abstract class PlatformInfos {
height: 64,
filterQuality: FilterQuality.medium,
),
applicationName: AppConfig.applicationName,
applicationName: AppSettings.applicationName.value,
);
}
}

View file

@ -8,9 +8,9 @@ import 'package:collection/collection.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_shortcuts_new/flutter_shortcuts_new.dart';
import 'package:matrix/matrix.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/utils/client_download_content_extension.dart';
import 'package:fluffychat/utils/client_manager.dart';
@ -50,7 +50,7 @@ Future<void> pushHelper(
l10n.incomingMessages,
number: notification.counts?.unread,
ticker: l10n.unreadChatsInApp(
AppConfig.applicationName,
AppSettings.applicationName.value,
(notification.counts?.unread ?? 0).toString(),
),
importance: Importance.high,
@ -85,7 +85,7 @@ Future<void> _tryPushHelper(
client ??= (await ClientManager.getClients(
initialize: false,
store: await SharedPreferences.getInstance(),
store: await AppSettings.init(),
))
.first;
final event = await client.getEventByPushNotification(