2021-09-02 19:32:07 +00:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2020-12-01 19:08:19 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-04 18:58:25 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2020-12-01 19:08:19 +00:00
|
|
|
import 'package:selfprivacy/config/brand_theme.dart';
|
2022-05-17 13:31:34 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2022-08-30 03:09:09 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
2021-08-29 15:02:51 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/job.dart';
|
2022-10-04 18:58:25 +00:00
|
|
|
import 'package:selfprivacy/logic/models/service.dart';
|
2021-03-18 00:55:38 +00:00
|
|
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
2021-05-25 21:53:54 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
2020-12-03 16:52:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
2021-08-29 15:02:51 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_switch/brand_switch.dart';
|
2020-12-08 19:26:51 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
2020-12-01 19:08:19 +00:00
|
|
|
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
2021-03-18 00:55:38 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-29 20:35:06 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/services/service_page.dart';
|
|
|
|
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
2021-03-26 13:38:39 +00:00
|
|
|
import 'package:selfprivacy/utils/ui_helpers.dart';
|
2022-08-29 20:35:06 +00:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-12-01 19:08:19 +00:00
|
|
|
|
2021-09-02 19:32:07 +00:00
|
|
|
const switchableServices = [
|
2022-10-04 18:58:25 +00:00
|
|
|
'bitwarden',
|
|
|
|
'nextcloud',
|
|
|
|
'pleroma',
|
|
|
|
'gitea',
|
|
|
|
'ocserv',
|
2021-09-02 19:32:07 +00:00
|
|
|
];
|
|
|
|
|
2020-12-01 19:08:19 +00:00
|
|
|
class ServicesPage extends StatefulWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const ServicesPage({super.key});
|
2020-12-01 19:08:19 +00:00
|
|
|
|
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<ServicesPage> createState() => _ServicesPageState();
|
2020-12-01 19:08:19 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
void _launchURL(final url) async {
|
2022-08-29 20:35:06 +00:00
|
|
|
try {
|
|
|
|
final Uri uri = Uri.parse(url);
|
|
|
|
await launchUrl(
|
|
|
|
uri,
|
|
|
|
mode: LaunchMode.externalApplication,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
2021-12-23 13:52:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 19:08:19 +00:00
|
|
|
class _ServicesPageState extends State<ServicesPage> {
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2021-01-06 17:35:57 +00:00
|
|
|
|
2020-12-01 19:08:19 +00:00
|
|
|
return Scaffold(
|
2020-12-03 16:52:53 +00:00
|
|
|
appBar: PreferredSize(
|
2022-05-24 18:55:39 +00:00
|
|
|
preferredSize: const Size.fromHeight(52),
|
2021-05-25 21:53:54 +00:00
|
|
|
child: BrandHeader(
|
|
|
|
title: 'basis.services'.tr(),
|
|
|
|
),
|
2020-12-03 16:52:53 +00:00
|
|
|
),
|
2022-08-29 20:35:06 +00:00
|
|
|
body: RefreshIndicator(
|
|
|
|
onRefresh: () async {
|
|
|
|
context.read<ServicesCubit>().reload();
|
|
|
|
},
|
|
|
|
child: ListView(
|
|
|
|
padding: paddingH15V0,
|
|
|
|
children: [
|
2022-10-03 23:32:35 +00:00
|
|
|
BrandText.body1('basis.services_title'.tr()),
|
2022-08-29 20:35:06 +00:00
|
|
|
const SizedBox(height: 24),
|
|
|
|
if (!isReady) ...[const NotReadyCard(), const SizedBox(height: 24)],
|
2022-10-04 18:58:25 +00:00
|
|
|
...context
|
|
|
|
.read<ServicesCubit>()
|
|
|
|
.state
|
|
|
|
.services
|
2022-08-29 20:35:06 +00:00
|
|
|
.map(
|
2022-10-04 18:58:25 +00:00
|
|
|
(final service) => Padding(
|
2022-08-29 20:35:06 +00:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
bottom: 30,
|
|
|
|
),
|
2022-10-04 18:58:25 +00:00
|
|
|
child: _Card(service: service),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
2022-08-29 20:35:06 +00:00
|
|
|
)
|
|
|
|
.toList()
|
|
|
|
],
|
|
|
|
),
|
2020-12-01 19:08:19 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _Card extends StatelessWidget {
|
2022-10-04 18:58:25 +00:00
|
|
|
const _Card({required this.service});
|
2020-12-01 19:08:19 +00:00
|
|
|
|
2022-10-04 18:58:25 +00:00
|
|
|
final Service service;
|
2020-12-01 19:08:19 +00:00
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2021-08-29 15:02:51 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
final serviceState = context.watch<ServicesCubit>().state;
|
|
|
|
final jobsCubit = context.watch<JobsCubit>();
|
|
|
|
final jobState = jobsCubit.state;
|
2021-09-02 19:32:07 +00:00
|
|
|
|
2022-10-04 18:58:25 +00:00
|
|
|
final switchableService = switchableServices.contains(service.id);
|
2022-06-05 22:40:34 +00:00
|
|
|
final hasSwitchJob = switchableService &&
|
2021-09-02 19:32:07 +00:00
|
|
|
jobState is JobsStateWithJobs &&
|
2022-08-24 05:35:49 +00:00
|
|
|
jobState.clientJobList.any(
|
2022-10-04 18:58:25 +00:00
|
|
|
(final el) => el is ServiceToggleJob && el.id == service.id,
|
2022-06-05 22:40:34 +00:00
|
|
|
);
|
2021-09-02 19:32:07 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
final isSwitchOn = isReady &&
|
2022-10-04 18:58:25 +00:00
|
|
|
(!switchableServices.contains(service.id) ||
|
|
|
|
serviceState.isEnableByType(service));
|
2021-08-29 15:02:51 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
final config = context.watch<ServerInstallationCubit>().state;
|
|
|
|
final domainName = UiHelpers.getDomainName(config);
|
2021-12-23 13:52:12 +00:00
|
|
|
|
2021-03-18 00:55:38 +00:00
|
|
|
return GestureDetector(
|
2022-09-16 14:14:29 +00:00
|
|
|
onTap: isReady
|
|
|
|
? () => Navigator.of(context)
|
2022-10-04 18:58:25 +00:00
|
|
|
.push(materialRoute(ServicePage(serviceId: service.id)))
|
2022-09-16 14:14:29 +00:00
|
|
|
: null,
|
2021-05-25 21:53:54 +00:00
|
|
|
child: BrandCards.big(
|
2021-03-18 00:55:38 +00:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2021-08-29 15:02:51 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
IconStatusMask(
|
2021-09-02 19:32:07 +00:00
|
|
|
status:
|
2022-02-16 07:28:29 +00:00
|
|
|
isSwitchOn ? StateType.stable : StateType.uninitialized,
|
2022-10-04 18:58:25 +00:00
|
|
|
icon: SvgPicture.string(
|
|
|
|
service.svgIcon,
|
|
|
|
width: 30.0,
|
|
|
|
height: 30.0,
|
|
|
|
color: Theme.of(context).colorScheme.onBackground,
|
|
|
|
),
|
2021-08-29 15:02:51 +00:00
|
|
|
),
|
2022-02-16 07:28:29 +00:00
|
|
|
if (isReady && switchableService) ...[
|
2022-05-24 18:55:39 +00:00
|
|
|
const Spacer(),
|
2021-08-29 15:02:51 +00:00
|
|
|
Builder(
|
2022-06-05 22:40:34 +00:00
|
|
|
builder: (final context) {
|
2021-08-29 15:02:51 +00:00
|
|
|
late bool isActive;
|
2021-09-02 19:32:07 +00:00
|
|
|
if (hasSwitchJob) {
|
2022-08-24 05:35:49 +00:00
|
|
|
isActive = (jobState.clientJobList.firstWhere(
|
2022-06-05 22:40:34 +00:00
|
|
|
(final el) =>
|
2022-10-04 18:58:25 +00:00
|
|
|
el is ServiceToggleJob && el.id == service.id,
|
2022-06-05 22:40:34 +00:00
|
|
|
) as ServiceToggleJob)
|
2021-08-29 15:02:51 +00:00
|
|
|
.needToTurnOn;
|
|
|
|
} else {
|
2022-10-04 18:58:25 +00:00
|
|
|
isActive = serviceState.isEnableByType(service);
|
2021-08-29 15:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return BrandSwitch(
|
|
|
|
value: isActive,
|
2022-10-07 17:50:18 +00:00
|
|
|
onChanged: (final value) => jobsCubit.addJob(
|
2021-08-29 15:02:51 +00:00
|
|
|
ServiceToggleJob(
|
2022-10-04 18:58:25 +00:00
|
|
|
service: service,
|
2021-08-29 15:02:51 +00:00
|
|
|
needToTurnOn: value,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
],
|
2021-03-18 00:55:38 +00:00
|
|
|
),
|
2021-09-02 19:32:07 +00:00
|
|
|
ClipRect(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 10),
|
2022-10-04 18:58:25 +00:00
|
|
|
BrandText.h2(service.displayName),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 10),
|
2022-10-04 18:58:25 +00:00
|
|
|
if (service.url != '' && service.url != null)
|
2021-12-23 13:52:12 +00:00
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () => _launchURL(
|
2022-10-04 18:58:25 +00:00
|
|
|
'https://${service.url}',
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
2021-12-23 13:52:12 +00:00
|
|
|
child: Text(
|
2022-10-04 18:58:25 +00:00
|
|
|
'${service.url}',
|
2022-05-30 16:55:09 +00:00
|
|
|
style: TextStyle(
|
|
|
|
color:
|
|
|
|
Theme.of(context).colorScheme.secondary,
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
),
|
2021-12-23 13:52:12 +00:00
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 10),
|
2021-12-23 13:52:12 +00:00
|
|
|
],
|
|
|
|
),
|
2022-10-04 18:58:25 +00:00
|
|
|
if (service.id == 'mailserver')
|
2022-06-05 22:40:34 +00:00
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
domainName,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
),
|
2022-05-30 16:55:09 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
const SizedBox(height: 10),
|
|
|
|
],
|
|
|
|
),
|
2022-10-04 18:58:25 +00:00
|
|
|
BrandText.body2(service.loginInfo),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 10),
|
2022-10-04 18:58:25 +00:00
|
|
|
BrandText.body2(service.description),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 10),
|
2021-09-02 19:32:07 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
if (hasSwitchJob)
|
|
|
|
Positioned(
|
2021-09-29 18:28:47 +00:00
|
|
|
bottom: 24,
|
2021-09-02 19:32:07 +00:00
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
child: BackdropFilter(
|
|
|
|
filter: ImageFilter.blur(
|
|
|
|
sigmaX: 3,
|
|
|
|
sigmaY: 2,
|
|
|
|
),
|
|
|
|
child: BrandText.h2(
|
2022-10-03 23:32:35 +00:00
|
|
|
'jobs.run_jobs'.tr(),
|
2021-09-02 19:32:07 +00:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
2020-12-01 19:08:19 +00:00
|
|
|
],
|
2021-03-18 00:55:38 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|