Compare commits

..

No commits in common. "b93e2978b0239ad8704d0a27d8b651a766d7641a" and "7605be809c0da9e52437616ddf71e97d5c94e39d" have entirely different histories.

3 changed files with 17 additions and 45 deletions

View File

@ -334,7 +334,6 @@ void handlers::handle_post_mount(auto &&req, auto &&res) const {
} else { } else {
if (not utils::file::directory{location}.exists()) { if (not utils::file::directory{location}.exists()) {
res.status = http_error_codes::internal_error; res.status = http_error_codes::internal_error;
return;
} }
launch_process(prov, name, fmt::format(R"("{}")", location), true); launch_process(prov, name, fmt::format(R"("{}")", location), true);

View File

@ -2,7 +2,6 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:repertory/constants.dart' as constants;
import 'package:repertory/helpers.dart'; import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount_list.dart'; import 'package:repertory/models/mount_list.dart';
import 'package:repertory/types/mount_config.dart'; import 'package:repertory/types/mount_config.dart';
@ -74,9 +73,9 @@ class Mount with ChangeNotifier {
} }
} }
Future<bool> mount(bool unmount, {String? location}) async { Future<void> mount(bool unmount, {String? location}) async {
try { try {
final response = await http.post( await http.post(
Uri.parse( Uri.parse(
Uri.encodeFull( Uri.encodeFull(
'${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location', '${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
@ -84,16 +83,10 @@ class Mount with ChangeNotifier {
), ),
); );
if (!unmount && response.statusCode == 500) { return refresh();
return false;
}
await refresh();
} catch (e) { } catch (e) {
debugPrint('$e'); debugPrint('$e');
} }
return true;
} }
Future<void> refresh() async { Future<void> refresh() async {

View File

@ -4,7 +4,6 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:repertory/constants.dart' as constants;
import 'package:repertory/helpers.dart'; import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount.dart'; import 'package:repertory/models/mount.dart';
@ -141,15 +140,9 @@ class _MountWidgetState extends State<MountWidget> {
} }
} }
cleanup() {
setState(() {
_enabled = true;
});
}
if (location == null) { if (location == null) {
if (!context.mounted) { if (!context.mounted) {
return cleanup(); return;
} }
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@ -160,34 +153,21 @@ class _MountWidgetState extends State<MountWidget> {
), ),
), ),
); );
return;
return cleanup();
} }
final success = await mount.mount( mount
isActive, .mount(isActive, location: location)
location: location, .then((_) {
); setState(() {
_enabled = true;
if (success || });
isActive || })
constants.navigatorKey.currentContext == null || .catchError((_) {
!constants.navigatorKey.currentContext!.mounted) { setState(() {
return cleanup(); _enabled = true;
} });
});
ScaffoldMessenger.of(
constants.navigatorKey.currentContext!,
).showSnackBar(
SnackBar(
content: const Text(
"Mount location not found",
textAlign: TextAlign.center,
),
),
);
return cleanup();
} }
: null, : null,
), ),