[ui] Add auto-mount on first launch functionality #52
This commit is contained in:
@@ -21,6 +21,7 @@ class Mount with ChangeNotifier {
|
||||
refresh();
|
||||
}
|
||||
|
||||
bool get autoStart => mountConfig.autoStart;
|
||||
String? get bucket => mountConfig.bucket;
|
||||
String get id => '${type}_$name';
|
||||
bool? get mounted => mountConfig.mounted;
|
||||
@@ -101,6 +102,35 @@ class Mount with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setMountAutoStart(bool autoStart) async {
|
||||
try {
|
||||
mountConfig.autoStart = autoStart;
|
||||
|
||||
final auth = await _auth.createAuth();
|
||||
final response = await http.put(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
'${getBaseUri()}/api/v1/mount_location?auth=$auth&name=$name&type=$type&auto_start=$autoStart',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 401) {
|
||||
_auth.logoff();
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.statusCode == 404) {
|
||||
_mountList?.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
return refresh();
|
||||
} catch (e) {
|
||||
debugPrint('$e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setMountLocation(String location) async {
|
||||
try {
|
||||
mountConfig.path = location;
|
||||
|
@@ -3,6 +3,7 @@ import 'package:repertory/helpers.dart' show initialCaps;
|
||||
|
||||
class MountConfig {
|
||||
bool? mounted;
|
||||
bool autoStart = false;
|
||||
final String _name;
|
||||
String path = '';
|
||||
Map<String, dynamic> _settings = {};
|
||||
@@ -30,6 +31,9 @@ class MountConfig {
|
||||
}
|
||||
|
||||
void updateStatus(Map<String, dynamic> status) {
|
||||
autoStart = status.containsKey('AutoStart')
|
||||
? status['AutoStart'] as bool
|
||||
: false;
|
||||
path = status['Location'] as String;
|
||||
mounted = status['Active'] as bool;
|
||||
}
|
||||
|
@@ -35,6 +35,11 @@ class _MountWidgetState extends State<MountWidget>
|
||||
);
|
||||
final subStyle = textTheme.bodyMedium?.copyWith(color: scheme.onSurface);
|
||||
|
||||
final visualDensity = VisualDensity(
|
||||
horizontal: -VisualDensity.maximumDensity,
|
||||
vertical: -(VisualDensity.maximumDensity * 2.0),
|
||||
);
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 120),
|
||||
child: Card(
|
||||
@@ -141,6 +146,43 @@ class _MountWidgetState extends State<MountWidget>
|
||||
style: subStyle,
|
||||
),
|
||||
),
|
||||
IntrinsicWidth(
|
||||
child: Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
listTileTheme: const ListTileThemeData(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
horizontalTitleGap: 0,
|
||||
minLeadingWidth: 0,
|
||||
minVerticalPadding: 0,
|
||||
),
|
||||
checkboxTheme: CheckboxThemeData(
|
||||
materialTapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
visualDensity: visualDensity,
|
||||
),
|
||||
),
|
||||
child: CheckboxListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
materialTapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
onChanged: (_) {},
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: const [
|
||||
Icon(
|
||||
Icons.auto_mode,
|
||||
size: constants.smallIconSize,
|
||||
),
|
||||
SizedBox(width: constants.paddingSmall),
|
||||
Text('Auto-mount'),
|
||||
SizedBox(width: constants.paddingSmall),
|
||||
],
|
||||
),
|
||||
value: mount.autoStart,
|
||||
visualDensity: visualDensity,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
Reference in New Issue
Block a user