refactor: Use AppSettings enum based configuration everywhere and fix load from json on web
This commit is contained in:
parent
4f0ed3e93f
commit
4c357f6249
46 changed files with 357 additions and 402 deletions
|
|
@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:desktop_notifications/desktop_notifications.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
|
|
@ -27,7 +26,6 @@ import 'package:fluffychat/utils/voip_plugin.dart';
|
|||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import '../config/app_config.dart';
|
||||
import '../config/setting_keys.dart';
|
||||
import '../pages/key_verification/key_verification_dialog.dart';
|
||||
import '../utils/account_bundles.dart';
|
||||
|
|
@ -155,7 +153,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
}
|
||||
final candidate =
|
||||
_loginClientCandidate ??= await ClientManager.createClient(
|
||||
'${AppConfig.applicationName}-${DateTime.now().millisecondsSinceEpoch}',
|
||||
'${AppSettings.applicationName.value}-${DateTime.now().millisecondsSinceEpoch}',
|
||||
store,
|
||||
)
|
||||
..onLoginStateChanged
|
||||
|
|
@ -221,24 +219,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
initMatrix();
|
||||
if (PlatformInfos.isWeb) {
|
||||
initConfig().then((_) => initSettings());
|
||||
} else {
|
||||
initSettings();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> initConfig() async {
|
||||
try {
|
||||
final configJsonString =
|
||||
utf8.decode((await http.get(Uri.parse('config.json'))).bodyBytes);
|
||||
final configJson = json.decode(configJsonString);
|
||||
AppConfig.loadFromJson(configJson);
|
||||
} on FormatException catch (_) {
|
||||
Logs().v('[ConfigLoader] config.json not found');
|
||||
} catch (e) {
|
||||
Logs().v('[ConfigLoader] config.json not found', e);
|
||||
}
|
||||
}
|
||||
|
||||
void _registerSubs(String name) {
|
||||
|
|
@ -358,7 +338,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
);
|
||||
}
|
||||
if (result == OkCancelResult.cancel) {
|
||||
await store.setBool(SettingKeys.showNoGoogle, true);
|
||||
await AppSettings.showNoGoogle.setItem(true);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
@ -368,7 +348,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
}
|
||||
|
||||
void createVoipPlugin() async {
|
||||
if (store.getBool(SettingKeys.experimentalVoip) == false) {
|
||||
if (AppSettings.experimentalVoip.value) {
|
||||
voipPlugin = null;
|
||||
return;
|
||||
}
|
||||
|
|
@ -390,55 +370,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
}
|
||||
}
|
||||
|
||||
void initSettings() {
|
||||
AppConfig.fontSizeFactor =
|
||||
double.tryParse(store.getString(SettingKeys.fontSizeFactor) ?? '') ??
|
||||
AppConfig.fontSizeFactor;
|
||||
|
||||
AppConfig.renderHtml =
|
||||
store.getBool(SettingKeys.renderHtml) ?? AppConfig.renderHtml;
|
||||
|
||||
AppConfig.swipeRightToLeftToReply =
|
||||
store.getBool(SettingKeys.swipeRightToLeftToReply) ??
|
||||
AppConfig.swipeRightToLeftToReply;
|
||||
|
||||
AppConfig.hideRedactedEvents =
|
||||
store.getBool(SettingKeys.hideRedactedEvents) ??
|
||||
AppConfig.hideRedactedEvents;
|
||||
|
||||
AppConfig.hideUnknownEvents =
|
||||
store.getBool(SettingKeys.hideUnknownEvents) ??
|
||||
AppConfig.hideUnknownEvents;
|
||||
|
||||
AppConfig.separateChatTypes =
|
||||
store.getBool(SettingKeys.separateChatTypes) ??
|
||||
AppConfig.separateChatTypes;
|
||||
|
||||
AppConfig.autoplayImages =
|
||||
store.getBool(SettingKeys.autoplayImages) ?? AppConfig.autoplayImages;
|
||||
|
||||
AppConfig.sendTypingNotifications =
|
||||
store.getBool(SettingKeys.sendTypingNotifications) ??
|
||||
AppConfig.sendTypingNotifications;
|
||||
|
||||
AppConfig.sendPublicReadReceipts =
|
||||
store.getBool(SettingKeys.sendPublicReadReceipts) ??
|
||||
AppConfig.sendPublicReadReceipts;
|
||||
|
||||
AppConfig.sendOnEnter =
|
||||
store.getBool(SettingKeys.sendOnEnter) ?? AppConfig.sendOnEnter;
|
||||
|
||||
AppConfig.experimentalVoip = store.getBool(SettingKeys.experimentalVoip) ??
|
||||
AppConfig.experimentalVoip;
|
||||
|
||||
AppConfig.showPresences =
|
||||
store.getBool(SettingKeys.showPresences) ?? AppConfig.showPresences;
|
||||
|
||||
AppConfig.displayNavigationRail =
|
||||
store.getBool(SettingKeys.displayNavigationRail) ??
|
||||
AppConfig.displayNavigationRail;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue