feat(flutter): persist voice settings and per-user volume (TODO-039,040)
Add SharedPreferences persistence for transmit mode, release tail, input/output device. Per-user volume/mute persisted across sessions.
This commit is contained in:
@@ -18,11 +18,19 @@ class UiSettings {
|
||||
this.host = '',
|
||||
this.nickname = '',
|
||||
this.themeMode = UiThemeMode.system,
|
||||
this.transmitModeIndex,
|
||||
this.releaseTailMs,
|
||||
this.inputDeviceId,
|
||||
this.outputDeviceId,
|
||||
});
|
||||
|
||||
final String host;
|
||||
final String nickname;
|
||||
final UiThemeMode themeMode;
|
||||
final int? transmitModeIndex;
|
||||
final int? releaseTailMs;
|
||||
final String? inputDeviceId;
|
||||
final String? outputDeviceId;
|
||||
}
|
||||
|
||||
class UiPreferencesService {
|
||||
@@ -30,6 +38,10 @@ class UiPreferencesService {
|
||||
static const _nicknameKey = 'ui.nickname';
|
||||
static const _themeModeKey = 'ui.theme_mode';
|
||||
static const _permissionsExplainedKey = 'perms_explained';
|
||||
static const _transmitModeIndexKey = 'voice.transmit_mode_index';
|
||||
static const _releaseTailMsKey = 'voice.release_tail_ms';
|
||||
static const _inputDeviceIdKey = 'audio.input_device_id';
|
||||
static const _outputDeviceIdKey = 'audio.output_device_id';
|
||||
|
||||
const UiPreferencesService();
|
||||
|
||||
@@ -39,6 +51,10 @@ class UiPreferencesService {
|
||||
host: prefs.getString(_hostKey) ?? '',
|
||||
nickname: prefs.getString(_nicknameKey) ?? '',
|
||||
themeMode: UiThemeMode.fromStorage(prefs.getString(_themeModeKey)),
|
||||
transmitModeIndex: prefs.getInt(_transmitModeIndexKey),
|
||||
releaseTailMs: prefs.getInt(_releaseTailMsKey),
|
||||
inputDeviceId: prefs.getString(_inputDeviceIdKey),
|
||||
outputDeviceId: prefs.getString(_outputDeviceIdKey),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,6 +69,34 @@ class UiPreferencesService {
|
||||
await prefs.setString(_themeModeKey, themeMode.name);
|
||||
}
|
||||
|
||||
Future<void> saveTransmitModeIndex(int index) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_transmitModeIndexKey, index);
|
||||
}
|
||||
|
||||
Future<void> saveReleaseTailMs(int ms) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_releaseTailMsKey, ms);
|
||||
}
|
||||
|
||||
Future<void> saveInputDeviceId(String? id) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (id == null) {
|
||||
await prefs.remove(_inputDeviceIdKey);
|
||||
} else {
|
||||
await prefs.setString(_inputDeviceIdKey, id);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveOutputDeviceId(String? id) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (id == null) {
|
||||
await prefs.remove(_outputDeviceIdKey);
|
||||
} else {
|
||||
await prefs.setString(_outputDeviceIdKey, id);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> hasExplainedPermissions() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getBool(_permissionsExplainedKey) ?? false;
|
||||
|
||||
Reference in New Issue
Block a user