diff --git a/web/repertory/lib/helpers.dart b/web/repertory/lib/helpers.dart index 6b9e174f..4455edd3 100644 --- a/web/repertory/lib/helpers.dart +++ b/web/repertory/lib/helpers.dart @@ -96,7 +96,7 @@ Map createDefaultSettings(String mountType) { return {}; } -void displayErrorMessage(context, text) { +void displayErrorMessage(context, String text) { if (!context.mounted) { return; } diff --git a/web/repertory/lib/main.dart b/web/repertory/lib/main.dart index 199a5773..c45e91ce 100644 --- a/web/repertory/lib/main.dart +++ b/web/repertory/lib/main.dart @@ -62,7 +62,7 @@ class _MyAppState extends State { return EditMountScreen( mount: mount, title: - '${initialCaps(mount.type)} [${formatMountName(mount.type, mount.name)}] Settings', + '${mount.provider} [${formatMountName(mount.type, mount.name)}] Settings', ); }, ); diff --git a/web/repertory/lib/models/mount.dart b/web/repertory/lib/models/mount.dart index 1f9d7641..93a6b323 100644 --- a/web/repertory/lib/models/mount.dart +++ b/web/repertory/lib/models/mount.dart @@ -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 _fetch() async { @@ -76,7 +77,7 @@ class Mount with ChangeNotifier { Future mount(bool unmount, {String? location}) async { try { - mountConfig.state = null; + mountConfig.mounted = null; notifyListeners(); final response = await http.post( diff --git a/web/repertory/lib/types/mount_config.dart b/web/repertory/lib/types/mount_config.dart index 17421569..8a6a10d1 100644 --- a/web/repertory/lib/types/mount_config.dart +++ b/web/repertory/lib/types/mount_config.dart @@ -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 _settings = {}; - IconData? _state; final String _type; MountConfig({required name, required type, Map? 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 get settings => UnmodifiableMapView(_settings); - IconData? get state => _state; - set state(value) => _state = value; String get type => _type; void updateSettings(Map settings) { @@ -32,6 +29,6 @@ class MountConfig { void updateStatus(Map status) { _path = status['Location'] as String; - _state = status['Active'] as bool ? Icons.toggle_on : Icons.toggle_off; + mounted = status['Active'] as bool; } } diff --git a/web/repertory/lib/widgets/mount_widget.dart b/web/repertory/lib/widgets/mount_widget.dart index f6599d32..f7a1871b 100644 --- a/web/repertory/lib/widgets/mount_widget.dart +++ b/web/repertory/lib/widgets/mount_widget.dart @@ -24,14 +24,13 @@ class _MountWidgetState extends State { return Card( margin: const EdgeInsets.all(0.0), child: Consumer( - 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 { children: [ nameText, SelectableText( - mount.path.isEmpty && mount.state == null + mount.path.isEmpty && mount.mounted == null ? 'loading...' : mount.path.isEmpty ? '' @@ -59,16 +58,22 @@ class _MountWidgetState extends State { ], ), 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 { ); } - 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 { }); } - 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 { super.dispose(); } - Future _getMountLocation(context, mount, isMounted) async { - if (isMounted) { + Future _getMountLocation(context, Mount mount) async { + if (mount.mounted ?? false) { return null; } - if (!mount.path.isEmpty) { + if (mount.path.isNotEmpty) { return mount.path; }