Compare commits
4 Commits
7605be809c
...
b93e2978b0
Author | SHA1 | Date | |
---|---|---|---|
b93e2978b0 | |||
ece002f25b | |||
b9f5f774e2 | |||
52d210974b |
@ -334,6 +334,7 @@ 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);
|
||||||
|
@ -2,6 +2,7 @@ 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';
|
||||||
@ -73,9 +74,9 @@ class Mount with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> mount(bool unmount, {String? location}) async {
|
Future<bool> mount(bool unmount, {String? location}) async {
|
||||||
try {
|
try {
|
||||||
await http.post(
|
final response = 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',
|
||||||
@ -83,10 +84,16 @@ class Mount with ChangeNotifier {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return refresh();
|
if (!unmount && response.statusCode == 500) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await refresh();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('$e');
|
debugPrint('$e');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
|
@ -4,6 +4,7 @@ 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';
|
||||||
|
|
||||||
@ -140,9 +141,15 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
setState(() {
|
||||||
|
_enabled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
if (!context.mounted) {
|
if (!context.mounted) {
|
||||||
return;
|
return cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
@ -153,21 +160,34 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
|
return cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
mount
|
final success = await mount.mount(
|
||||||
.mount(isActive, location: location)
|
isActive,
|
||||||
.then((_) {
|
location: location,
|
||||||
setState(() {
|
);
|
||||||
_enabled = true;
|
|
||||||
});
|
if (success ||
|
||||||
})
|
isActive ||
|
||||||
.catchError((_) {
|
constants.navigatorKey.currentContext == null ||
|
||||||
setState(() {
|
!constants.navigatorKey.currentContext!.mounted) {
|
||||||
_enabled = true;
|
return cleanup();
|
||||||
});
|
}
|
||||||
});
|
|
||||||
|
ScaffoldMessenger.of(
|
||||||
|
constants.navigatorKey.currentContext!,
|
||||||
|
).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: const Text(
|
||||||
|
"Mount location not found",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return cleanup();
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user