Add basic flavors

This commit is contained in:
problematicconsumer
2023-09-12 15:22:58 +03:30
parent ea81be3763
commit f1b0f8ee4b
24 changed files with 271 additions and 293 deletions

View File

@@ -3,8 +3,8 @@ import 'package:gap/gap.dart';
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/domain/constants.dart';
import 'package:hiddify/domain/failures.dart';
import 'package:hiddify/features/common/common.dart';
import 'package:hiddify/features/common/new_version_dialog.dart';
import 'package:hiddify/features/common/runtime_details.dart';
import 'package:hiddify/gen/assets.gen.dart';
import 'package:hiddify/services/service_providers.dart';
import 'package:hiddify/utils/utils.dart';
@@ -16,33 +16,22 @@ class AboutPage extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
final appVersion = ref.watch(appVersionProvider);
final isCheckingForUpdate = ref.watch(
runtimeDetailsNotifierProvider.select(
(value) => value.maybeWhen(
data: (data) => data.latestVersion.isLoading,
orElse: () => false,
),
),
);
final appInfo = ref.watch(appInfoProvider);
final appUpdate = ref.watch(appUpdateNotifierProvider);
ref.listen(
runtimeDetailsNotifierProvider,
appUpdateNotifierProvider,
(_, next) async {
if (next case AsyncData(:final value)) {
switch (value.latestVersion) {
case AsyncError(:final error):
CustomToast.error(t.printError(error)).show(context);
default:
if (value.newVersionAvailable) {
await NewVersionDialog(
value.appVersion,
value.latestVersion.value!,
canIgnore: false,
).show(context);
}
}
switch (next) {
case AsyncData(value: final remoteVersion?):
await NewVersionDialog(
appInfo.version,
remoteVersion,
canIgnore: false,
).show(context);
case AsyncError(:final error):
if (!context.mounted) return;
CustomToast.error(t.printError(error)).show(context);
}
},
);
@@ -53,86 +42,77 @@ class AboutPage extends HookConsumerWidget {
SliverAppBar(
title: Text(t.about.pageTitle),
),
...switch (appVersion) {
AsyncData(:final value) => [
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Assets.images.logo.svg(width: 64, height: 64),
const Gap(16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
t.general.appTitle,
style: Theme.of(context).textTheme.titleLarge,
),
const Gap(4),
Text(
"${t.about.version} ${value.version} ${value.buildNumber}",
),
],
),
],
),
),
),
SliverList(
delegate: SliverChildListDelegate(
[
ListTile(
title: Text(t.about.sourceCode),
trailing: const Icon(Icons.open_in_new),
onTap: () async {
await UriUtils.tryLaunch(
Uri.parse(Constants.githubUrl),
);
},
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Assets.images.logo.svg(width: 64, height: 64),
const Gap(16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
t.general.appTitle,
style: Theme.of(context).textTheme.titleLarge,
),
ListTile(
title: Text(t.about.telegramChannel),
trailing: const Icon(Icons.open_in_new),
onTap: () async {
await UriUtils.tryLaunch(
Uri.parse(Constants.telegramChannelUrl),
);
},
),
ListTile(
title: Text(t.about.checkForUpdate),
trailing: isCheckingForUpdate
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(),
)
: const Icon(Icons.update),
onTap: () async {
await ref
.read(runtimeDetailsNotifierProvider.notifier)
.checkForUpdates();
},
),
ListTile(
title: Text(t.settings.general.openWorkingDir),
trailing: const Icon(Icons.arrow_outward_outlined),
onTap: () async {
final path = ref
.read(filesEditorServiceProvider)
.workingDir
.uri;
await UriUtils.tryLaunch(path);
},
const Gap(4),
Text(
"${t.about.version} ${appInfo.version}",
),
],
),
],
),
),
),
SliverList(
delegate: SliverChildListDelegate(
[
ListTile(
title: Text(t.about.sourceCode),
trailing: const Icon(Icons.open_in_new),
onTap: () async {
await UriUtils.tryLaunch(
Uri.parse(Constants.githubUrl),
);
},
),
ListTile(
title: Text(t.about.telegramChannel),
trailing: const Icon(Icons.open_in_new),
onTap: () async {
await UriUtils.tryLaunch(
Uri.parse(Constants.telegramChannelUrl),
);
},
),
ListTile(
title: Text(t.about.checkForUpdate),
trailing: appUpdate.isLoading
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(),
)
: const Icon(Icons.update),
onTap: () {
ref.invalidate(appUpdateNotifierProvider);
},
),
ListTile(
title: Text(t.settings.general.openWorkingDir),
trailing: const Icon(Icons.arrow_outward_outlined),
onTap: () async {
final path =
ref.read(filesEditorServiceProvider).workingDir.uri;
await UriUtils.tryLaunch(path);
},
),
],
_ => [],
},
),
),
],
),
);