grab mount settings and status

This commit is contained in:
2025-03-01 10:34:13 -06:00
parent 7d441964e9
commit 0aeb69a050
4 changed files with 141 additions and 75 deletions

View File

@ -7,7 +7,7 @@ import 'package:repertory/types/mount_config.dart';
class Mount with ChangeNotifier {
final MountConfig mountConfig;
Mount(this.mountConfig) {
_fetch();
refresh();
}
String get name => mountConfig.name;
@ -20,15 +20,33 @@ class Mount with ChangeNotifier {
),
);
if (response.statusCode == 200) {
mountConfig.updateSettings(jsonDecode(response.body));
notifyListeners();
if (response.statusCode != 200) {
return;
}
mountConfig.updateSettings(jsonDecode(response.body));
notifyListeners();
}
void refresh() {
_fetch();
Future<void> _fetchStatus() async {
final response = await http.get(
Uri.parse(
Uri.encodeFull(
'${Uri.base.origin}/api/v1/mount_status?name=$name&type=$type',
),
),
);
if (response.statusCode != 200) {
return;
}
mountConfig.updateStatus(jsonDecode(response.body));
}
Future<void> refresh() async {
await _fetch();
return _fetchStatus();
}
}

View File

@ -4,9 +4,12 @@ class MountConfig {
final String _name;
final String _type;
Map<String, dynamic> _settings = {};
Map<String, dynamic> _status = {};
MountConfig({required name, required type}) : _name = name, _type = type;
UnmodifiableMapView get items => UnmodifiableMapView(_settings);
UnmodifiableMapView get settings => UnmodifiableMapView(_settings);
UnmodifiableMapView get status => UnmodifiableMapView(_status);
String get name => _name;
String get type => _type;
@ -17,4 +20,8 @@ class MountConfig {
void updateSettings(Map<String, dynamic> settings) {
_settings = settings;
}
void updateStatus(Map<String, dynamic> status) {
_status = status;
}
}