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:
@@ -27,6 +27,7 @@ class AudioDeviceListTile extends StatefulWidget {
|
||||
AudioDeviceListLoader? loadDevices,
|
||||
AudioDeviceSetter? setInputDevice,
|
||||
AudioDeviceSetter? setOutputDevice,
|
||||
this.onDeviceChanged,
|
||||
}) : loadDevices = loadDevices ?? rust.listAudioDevices,
|
||||
setInputDevice = setInputDevice ?? rust.setInputDevice,
|
||||
setOutputDevice = setOutputDevice ?? rust.setOutputDevice;
|
||||
@@ -46,6 +47,10 @@ class AudioDeviceListTile extends StatefulWidget {
|
||||
/// Selects an output device.
|
||||
final AudioDeviceSetter setOutputDevice;
|
||||
|
||||
/// Called after a device selection succeeds. Receives the device id
|
||||
/// (null for system default).
|
||||
final ValueChanged<String?>? onDeviceChanged;
|
||||
|
||||
@override
|
||||
State<AudioDeviceListTile> createState() => _AudioDeviceListTileState();
|
||||
}
|
||||
@@ -88,6 +93,7 @@ class _AudioDeviceListTileState extends State<AudioDeviceListTile> {
|
||||
setState(() {
|
||||
_selectedDeviceId = deviceId;
|
||||
});
|
||||
widget.onDeviceChanged?.call(deviceId);
|
||||
|
||||
final selectedName = _selectedDevice?.name ?? 'System default';
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../l10n/generated/app_localizations.dart';
|
||||
import '../services/channel_spacer.dart';
|
||||
@@ -571,11 +572,40 @@ class _ClientVolumePreference {
|
||||
}
|
||||
|
||||
class _ClientVolumePreferences extends ChangeNotifier {
|
||||
_ClientVolumePreferences._();
|
||||
_ClientVolumePreferences._() {
|
||||
_load();
|
||||
}
|
||||
|
||||
static final instance = _ClientVolumePreferences._();
|
||||
|
||||
static const _prefsKey = 'client_volume_prefs';
|
||||
|
||||
final Map<BigInt, _ClientVolumePreference> _byClientId = {};
|
||||
bool _loaded = false;
|
||||
|
||||
Future<void> _load() async {
|
||||
if (_loaded) return;
|
||||
_loaded = true;
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final raw = prefs.getStringList(_prefsKey) ?? const [];
|
||||
for (final entry in raw) {
|
||||
final parts = entry.split(':');
|
||||
if (parts.length == 3) {
|
||||
final id = BigInt.tryParse(parts[0]);
|
||||
final volume = double.tryParse(parts[1]);
|
||||
final muted = parts[2] == '1';
|
||||
if (id != null && volume != null) {
|
||||
_byClientId[id] = _ClientVolumePreference(
|
||||
volume: volume,
|
||||
muted: muted,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
_ClientVolumePreference preferenceFor(BigInt clientId) {
|
||||
return _byClientId[clientId] ?? const _ClientVolumePreference();
|
||||
@@ -588,6 +618,17 @@ class _ClientVolumePreferences extends ChangeNotifier {
|
||||
_byClientId.remove(clientId);
|
||||
}
|
||||
notifyListeners();
|
||||
_save();
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final raw = _byClientId.entries
|
||||
.map((e) => '${e.key}:${e.value.volume}:${e.value.muted ? 1 : 0}')
|
||||
.toList();
|
||||
await prefs.setStringList(_prefsKey, raw);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ class VoiceSettingsDialog extends StatefulWidget {
|
||||
this.talkPower,
|
||||
this.neededTalkPower,
|
||||
this.talkPowerGranted,
|
||||
this.onInputDeviceChanged,
|
||||
this.onOutputDeviceChanged,
|
||||
});
|
||||
|
||||
final rust.BridgeTransmitMode initialMode;
|
||||
@@ -58,6 +60,8 @@ class VoiceSettingsDialog extends StatefulWidget {
|
||||
final int? talkPower;
|
||||
final int? neededTalkPower;
|
||||
final bool? talkPowerGranted;
|
||||
final ValueChanged<String?>? onInputDeviceChanged;
|
||||
final ValueChanged<String?>? onOutputDeviceChanged;
|
||||
|
||||
@override
|
||||
State<VoiceSettingsDialog> createState() => _VoiceSettingsDialogState();
|
||||
@@ -207,13 +211,15 @@ class _VoiceSettingsDialogState extends State<VoiceSettingsDialog> {
|
||||
if (!isAndroidHost && !isIosHost) ...[
|
||||
const Divider(height: 24),
|
||||
const VoiceSectionHeader('Audio devices'),
|
||||
const AudioDeviceListTile(
|
||||
AudioDeviceListTile(
|
||||
label: 'Input',
|
||||
kind: AudioDeviceKind.input,
|
||||
onDeviceChanged: widget.onInputDeviceChanged,
|
||||
),
|
||||
const AudioDeviceListTile(
|
||||
AudioDeviceListTile(
|
||||
label: 'Output',
|
||||
kind: AudioDeviceKind.output,
|
||||
onDeviceChanged: widget.onOutputDeviceChanged,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user