2022-11-16 00:24:40 +00:00
|
|
|
part of 'server_api.dart';
|
2022-08-26 19:28:01 +00:00
|
|
|
|
2023-06-19 18:15:24 +00:00
|
|
|
mixin ServerActionsApi on GraphQLApiMap {
|
2022-08-26 19:28:01 +00:00
|
|
|
Future<bool> _commonBoolRequest(final Function graphQLMethod) async {
|
|
|
|
QueryResult response;
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
response = await graphQLMethod();
|
|
|
|
if (response.hasException) {
|
|
|
|
print(response.exception.toString());
|
|
|
|
result = false;
|
|
|
|
} else {
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-08-02 21:08:23 +00:00
|
|
|
Future<GenericResult<DateTime?>> reboot() async {
|
|
|
|
DateTime? time;
|
2022-08-26 19:28:01 +00:00
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
2023-08-06 21:24:41 +00:00
|
|
|
final response = await client.mutate$RebootSystem();
|
2023-08-02 21:08:23 +00:00
|
|
|
if (response.hasException) {
|
|
|
|
print(response.exception.toString());
|
|
|
|
}
|
2023-08-06 21:24:41 +00:00
|
|
|
if (response.parsedData!.rebootSystem.success) {
|
2023-11-13 10:03:52 +00:00
|
|
|
time = DateTime.now().toUtc();
|
2023-08-02 21:08:23 +00:00
|
|
|
}
|
2022-08-26 19:28:01 +00:00
|
|
|
} catch (e) {
|
2023-08-02 21:08:23 +00:00
|
|
|
print(e);
|
|
|
|
return GenericResult(data: time, success: false);
|
2022-08-26 19:28:01 +00:00
|
|
|
}
|
2023-08-02 21:08:23 +00:00
|
|
|
|
|
|
|
return GenericResult(data: time, success: true);
|
2022-08-26 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> pullConfigurationUpdate() async {
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
return await _commonBoolRequest(
|
2022-09-18 23:42:21 +00:00
|
|
|
() async => client.mutate$PullRepositoryChanges(),
|
2022-08-26 19:28:01 +00:00
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> upgrade() async {
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
2022-09-18 23:42:21 +00:00
|
|
|
return _commonBoolRequest(
|
|
|
|
() async => client.mutate$RunSystemUpgrade(),
|
2022-08-26 19:28:01 +00:00
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> apply() async {
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
await client.mutate$RunSystemRebuild();
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|