This commit is contained in:
parent
d7a0fd9d8c
commit
c720181208
@ -96,7 +96,7 @@ Map<String, dynamic> createDefaultSettings(String mountType) {
|
||||
return {};
|
||||
}
|
||||
|
||||
void displayErrorMessage(context, text) {
|
||||
void displayErrorMessage(context, String text) {
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class _MyAppState extends State<MyApp> {
|
||||
return EditMountScreen(
|
||||
mount: mount,
|
||||
title:
|
||||
'${initialCaps(mount.type)} [${formatMountName(mount.type, mount.name)}] Settings',
|
||||
'${mount.provider} [${formatMountName(mount.type, mount.name)}] Settings',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@ -18,9 +18,10 @@ class Mount with ChangeNotifier {
|
||||
|
||||
String? get bucket => mountConfig.bucket;
|
||||
String get id => '${type}_$name';
|
||||
bool? get mounted => mountConfig.mounted;
|
||||
String get name => mountConfig.name;
|
||||
String get path => mountConfig.path;
|
||||
IconData? get state => mountConfig.state;
|
||||
String get provider => mountConfig.provider;
|
||||
String get type => mountConfig.type;
|
||||
|
||||
Future<void> _fetch() async {
|
||||
@ -76,7 +77,7 @@ class Mount with ChangeNotifier {
|
||||
|
||||
Future<bool> mount(bool unmount, {String? location}) async {
|
||||
try {
|
||||
mountConfig.state = null;
|
||||
mountConfig.mounted = null;
|
||||
notifyListeners();
|
||||
|
||||
final response = await http.post(
|
||||
|
@ -1,12 +1,11 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:repertory/helpers.dart' show initialCaps;
|
||||
|
||||
class MountConfig {
|
||||
bool? mounted;
|
||||
final String _name;
|
||||
String _path = '';
|
||||
Map<String, dynamic> _settings = {};
|
||||
IconData? _state;
|
||||
final String _type;
|
||||
MountConfig({required name, required type, Map<String, dynamic>? settings})
|
||||
: _name = name,
|
||||
@ -16,14 +15,12 @@ class MountConfig {
|
||||
}
|
||||
}
|
||||
|
||||
String? get bucket =>
|
||||
_settings['${initialCaps(_type)}Config']?["Bucket"] as String;
|
||||
String? get bucket => _settings['${provider}Config']?["Bucket"] as String;
|
||||
String get name => _name;
|
||||
String get path => _path;
|
||||
String get provider => initialCaps(_type);
|
||||
UnmodifiableMapView<String, dynamic> get settings =>
|
||||
UnmodifiableMapView<String, dynamic>(_settings);
|
||||
IconData? get state => _state;
|
||||
set state(value) => _state = value;
|
||||
String get type => _type;
|
||||
|
||||
void updateSettings(Map<String, dynamic> settings) {
|
||||
@ -32,6 +29,6 @@ class MountConfig {
|
||||
|
||||
void updateStatus(Map<String, dynamic> status) {
|
||||
_path = status['Location'] as String;
|
||||
_state = status['Active'] as bool ? Icons.toggle_on : Icons.toggle_off;
|
||||
mounted = status['Active'] as bool;
|
||||
}
|
||||
}
|
||||
|
@ -24,14 +24,13 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
return Card(
|
||||
margin: const EdgeInsets.all(0.0),
|
||||
child: Consumer<Mount>(
|
||||
builder: (context, mount, _) {
|
||||
builder: (context, Mount mount, _) {
|
||||
final textColor = Theme.of(context).colorScheme.onSurface;
|
||||
final subTextColor =
|
||||
Theme.of(context).brightness == Brightness.dark
|
||||
? Colors.white38
|
||||
: Colors.black87;
|
||||
|
||||
final isMounted = mount.state == Icons.toggle_on;
|
||||
final nameText = SelectableText(
|
||||
formatMountName(mount.type, mount.name),
|
||||
style: TextStyle(color: subTextColor),
|
||||
@ -49,7 +48,7 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
children: [
|
||||
nameText,
|
||||
SelectableText(
|
||||
mount.path.isEmpty && mount.state == null
|
||||
mount.path.isEmpty && mount.mounted == null
|
||||
? 'loading...'
|
||||
: mount.path.isEmpty
|
||||
? '<mount location not set>'
|
||||
@ -59,16 +58,22 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
],
|
||||
),
|
||||
title: SelectableText(
|
||||
initialCaps(mount.type),
|
||||
mount.provider,
|
||||
style: TextStyle(color: textColor, fontWeight: FontWeight.bold),
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: Icon(
|
||||
mount.state ?? Icons.hourglass_top,
|
||||
mount.mounted == null
|
||||
? Icons.hourglass_top
|
||||
: mount.mounted!
|
||||
? Icons.toggle_on
|
||||
: Icons.toggle_off,
|
||||
color:
|
||||
isMounted ? Color.fromARGB(255, 163, 96, 76) : subTextColor,
|
||||
mount.mounted ?? false
|
||||
? Color.fromARGB(255, 163, 96, 76)
|
||||
: subTextColor,
|
||||
),
|
||||
onPressed: _createMountHandler(context, isMounted, mount),
|
||||
onPressed: _createMountHandler(context, mount),
|
||||
),
|
||||
);
|
||||
},
|
||||
@ -76,14 +81,14 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
VoidCallback? _createMountHandler(context, isMounted, mount) {
|
||||
return _enabled && mount.state != null
|
||||
VoidCallback? _createMountHandler(context, Mount mount) {
|
||||
return _enabled && mount.mounted != null
|
||||
? () async {
|
||||
setState(() {
|
||||
_enabled = false;
|
||||
});
|
||||
|
||||
final location = await _getMountLocation(context, mount, isMounted);
|
||||
final location = await _getMountLocation(context, mount);
|
||||
|
||||
cleanup() {
|
||||
setState(() {
|
||||
@ -91,15 +96,15 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
if (!isMounted && location == null) {
|
||||
if (!mount.mounted! && location == null) {
|
||||
displayErrorMessage(context, "Mount location is not set");
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
final success = await mount.mount(isMounted, location: location);
|
||||
final success = await mount.mount(mount.mounted!, location: location);
|
||||
|
||||
if (success ||
|
||||
isMounted ||
|
||||
mount.mounted! ||
|
||||
constants.navigatorKey.currentContext == null ||
|
||||
!constants.navigatorKey.currentContext!.mounted) {
|
||||
return cleanup();
|
||||
@ -118,12 +123,12 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<String?> _getMountLocation(context, mount, isMounted) async {
|
||||
if (isMounted) {
|
||||
Future<String?> _getMountLocation(context, Mount mount) async {
|
||||
if (mount.mounted ?? false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!mount.path.isEmpty) {
|
||||
if (mount.path.isNotEmpty) {
|
||||
return mount.path;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user