mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-24 09:46:42 +00:00
parent
4eb8f34e37
commit
caa2fd3b8e
|
@ -597,6 +597,7 @@
|
||||||
"service_turn_on": "Turn on",
|
"service_turn_on": "Turn on",
|
||||||
"job_added": "Job added",
|
"job_added": "Job added",
|
||||||
"job_postponed": "Job added, but you will be able to launch it after current jobs are finished",
|
"job_postponed": "Job added, but you will be able to launch it after current jobs are finished",
|
||||||
|
"job_removed": "Job removed",
|
||||||
"run_jobs": "Run jobs",
|
"run_jobs": "Run jobs",
|
||||||
"reboot_success": "Server is rebooting",
|
"reboot_success": "Server is rebooting",
|
||||||
"reboot_failed": "Couldn't reboot the server. Check the app logs.",
|
"reboot_failed": "Couldn't reboot the server. Check the app logs.",
|
||||||
|
|
|
@ -149,7 +149,7 @@ class ServerApi extends GraphQLApiMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setAutoUpgradeSettings(
|
Future<GenericResult<AutoUpgradeSettings?>> setAutoUpgradeSettings(
|
||||||
final AutoUpgradeSettings settings,
|
final AutoUpgradeSettings settings,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
|
@ -164,13 +164,38 @@ class ServerApi extends GraphQLApiMap
|
||||||
final mutation = Options$Mutation$ChangeAutoUpgradeSettings(
|
final mutation = Options$Mutation$ChangeAutoUpgradeSettings(
|
||||||
variables: variables,
|
variables: variables,
|
||||||
);
|
);
|
||||||
await client.mutate$ChangeAutoUpgradeSettings(mutation);
|
final result = await client.mutate$ChangeAutoUpgradeSettings(mutation);
|
||||||
|
if (result.hasException) {
|
||||||
|
return GenericResult<AutoUpgradeSettings?>(
|
||||||
|
success: false,
|
||||||
|
message: result.exception.toString(),
|
||||||
|
data: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return GenericResult<AutoUpgradeSettings?>(
|
||||||
|
success: result.parsedData?.system.changeAutoUpgradeSettings.success ??
|
||||||
|
false,
|
||||||
|
message: result.parsedData?.system.changeAutoUpgradeSettings.message,
|
||||||
|
data: result.parsedData == null
|
||||||
|
? null
|
||||||
|
: AutoUpgradeSettings(
|
||||||
|
allowReboot: result
|
||||||
|
.parsedData!.system.changeAutoUpgradeSettings.allowReboot,
|
||||||
|
enable: result.parsedData!.system.changeAutoUpgradeSettings
|
||||||
|
.enableAutoUpgrade,
|
||||||
|
),
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
|
return GenericResult<AutoUpgradeSettings?>(
|
||||||
|
success: false,
|
||||||
|
message: e.toString(),
|
||||||
|
data: null,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setTimezone(final String timezone) async {
|
Future<GenericResult<String?>> setTimezone(final String timezone) async {
|
||||||
try {
|
try {
|
||||||
final GraphQLClient client = await getClient();
|
final GraphQLClient client = await getClient();
|
||||||
final variables = Variables$Mutation$ChangeTimezone(
|
final variables = Variables$Mutation$ChangeTimezone(
|
||||||
|
@ -179,9 +204,26 @@ class ServerApi extends GraphQLApiMap
|
||||||
final mutation = Options$Mutation$ChangeTimezone(
|
final mutation = Options$Mutation$ChangeTimezone(
|
||||||
variables: variables,
|
variables: variables,
|
||||||
);
|
);
|
||||||
await client.mutate$ChangeTimezone(mutation);
|
final result = await client.mutate$ChangeTimezone(mutation);
|
||||||
|
if (result.hasException) {
|
||||||
|
return GenericResult<String>(
|
||||||
|
success: false,
|
||||||
|
message: result.exception.toString(),
|
||||||
|
data: '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return GenericResult<String?>(
|
||||||
|
success: result.parsedData?.system.changeTimezone.success ?? false,
|
||||||
|
message: result.parsedData?.system.changeTimezone.message,
|
||||||
|
data: result.parsedData?.system.changeTimezone.timezone,
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
|
return GenericResult<String?>(
|
||||||
|
success: false,
|
||||||
|
message: e.toString(),
|
||||||
|
data: '',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,15 @@ class JobsStateWithJobs extends JobsState {
|
||||||
final List<ClientJob> newJobsList = clientJobList
|
final List<ClientJob> newJobsList = clientJobList
|
||||||
.where((final element) => element.runtimeType != job.runtimeType)
|
.where((final element) => element.runtimeType != job.runtimeType)
|
||||||
.toList();
|
.toList();
|
||||||
|
if (job.shouldRemoveInsteadOfAdd(clientJobList)) {
|
||||||
|
getIt<NavigationService>().showSnackBar('jobs.job_removed'.tr());
|
||||||
|
} else {
|
||||||
newJobsList.add(job);
|
newJobsList.add(job);
|
||||||
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
||||||
|
}
|
||||||
|
if (newJobsList.isEmpty) {
|
||||||
|
return JobsStateEmpty();
|
||||||
|
}
|
||||||
return JobsStateWithJobs(newJobsList);
|
return JobsStateWithJobs(newJobsList);
|
||||||
}
|
}
|
||||||
if (job.canAddTo(clientJobList)) {
|
if (job.canAddTo(clientJobList)) {
|
||||||
|
@ -102,13 +109,16 @@ class JobsStateLoading extends JobsState {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
JobsState addJob(final ClientJob job) {
|
JobsState addJob(final ClientJob job) {
|
||||||
// Do the same, but add jobs to the postponed list
|
|
||||||
if (job is ReplaceableJob) {
|
if (job is ReplaceableJob) {
|
||||||
final List<ClientJob> newPostponedJobs = postponedJobs
|
final List<ClientJob> newPostponedJobs = postponedJobs
|
||||||
.where((final element) => element.runtimeType != job.runtimeType)
|
.where((final element) => element.runtimeType != job.runtimeType)
|
||||||
.toList();
|
.toList();
|
||||||
|
if (job.shouldRemoveInsteadOfAdd(postponedJobs)) {
|
||||||
|
getIt<NavigationService>().showSnackBar('jobs.job_removed'.tr());
|
||||||
|
} else {
|
||||||
newPostponedJobs.add(job);
|
newPostponedJobs.add(job);
|
||||||
getIt<NavigationService>().showSnackBar('jobs.job_postponed'.tr());
|
getIt<NavigationService>().showSnackBar('jobs.job_postponed'.tr());
|
||||||
|
}
|
||||||
return JobsStateLoading(clientJobList, rebuildJobUid, newPostponedJobs);
|
return JobsStateLoading(clientJobList, rebuildJobUid, newPostponedJobs);
|
||||||
}
|
}
|
||||||
if (job.canAddTo(postponedJobs)) {
|
if (job.canAddTo(postponedJobs)) {
|
||||||
|
@ -140,8 +150,15 @@ class JobsStateFinished extends JobsState {
|
||||||
final List<ClientJob> newPostponedJobs = postponedJobs
|
final List<ClientJob> newPostponedJobs = postponedJobs
|
||||||
.where((final element) => element.runtimeType != job.runtimeType)
|
.where((final element) => element.runtimeType != job.runtimeType)
|
||||||
.toList();
|
.toList();
|
||||||
|
if (job.shouldRemoveInsteadOfAdd(postponedJobs)) {
|
||||||
|
getIt<NavigationService>().showSnackBar('jobs.job_removed'.tr());
|
||||||
|
} else {
|
||||||
newPostponedJobs.add(job);
|
newPostponedJobs.add(job);
|
||||||
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
||||||
|
}
|
||||||
|
if (newPostponedJobs.isEmpty) {
|
||||||
|
return JobsStateEmpty();
|
||||||
|
}
|
||||||
return JobsStateWithJobs(newPostponedJobs);
|
return JobsStateWithJobs(newPostponedJobs);
|
||||||
}
|
}
|
||||||
if (job.canAddTo(postponedJobs)) {
|
if (job.canAddTo(postponedJobs)) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:pub_semver/pub_semver.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/config/hive_config.dart';
|
import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/backup.dart';
|
import 'package:selfprivacy/logic/models/backup.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
|
@ -188,6 +189,37 @@ class ApiConnectionRepository {
|
||||||
return (true, result.message ?? 'basis.done'.tr());
|
return (true, result.message ?? 'basis.done'.tr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<(bool, String)> setAutoUpgradeSettings(
|
||||||
|
final bool enable,
|
||||||
|
final bool allowReboot,
|
||||||
|
) async {
|
||||||
|
final GenericResult<AutoUpgradeSettings?> result =
|
||||||
|
await api.setAutoUpgradeSettings(
|
||||||
|
AutoUpgradeSettings(
|
||||||
|
enable: enable,
|
||||||
|
allowReboot: allowReboot,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
_apiData.settings.invalidate();
|
||||||
|
if (result.data != null) {
|
||||||
|
return (true, result.message ?? 'basis.done'.tr());
|
||||||
|
} else {
|
||||||
|
return (false, result.message ?? 'jobs.generic_error'.tr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<(bool, String)> setServerTimezone(
|
||||||
|
final String timezone,
|
||||||
|
) async {
|
||||||
|
final GenericResult result = await api.setTimezone(timezone);
|
||||||
|
_apiData.settings.invalidate();
|
||||||
|
if (result.success) {
|
||||||
|
return (true, result.message ?? 'basis.done'.tr());
|
||||||
|
} else {
|
||||||
|
return (false, result.message ?? 'jobs.generic_error'.tr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_dataStream.close();
|
_dataStream.close();
|
||||||
_connectionStatusStream.close();
|
_connectionStatusStream.close();
|
||||||
|
|
|
@ -2,7 +2,6 @@ import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
import 'package:selfprivacy/logic/models/json/server_job.dart';
|
import 'package:selfprivacy/logic/models/json/server_job.dart';
|
||||||
import 'package:selfprivacy/logic/models/service.dart';
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
|
@ -350,18 +349,21 @@ class ChangeAutoUpgradeSettingsJob extends ReplaceableJob {
|
||||||
final bool allowReboot;
|
final bool allowReboot;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<(bool, String)> execute() async {
|
Future<(bool, String)> execute() async => getIt<ApiConnectionRepository>()
|
||||||
await getIt<ApiConnectionRepository>().api.setAutoUpgradeSettings(
|
.setAutoUpgradeSettings(enable, allowReboot);
|
||||||
AutoUpgradeSettings(enable: enable, allowReboot: allowReboot),
|
|
||||||
);
|
|
||||||
getIt<ApiConnectionRepository>().apiData.settings.invalidate();
|
|
||||||
return (true, 'Check not implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRemoveInsteadOfAdd(final List<ClientJob> jobs) {
|
bool shouldRemoveInsteadOfAdd(final List<ClientJob> jobs) {
|
||||||
// TODO: Finish this
|
final currentSettings = getIt<ApiConnectionRepository>()
|
||||||
throw UnimplementedError();
|
.apiData
|
||||||
|
.settings
|
||||||
|
.data
|
||||||
|
?.autoUpgradeSettings;
|
||||||
|
if (currentSettings == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return currentSettings.enable == enable &&
|
||||||
|
currentSettings.allowReboot == allowReboot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -392,16 +394,17 @@ class ChangeServerTimezoneJob extends ReplaceableJob {
|
||||||
final String timezone;
|
final String timezone;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<(bool, String)> execute() async {
|
Future<(bool, String)> execute() async =>
|
||||||
await getIt<ApiConnectionRepository>().api.setTimezone(timezone);
|
getIt<ApiConnectionRepository>().setServerTimezone(timezone);
|
||||||
getIt<ApiConnectionRepository>().apiData.settings.invalidate();
|
|
||||||
return (true, 'Check not implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRemoveInsteadOfAdd(final List<ClientJob> jobs) {
|
bool shouldRemoveInsteadOfAdd(final List<ClientJob> jobs) {
|
||||||
// TODO: Finish this
|
final currentSettings =
|
||||||
throw UnimplementedError();
|
getIt<ApiConnectionRepository>().apiData.settings.data?.timezone;
|
||||||
|
if (currentSettings == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return currentSettings == timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in a new issue