mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-25 11:22:23 +00:00
Check server version
This commit is contained in:
parent
e5528c0d2c
commit
e08404b140
5 changed files with 152 additions and 19 deletions
4
lib/config/minimum_server_version.dart
Normal file
4
lib/config/minimum_server_version.dart
Normal file
|
@ -0,0 +1,4 @@
|
|||
class MinimumServerVersion {
|
||||
static const String stable = "v0.107.28";
|
||||
static const String beta = "v0.108.0-b.33";
|
||||
}
|
|
@ -682,5 +682,9 @@
|
|||
"processingLists": "Processing lists...",
|
||||
"enableDisableResult": "Enable or disable result",
|
||||
"selectedListsEnabledDisabledSuccessfully": "All selected lists have been enabled or disabled successfully",
|
||||
"sslWarning": "If you are using an HTTPS connection with a self signed certificate, make sure to enable \"Don't check SSL certificate\" at Settings > Advanced settings."
|
||||
"sslWarning": "If you are using an HTTPS connection with a self signed certificate, make sure to enable \"Don't check SSL certificate\" at Settings > Advanced settings.",
|
||||
"unsupportedServerVersion": "Unsupported server version",
|
||||
"unsupportedServerVersionMessage": "Your AdGuard Home server version is too old and is not supported by AdGuard Home Manager. You will need to upgrade your AdGuard Home server to a newer version to use this application.",
|
||||
"yourVersion": "Your version: {version}",
|
||||
"minimumRequiredVersion": "Minimum required version: {version}"
|
||||
}
|
|
@ -682,5 +682,9 @@
|
|||
"processingLists": "Procesando listas...",
|
||||
"enableDisableResult": "Resultado de activar o desactivar",
|
||||
"selectedListsEnabledDisabledSuccessfully": "Todas las listas seleccionadas se han activado o desactivado correctamente.",
|
||||
"sslWarning": "Si estás usando una conexión HTTPS con un certificado autofirmado, asegúrate de activar \"No comprobar el certificado SSL\" en Ajustes > Ajustes avanzados."
|
||||
"sslWarning": "Si estás usando una conexión HTTPS con un certificado autofirmado, asegúrate de activar \"No comprobar el certificado SSL\" en Ajustes > Ajustes avanzados.",
|
||||
"unsupportedServerVersion": "Versión del servidor no soportada",
|
||||
"unsupportedServerVersionMessage": "La versión de tu servidor AdGuard Home es demasiado antigua y no está soportada por AdGuard Home Manager. Necesitarás actualizar tu servidor AdGuard Home a una versión más actual para utilizar esta aplicación.",
|
||||
"yourVersion": "Tu versión: {version}",
|
||||
"minimumRequiredVersion": "Versión mínima requerida: {version}"
|
||||
}
|
|
@ -5,12 +5,15 @@ import 'package:segmented_button_slide/segmented_button_slide.dart';
|
|||
import 'package:uuid/uuid.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/widgets/add_server/unsupported_version_modal.dart';
|
||||
import 'package:adguard_home_manager/widgets/add_server/form_text_field.dart';
|
||||
import 'package:adguard_home_manager/widgets/section_label.dart';
|
||||
import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart';
|
||||
import 'package:adguard_home_manager/widgets/add_server/add_server_functions.dart';
|
||||
|
||||
import 'package:adguard_home_manager/config/minimum_server_version.dart';
|
||||
import 'package:adguard_home_manager/models/server_status.dart';
|
||||
import 'package:adguard_home_manager/functions/compare_versions.dart';
|
||||
import 'package:adguard_home_manager/services/auth.dart';
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
import 'package:adguard_home_manager/services/api_client.dart';
|
||||
|
@ -166,6 +169,36 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
serverObj.authToken = encodeBase64UserPass(serverObj.user!, serverObj.password!);
|
||||
}
|
||||
|
||||
statusProvider.setServerStatusLoad(LoadStatus.loading);
|
||||
final ApiClientV2 apiClient2 = ApiClientV2(server: serverObj);
|
||||
final serverStatus = await apiClient2.getServerStatus();
|
||||
|
||||
// If something goes wrong when fetching server status
|
||||
if (serverStatus.successful == false) {
|
||||
statusProvider.setServerStatusLoad(LoadStatus.error);
|
||||
Navigator.pop(context);
|
||||
return;
|
||||
}
|
||||
|
||||
final status = serverStatus.content as ServerStatus;
|
||||
|
||||
// Check if ths server version is compatible
|
||||
final validVersion = serverVersionIsAhead(
|
||||
currentVersion: status.serverVersion,
|
||||
referenceVersion: MinimumServerVersion.stable,
|
||||
referenceVersionBeta: MinimumServerVersion.beta
|
||||
);
|
||||
if (validVersion == false) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => UnsupportedVersionModal(
|
||||
serverVersion: status.serverVersion,
|
||||
onClose: () => Navigator.pop(context)
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final serverCreated = await serversProvider.createServer(serverObj);
|
||||
|
||||
// If something goes wrong when saving the connection on the db
|
||||
|
@ -181,19 +214,6 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
return;
|
||||
}
|
||||
|
||||
statusProvider.setServerStatusLoad(LoadStatus.loading);
|
||||
final ApiClientV2 apiClient2 = ApiClientV2(server: serverObj);
|
||||
final serverStatus = await apiClient2.getServerStatus();
|
||||
|
||||
// If something goes wrong when fetching server status
|
||||
if (serverStatus.successful == false) {
|
||||
statusProvider.setServerStatusLoad(LoadStatus.error);
|
||||
Navigator.pop(context);
|
||||
return;
|
||||
}
|
||||
|
||||
final status = serverStatus.content as ServerStatus;
|
||||
|
||||
// If everything is successful
|
||||
statusProvider.setServerStatusData(
|
||||
data: status
|
||||
|
@ -247,6 +267,31 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
if (serverObj.user != null && serverObj.password != null) {
|
||||
serverObj.authToken = encodeBase64UserPass(serverObj.user!, serverObj.password!);
|
||||
}
|
||||
|
||||
final ApiClientV2 apiClient2 = ApiClientV2(server: serverObj);
|
||||
final version = await apiClient2.getServerVersion();
|
||||
if (version.successful == false) {
|
||||
if (mounted) setState(() => isConnecting = false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if ths server version is compatible
|
||||
final validVersion = serverVersionIsAhead(
|
||||
currentVersion: version.content,
|
||||
referenceVersion: MinimumServerVersion.stable,
|
||||
referenceVersionBeta: MinimumServerVersion.beta
|
||||
);
|
||||
if (validVersion == false) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => UnsupportedVersionModal(
|
||||
serverVersion: version.content,
|
||||
onClose: () => Navigator.pop(context)
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final serverSaved = await serversProvider.editServer(serverObj);
|
||||
|
||||
// If something goes wrong when saving the connection on the db
|
||||
|
@ -270,8 +315,6 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
}
|
||||
|
||||
// If everything is successful
|
||||
final ApiClientV2 apiClient2 = ApiClientV2(server: serverObj);
|
||||
final version = await apiClient2.getServerVersion();
|
||||
if (
|
||||
version.successful == true &&
|
||||
(version.content.contains('a') || version.content.contains('b')) // alpha or beta
|
||||
|
@ -499,7 +542,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
leading: CloseButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
title: widget.server != null
|
||||
title: widget.server == null
|
||||
? Text(AppLocalizations.of(context)!.createConnection)
|
||||
: Text(AppLocalizations.of(context)!.editConnection),
|
||||
actions: [
|
||||
|
@ -532,7 +575,9 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.createConnection,
|
||||
widget.server == null
|
||||
? AppLocalizations.of(context)!.createConnection
|
||||
: AppLocalizations.of(context)!.editConnection,
|
||||
style: const TextStyle(
|
||||
fontSize: 20
|
||||
),
|
||||
|
|
76
lib/widgets/add_server/unsupported_version_modal.dart
Normal file
76
lib/widgets/add_server/unsupported_version_modal.dart
Normal file
|
@ -0,0 +1,76 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/config/minimum_server_version.dart';
|
||||
|
||||
class UnsupportedVersionModal extends StatelessWidget {
|
||||
final String serverVersion;
|
||||
final void Function() onClose;
|
||||
|
||||
const UnsupportedVersionModal({
|
||||
super.key,
|
||||
required this.serverVersion,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_rounded,
|
||||
size: 24,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.unsupportedServerVersion,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurface
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context)!.unsupportedServerVersionMessage,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.yourVersion(serverVersion),
|
||||
style: const TextStyle(
|
||||
fontStyle: FontStyle.italic
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.minimumRequiredVersion(
|
||||
serverVersion.contains("b")
|
||||
? MinimumServerVersion.beta
|
||||
: MinimumServerVersion.stable
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontStyle: FontStyle.italic
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
onClose();
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.close)
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue