2023-05-01 19:00:06 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-10-29 18:40:07 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
|
|
|
import 'package:adguard_home_manager/models/github_release.dart';
|
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
|
|
|
|
|
|
|
class UpdateModal extends StatefulWidget {
|
|
|
|
final GitHubRelease gitHubRelease;
|
|
|
|
final void Function(String, String) onDownload;
|
|
|
|
|
|
|
|
const UpdateModal({
|
|
|
|
Key? key,
|
|
|
|
required this.gitHubRelease,
|
|
|
|
required this.onDownload,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<UpdateModal> createState() => _UpdateModalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UpdateModalState extends State<UpdateModal> {
|
|
|
|
bool doNotRemember = false;
|
|
|
|
|
2023-05-01 19:00:06 +02:00
|
|
|
String? getDownloadLink() {
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
return widget.gitHubRelease.assets.firstWhere((item) => item.browserDownloadUrl.contains('apk')).browserDownloadUrl;
|
|
|
|
}
|
|
|
|
else if (Platform.isMacOS) {
|
|
|
|
return widget.gitHubRelease.assets.firstWhere((item) => item.browserDownloadUrl.contains('macOS')).browserDownloadUrl; // macOS package is a zip
|
|
|
|
}
|
|
|
|
else if (Platform.isWindows) {
|
|
|
|
return widget.gitHubRelease.assets.firstWhere((item) => item.browserDownloadUrl.contains('exe')).browserDownloadUrl;
|
|
|
|
}
|
|
|
|
else if (Platform.isLinux) {
|
|
|
|
return widget.gitHubRelease.assets.firstWhere((item) => item.browserDownloadUrl.contains('deb')).browserDownloadUrl;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
2022-10-29 18:40:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
|
|
|
|
2023-05-01 19:00:06 +02:00
|
|
|
final downloadLink = getDownloadLink();
|
|
|
|
|
2022-10-29 18:40:07 +02:00
|
|
|
return AlertDialog(
|
|
|
|
scrollable: true,
|
|
|
|
title: Column(
|
|
|
|
children: [
|
2022-11-04 22:56:00 +01:00
|
|
|
Icon(
|
2022-10-29 18:40:07 +02:00
|
|
|
Icons.system_update_rounded,
|
2022-11-04 22:56:00 +01:00
|
|
|
size: 24,
|
2022-11-05 02:35:35 +01:00
|
|
|
color: Theme.of(context).listTileTheme.iconColor,
|
2022-10-29 18:40:07 +02:00
|
|
|
),
|
2022-11-04 22:56:00 +01:00
|
|
|
const SizedBox(height: 16),
|
2022-10-29 18:40:07 +02:00
|
|
|
Text(
|
|
|
|
AppLocalizations.of(context)!.updateAvailable,
|
|
|
|
textAlign: TextAlign.center,
|
2022-11-04 22:56:00 +01:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface
|
2022-10-29 18:40:07 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
content: Column(
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 10),
|
2022-11-04 22:56:00 +01:00
|
|
|
Text(
|
|
|
|
"${AppLocalizations.of(context)!.installedVersion}: ${appConfigProvider.getAppInfo!.version}",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant
|
|
|
|
),
|
|
|
|
),
|
2022-10-29 18:40:07 +02:00
|
|
|
const SizedBox(height: 10),
|
2022-11-04 22:56:00 +01:00
|
|
|
Text(
|
|
|
|
"${AppLocalizations.of(context)!.newVersion}: ${widget.gitHubRelease.tagName}",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant
|
|
|
|
),
|
|
|
|
),
|
2022-10-29 18:40:07 +02:00
|
|
|
const SizedBox(height: 10),
|
2022-11-04 22:56:00 +01:00
|
|
|
Text(
|
|
|
|
"${AppLocalizations.of(context)!.source}: GitHub",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant
|
|
|
|
),
|
|
|
|
),
|
2022-10-29 18:40:07 +02:00
|
|
|
const SizedBox(height: 20),
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () => setState(() => doNotRemember = !doNotRemember),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Checkbox(
|
|
|
|
value: doNotRemember,
|
|
|
|
onChanged: (value) => setState(() => doNotRemember = value!),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(5)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 10),
|
2022-11-04 22:56:00 +01:00
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context)!.doNotRememberAgainUpdate,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
2022-10-29 18:40:07 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2023-05-01 19:00:06 +02:00
|
|
|
if (downloadLink != null) TextButton(
|
2022-10-29 18:40:07 +02:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context);
|
2023-05-01 19:00:06 +02:00
|
|
|
widget.onDownload(downloadLink, widget.gitHubRelease.tagName);
|
2022-10-29 18:40:07 +02:00
|
|
|
},
|
|
|
|
child: Text(AppLocalizations.of(context)!.download)
|
|
|
|
),
|
|
|
|
TextButton(
|
2022-10-29 19:16:05 +02:00
|
|
|
onPressed: () {
|
|
|
|
if (doNotRemember == true) {
|
|
|
|
appConfigProvider.setDoNotRememberVersion(widget.gitHubRelease.tagName);
|
|
|
|
}
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
2022-10-29 18:40:07 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.close)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|