selfprivacy.org.app/lib/logic/cubit/services/services_state.dart

92 lines
2.3 KiB
Dart
Raw Normal View History

2021-08-29 09:50:24 +00:00
part of 'services_cubit.dart';
class ServicesState extends ServerInstallationDependendState {
2021-08-29 13:54:28 +00:00
const ServicesState({
required this.services,
2022-09-19 00:21:08 +00:00
required this.lockedServices,
2021-08-29 13:54:28 +00:00
});
2022-09-19 00:21:08 +00:00
const ServicesState.empty()
: this(services: const [], lockedServices: const []);
2021-08-29 13:54:28 +00:00
final List<Service> services;
2022-09-19 00:21:08 +00:00
final List<String> lockedServices;
bool isServiceLocked(final String serviceId) =>
lockedServices.contains(serviceId);
2022-09-05 04:34:47 +00:00
bool get isPasswordManagerEnable => services
.firstWhere(
(final service) => service.id == 'bitwarden',
orElse: () => Service.empty,
)
2022-09-05 04:34:47 +00:00
.isEnabled;
bool get isCloudEnable => services
.firstWhere(
(final service) => service.id == 'nextcloud',
orElse: () => Service.empty,
)
2022-09-05 04:34:47 +00:00
.isEnabled;
bool get isGitEnable => services
.firstWhere(
(final service) => service.id == 'gitea',
orElse: () => Service.empty,
)
2022-09-05 04:34:47 +00:00
.isEnabled;
bool get isSocialNetworkEnable => services
.firstWhere(
(final service) => service.id == 'pleroma',
orElse: () => Service.empty,
)
2022-09-05 04:34:47 +00:00
.isEnabled;
bool get isVpnEnable => services
.firstWhere(
(final service) => service.id == 'ocserv',
orElse: () => Service.empty,
)
2022-09-05 04:34:47 +00:00
.isEnabled;
2021-08-29 13:54:28 +00:00
Service? getServiceById(final String id) {
final service = services.firstWhere(
(final service) => service.id == id,
orElse: () => Service.empty,
);
if (service.id == 'empty') {
return null;
}
return service;
}
2021-08-29 09:50:24 +00:00
@override
2021-08-29 13:54:28 +00:00
List<Object> get props => [
services,
2022-09-19 00:21:08 +00:00
lockedServices,
2021-08-29 13:54:28 +00:00
];
2021-08-29 15:02:51 +00:00
bool isEnableByType(final Service service) {
switch (service.id) {
case 'bitwarden':
2021-08-29 15:02:51 +00:00
return isPasswordManagerEnable;
case 'nextcloud':
2021-08-29 15:02:51 +00:00
return isCloudEnable;
case 'pleroma':
2021-08-29 15:02:51 +00:00
return isSocialNetworkEnable;
case 'gitea':
2021-08-29 15:02:51 +00:00
return isGitEnable;
case 'ocserv':
2021-08-29 15:02:51 +00:00
return isVpnEnable;
default:
throw Exception('wrong state');
}
}
2022-09-19 00:21:08 +00:00
ServicesState copyWith({
final List<Service>? services,
final List<String>? lockedServices,
}) =>
ServicesState(
services: services ?? this.services,
lockedServices: lockedServices ?? this.lockedServices,
);
2021-08-29 09:50:24 +00:00
}