feat: Add advanced configuration page
This commit is contained in:
parent
b94893be18
commit
730fb22be3
5 changed files with 177 additions and 9 deletions
|
|
@ -31,6 +31,7 @@ import 'package:fluffychat/pages/settings_notifications/settings_notifications.d
|
||||||
import 'package:fluffychat/pages/settings_password/settings_password.dart';
|
import 'package:fluffychat/pages/settings_password/settings_password.dart';
|
||||||
import 'package:fluffychat/pages/settings_security/settings_security.dart';
|
import 'package:fluffychat/pages/settings_security/settings_security.dart';
|
||||||
import 'package:fluffychat/pages/settings_style/settings_style.dart';
|
import 'package:fluffychat/pages/settings_style/settings_style.dart';
|
||||||
|
import 'package:fluffychat/widgets/config_viewer.dart';
|
||||||
import 'package:fluffychat/widgets/layouts/empty_page.dart';
|
import 'package:fluffychat/widgets/layouts/empty_page.dart';
|
||||||
import 'package:fluffychat/widgets/layouts/two_column_layout.dart';
|
import 'package:fluffychat/widgets/layouts/two_column_layout.dart';
|
||||||
import 'package:fluffychat/widgets/log_view.dart';
|
import 'package:fluffychat/widgets/log_view.dart';
|
||||||
|
|
@ -86,6 +87,14 @@ abstract class AppRoutes {
|
||||||
const LogViewer(),
|
const LogViewer(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/configs',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
state,
|
||||||
|
const ConfigViewer(),
|
||||||
|
),
|
||||||
|
),
|
||||||
ShellRoute(
|
ShellRoute(
|
||||||
// Never use a transition on the shell route. Changing the PageBuilder
|
// Never use a transition on the shell route. Changing the PageBuilder
|
||||||
// here based on a MediaQuery causes the child to briefly be rendered
|
// here based on a MediaQuery causes the child to briefly be rendered
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
abstract class SettingKeys {
|
abstract class SettingKeys {
|
||||||
static const String renderHtml = 'chat.fluffy.renderHtml';
|
static const String renderHtml = 'chat.fluffy.renderHtml';
|
||||||
static const String hideRedactedEvents = 'chat.fluffy.hideRedactedEvents';
|
static const String hideRedactedEvents = 'chat.fluffy.hideRedactedEvents';
|
||||||
|
|
@ -36,3 +38,43 @@ abstract class SettingKeys {
|
||||||
'chat.fluffy.no_encryption_warning_shown';
|
'chat.fluffy.no_encryption_warning_shown';
|
||||||
static const String shareKeysWith = 'chat.fluffy.share_keys_with';
|
static const String shareKeysWith = 'chat.fluffy.share_keys_with';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum AppSettings<T> {
|
||||||
|
audioRecordingNumChannels<int>('audioRecordingNumChannels', 1),
|
||||||
|
audioRecordingAutoGain<bool>('audioRecordingAutoGain', true),
|
||||||
|
audioRecordingEchoCancel<bool>('audioRecordingEchoCancel', true),
|
||||||
|
audioRecordingNoiseSuppress<bool>('audioRecordingNoiseSuppress', true),
|
||||||
|
audioRecordingBitRate<int>('audioRecordingBitRate', 64000),
|
||||||
|
audioRecordingSamplingRate<int>('audioRecordingSamplingRate', 44100);
|
||||||
|
|
||||||
|
final String key;
|
||||||
|
final T defaultValue;
|
||||||
|
|
||||||
|
const AppSettings(this.key, this.defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppSettingsBoolExtension on AppSettings<bool> {
|
||||||
|
bool getItem(SharedPreferences store) => store.getBool(key) ?? defaultValue;
|
||||||
|
Future<void> setItem(SharedPreferences store, bool value) =>
|
||||||
|
store.setBool(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppSettingsStringExtension on AppSettings<String> {
|
||||||
|
String getItem(SharedPreferences store) =>
|
||||||
|
store.getString(key) ?? defaultValue;
|
||||||
|
Future<void> setItem(SharedPreferences store, String value) =>
|
||||||
|
store.setString(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppSettingsIntExtension on AppSettings<int> {
|
||||||
|
int getItem(SharedPreferences store) => store.getInt(key) ?? defaultValue;
|
||||||
|
Future<void> setItem(SharedPreferences store, int value) =>
|
||||||
|
store.setInt(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppSettingsDoubleExtension on AppSettings<double> {
|
||||||
|
double getItem(SharedPreferences store) =>
|
||||||
|
store.getDouble(key) ?? defaultValue;
|
||||||
|
Future<void> setItem(SharedPreferences store, double value) =>
|
||||||
|
store.setDouble(key, value);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@ import 'package:record/record.dart';
|
||||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
|
import 'package:fluffychat/config/setting_keys.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
import 'events/audio_player.dart';
|
import 'events/audio_player.dart';
|
||||||
|
|
||||||
class RecordingDialog extends StatefulWidget {
|
class RecordingDialog extends StatefulWidget {
|
||||||
|
|
@ -34,10 +36,8 @@ class RecordingDialogState extends State<RecordingDialog> {
|
||||||
|
|
||||||
String? fileName;
|
String? fileName;
|
||||||
|
|
||||||
static const int bitRate = 64000;
|
|
||||||
static const int samplingRate = 44100;
|
|
||||||
|
|
||||||
Future<void> startRecording() async {
|
Future<void> startRecording() async {
|
||||||
|
final store = Matrix.of(context).store;
|
||||||
try {
|
try {
|
||||||
final codec = kIsWeb
|
final codec = kIsWeb
|
||||||
// Web seems to create webm instead of ogg when using opus encoder
|
// Web seems to create webm instead of ogg when using opus encoder
|
||||||
|
|
@ -64,12 +64,12 @@ class RecordingDialogState extends State<RecordingDialog> {
|
||||||
|
|
||||||
await _audioRecorder.start(
|
await _audioRecorder.start(
|
||||||
RecordConfig(
|
RecordConfig(
|
||||||
bitRate: bitRate,
|
bitRate: AppSettings.audioRecordingBitRate.getItem(store),
|
||||||
sampleRate: samplingRate,
|
sampleRate: AppSettings.audioRecordingSamplingRate.getItem(store),
|
||||||
numChannels: 1,
|
numChannels: AppSettings.audioRecordingNumChannels.getItem(store),
|
||||||
autoGain: true,
|
autoGain: AppSettings.audioRecordingAutoGain.getItem(store),
|
||||||
echoCancel: true,
|
echoCancel: AppSettings.audioRecordingEchoCancel.getItem(store),
|
||||||
noiseSuppress: true,
|
noiseSuppress: AppSettings.audioRecordingNoiseSuppress.getItem(store),
|
||||||
encoder: codec,
|
encoder: codec,
|
||||||
),
|
),
|
||||||
path: path ?? '',
|
path: path ?? '',
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,18 @@ abstract class PlatformInfos {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Builder(
|
||||||
|
builder: (innerContext) {
|
||||||
|
return TextButton.icon(
|
||||||
|
onPressed: () {
|
||||||
|
context.go('/configs');
|
||||||
|
Navigator.of(innerContext).pop();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.settings_applications_outlined),
|
||||||
|
label: const Text('Advanced Configs'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
applicationIcon: Image.asset(
|
applicationIcon: Image.asset(
|
||||||
'assets/logo.png',
|
'assets/logo.png',
|
||||||
|
|
|
||||||
105
lib/widgets/config_viewer.dart
Normal file
105
lib/widgets/config_viewer.dart
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/config/setting_keys.dart';
|
||||||
|
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
|
class ConfigViewer extends StatelessWidget {
|
||||||
|
const ConfigViewer({super.key});
|
||||||
|
|
||||||
|
void _changeSetting(
|
||||||
|
BuildContext context,
|
||||||
|
AppSettings appSetting,
|
||||||
|
SharedPreferences store,
|
||||||
|
Function setState,
|
||||||
|
) async {
|
||||||
|
final value = await showTextInputDialog(
|
||||||
|
context: context,
|
||||||
|
title: appSetting.name,
|
||||||
|
initialText: appSetting.defaultValue.toString(),
|
||||||
|
);
|
||||||
|
if (value == null) return;
|
||||||
|
|
||||||
|
if (appSetting is AppSettings<String>) {
|
||||||
|
appSetting.setItem(store, value);
|
||||||
|
}
|
||||||
|
if (appSetting is AppSettings<bool>) {
|
||||||
|
appSetting.setItem(store, value == 'true');
|
||||||
|
}
|
||||||
|
if (appSetting is AppSettings<int>) {
|
||||||
|
appSetting.setItem(store, int.parse(value));
|
||||||
|
}
|
||||||
|
if (appSetting is AppSettings<double>) {
|
||||||
|
appSetting.setItem(store, double.parse(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Advanced configurations'),
|
||||||
|
leading: BackButton(
|
||||||
|
onPressed: () => context.go('/'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.all(16),
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
color: theme.colorScheme.errorContainer,
|
||||||
|
child: Text(
|
||||||
|
'Changing configs by hand is untested! Use without any warranty!',
|
||||||
|
style: TextStyle(
|
||||||
|
color: theme.colorScheme.onErrorContainer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: StatefulBuilder(
|
||||||
|
builder: (context, setState) {
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: AppSettings.values.length,
|
||||||
|
itemBuilder: (context, i) {
|
||||||
|
final store = Matrix.of(context).store;
|
||||||
|
final appSetting = AppSettings.values[i];
|
||||||
|
var value = '';
|
||||||
|
if (appSetting is AppSettings<String>) {
|
||||||
|
value = appSetting.getItem(store);
|
||||||
|
}
|
||||||
|
if (appSetting is AppSettings<int>) {
|
||||||
|
value = appSetting.getItem(store).toString();
|
||||||
|
}
|
||||||
|
if (appSetting is AppSettings<bool>) {
|
||||||
|
value = appSetting.getItem(store).toString();
|
||||||
|
}
|
||||||
|
if (appSetting is AppSettings<double>) {
|
||||||
|
value = appSetting.getItem(store).toString();
|
||||||
|
}
|
||||||
|
return ListTile(
|
||||||
|
title: Text(appSetting.name),
|
||||||
|
subtitle: Text(value),
|
||||||
|
onTap: () => _changeSetting(
|
||||||
|
context,
|
||||||
|
appSetting,
|
||||||
|
store,
|
||||||
|
setState,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue