2021-08-29 13:54:28 +00:00
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:selfprivacy/config/hive_config.dart';
|
2021-09-29 13:08:19 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
2021-08-29 13:54:28 +00:00
|
|
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
2021-09-29 13:08:19 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
2021-08-29 09:50:24 +00:00
|
|
|
|
|
|
|
part 'services_state.dart';
|
|
|
|
|
2021-09-29 13:08:19 +00:00
|
|
|
class ServicesCubit extends AppConfigDependendCubit<ServicesState> {
|
|
|
|
ServicesCubit(AppConfigCubit appConfigCubit)
|
|
|
|
: super(appConfigCubit, ServicesState.allOff());
|
2021-08-29 09:50:24 +00:00
|
|
|
|
2021-08-29 13:54:28 +00:00
|
|
|
Box box = Hive.box(BNames.servicesState);
|
2021-09-29 13:08:19 +00:00
|
|
|
final api = ServerApi();
|
|
|
|
Future<void> load() async {
|
2021-09-29 18:28:47 +00:00
|
|
|
if (appConfigCubit.state is AppConfigFinished) {
|
|
|
|
var statuses = await api.servicesPowerCheck();
|
|
|
|
emit(
|
|
|
|
ServicesState(
|
|
|
|
isPasswordManagerEnable: statuses[ServiceTypes.passwordManager]!,
|
|
|
|
isCloudEnable: statuses[ServiceTypes.cloud]!,
|
|
|
|
isGitEnable: statuses[ServiceTypes.git]!,
|
|
|
|
isSocialNetworkEnable: statuses[ServiceTypes.socialNetwork]!,
|
|
|
|
isVpnEnable: statuses[ServiceTypes.vpn]!,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-08-29 13:54:28 +00:00
|
|
|
}
|
|
|
|
|
2021-09-29 13:08:19 +00:00
|
|
|
@override
|
|
|
|
void clear() async {
|
|
|
|
box.clear();
|
2021-08-29 13:54:28 +00:00
|
|
|
emit(ServicesState.allOff());
|
|
|
|
}
|
2021-08-29 09:50:24 +00:00
|
|
|
}
|