mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-04 20:30:35 +00:00
Improved app logs
This commit is contained in:
parent
f3ce298994
commit
191bae78bb
8 changed files with 297 additions and 65 deletions
27
lib/models/app_log.dart
Normal file
27
lib/models/app_log.dart
Normal file
|
@ -0,0 +1,27 @@
|
|||
import 'dart:convert';
|
||||
|
||||
class AppLog {
|
||||
final String type;
|
||||
final DateTime dateTime;
|
||||
final String message;
|
||||
final int? statusCode;
|
||||
final String? resBody;
|
||||
|
||||
const AppLog({
|
||||
required this.type,
|
||||
required this.dateTime,
|
||||
required this.message,
|
||||
this.statusCode,
|
||||
this.resBody,
|
||||
});
|
||||
|
||||
Map<String, String> toMap() {
|
||||
return {
|
||||
'type': type,
|
||||
'dateTime': dateTime.toString(),
|
||||
'message': message,
|
||||
'statusCode': statusCode.toString(),
|
||||
'resBody': resBody.toString()
|
||||
};
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ import 'package:flutter/scheduler.dart';
|
|||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:sqflite/sqlite_api.dart';
|
||||
|
||||
import 'package:adguard_home_manager/models/app_log.dart';
|
||||
|
||||
class AppConfigProvider with ChangeNotifier {
|
||||
Database? _dbInstance;
|
||||
|
||||
|
@ -15,7 +17,7 @@ class AppConfigProvider with ChangeNotifier {
|
|||
|
||||
int _selectedClientsTab = 0;
|
||||
|
||||
final List<Map<dynamic, dynamic>> _logs = [];
|
||||
final List<AppLog> _logs = [];
|
||||
|
||||
PackageInfo? get getAppInfo {
|
||||
return _appInfo;
|
||||
|
@ -55,7 +57,7 @@ class AppConfigProvider with ChangeNotifier {
|
|||
return _selectedClientsTab;
|
||||
}
|
||||
|
||||
List<Map<dynamic, dynamic>> get logs {
|
||||
List<AppLog> get logs {
|
||||
return _logs;
|
||||
}
|
||||
|
||||
|
@ -80,7 +82,7 @@ class AppConfigProvider with ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
void addLog(Map<dynamic, dynamic> log) {
|
||||
void addLog(AppLog log) {
|
||||
_logs.add(log);
|
||||
notifyListeners();
|
||||
}
|
||||
|
|
170
lib/screens/app_logs/app_log_details_modal.dart
Normal file
170
lib/screens/app_logs/app_log_details_modal.dart
Normal file
|
@ -0,0 +1,170 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adguard_home_manager/models/app_log.dart';
|
||||
|
||||
class AppLogDetailsModal extends StatefulWidget {
|
||||
final AppLog log;
|
||||
|
||||
const AppLogDetailsModal({
|
||||
Key? key,
|
||||
required this.log
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AppLogDetailsModal> createState() => _AppLogDetailsModalState();
|
||||
}
|
||||
|
||||
class _AppLogDetailsModalState extends State<AppLogDetailsModal> {
|
||||
String valueToShow = 'message';
|
||||
|
||||
String generateBody() {
|
||||
switch (valueToShow) {
|
||||
case 'message':
|
||||
return widget.log.message;
|
||||
|
||||
case 'statusCode':
|
||||
return widget.log.statusCode != null
|
||||
? widget.log.statusCode.toString()
|
||||
: "[NO STAUS CODE]";
|
||||
|
||||
case 'body':
|
||||
return widget.log.resBody != null
|
||||
? widget.log.resBody.toString()
|
||||
: "[NO RESPONSE BODY]";
|
||||
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Log details"),
|
||||
scrollable: true,
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Material(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15)
|
||||
),
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15)
|
||||
),
|
||||
onTap: () => setState(() => valueToShow = 'message'),
|
||||
child: AnimatedContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15)
|
||||
),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
color: valueToShow == 'message'
|
||||
? Theme.of(context).primaryColor
|
||||
: Theme.of(context).primaryColor.withOpacity(0.05)
|
||||
),
|
||||
child: Text(
|
||||
"Message",
|
||||
style: TextStyle(
|
||||
color: valueToShow == 'message'
|
||||
? Colors.white
|
||||
: null
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => setState(() => valueToShow = 'statusCode'),
|
||||
child: AnimatedContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
color: valueToShow == 'statusCode'
|
||||
? Theme.of(context).primaryColor
|
||||
: Theme.of(context).primaryColor.withOpacity(0.05)
|
||||
),
|
||||
child: Text(
|
||||
"Status code",
|
||||
style: TextStyle(
|
||||
color: valueToShow == 'statusCode'
|
||||
? Colors.white
|
||||
: null
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Material(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15)
|
||||
),
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15)
|
||||
),
|
||||
onTap: () => setState(() => valueToShow = 'body'),
|
||||
child: AnimatedContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15)
|
||||
),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).primaryColor
|
||||
),
|
||||
color: valueToShow == 'body'
|
||||
? Theme.of(context).primaryColor
|
||||
: Theme.of(context).primaryColor.withOpacity(0.05)
|
||||
),
|
||||
child: Text(
|
||||
"Body",
|
||||
style: TextStyle(
|
||||
color: valueToShow == 'body'
|
||||
? Colors.white
|
||||
: null
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(generateBody())
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text("Close")
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,22 +2,24 @@
|
|||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:adguard_home_manager/screens/app_logs/app_log_details_modal.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
||||
class Logs extends StatelessWidget {
|
||||
const Logs({Key? key}) : super(key: key);
|
||||
class AppLogs extends StatelessWidget {
|
||||
const AppLogs({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||
|
||||
void copyLogsClipboard() async {
|
||||
List<Map<String, String>> logsString = appConfigProvider.logs.map((log) => log.toMap()).toList();
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: jsonEncode(appConfigProvider.logs))
|
||||
ClipboardData(text: jsonEncode(logsString))
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
|
@ -46,9 +48,17 @@ class Logs extends StatelessWidget {
|
|||
padding: const EdgeInsets.only(top: 0),
|
||||
itemCount: appConfigProvider.logs.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
title: Text(appConfigProvider.logs[index]['message']),
|
||||
subtitle: Text(appConfigProvider.logs[index]['time']),
|
||||
trailing: Text(appConfigProvider.logs[index]['type']),
|
||||
title: Text(appConfigProvider.logs[index].message),
|
||||
subtitle: Text(appConfigProvider.logs[index].dateTime.toString()),
|
||||
trailing: Text(appConfigProvider.logs[index].type),
|
||||
onTap: () => {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AppLogDetailsModal(
|
||||
log: appConfigProvider.logs[index]
|
||||
)
|
||||
)
|
||||
},
|
||||
)
|
||||
)
|
||||
: const Center(
|
|
@ -6,7 +6,7 @@ import 'package:adguard_home_manager/screens/settings/theme_modal.dart';
|
|||
import 'package:adguard_home_manager/screens/settings/custom_list_tile.dart';
|
||||
import 'package:adguard_home_manager/screens/settings/section_label.dart';
|
||||
import 'package:adguard_home_manager/screens/servers/servers.dart';
|
||||
import 'package:adguard_home_manager/screens/logs/logs.dart';
|
||||
import 'package:adguard_home_manager/screens/app_logs/app_logs.dart';
|
||||
|
||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||
|
@ -86,7 +86,7 @@ class Settings extends StatelessWidget {
|
|||
label: AppLocalizations.of(context)!.createdBy,
|
||||
description: "JGeek00",
|
||||
onDoubleTap: () => Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const Logs())
|
||||
MaterialPageRoute(builder: (context) => const AppLogs())
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:adguard_home_manager/models/app_log.dart';
|
||||
import 'package:adguard_home_manager/models/server_status.dart';
|
||||
import 'package:adguard_home_manager/models/clients.dart';
|
||||
import 'package:adguard_home_manager/models/clients_allowed_blocked.dart';
|
||||
|
@ -51,27 +51,77 @@ Future login(Server server) async {
|
|||
}
|
||||
else if (result.statusCode == 400) {
|
||||
return {
|
||||
'result': 'error',
|
||||
'message': 'invalid_username_password'
|
||||
'result': 'invalid_username_password',
|
||||
'log': AppLog(
|
||||
type: 'login',
|
||||
dateTime: DateTime.now(),
|
||||
message: 'invalid_username_password',
|
||||
statusCode: result.statusCode,
|
||||
resBody: result.body
|
||||
)
|
||||
};
|
||||
}
|
||||
else if (result.statusCode == 429) {
|
||||
return {
|
||||
'result': 'error',
|
||||
'message': 'many_attempts'
|
||||
'result': 'many_attempts',
|
||||
'log': AppLog(
|
||||
type: 'login',
|
||||
dateTime: DateTime.now(),
|
||||
message: 'many_attempts',
|
||||
statusCode: result.statusCode,
|
||||
resBody: result.body
|
||||
)
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {'result': 'error', 'message': 'error_code_not_expected'};
|
||||
return {
|
||||
'result': 'error',
|
||||
'log': AppLog(
|
||||
type: 'login',
|
||||
dateTime: DateTime.now(),
|
||||
message: 'error_code_not_expected',
|
||||
statusCode: result.statusCode,
|
||||
resBody: result.body
|
||||
)
|
||||
};
|
||||
}
|
||||
} on SocketException {
|
||||
return {'result': 'no_connection', 'message': 'SocketException'};
|
||||
return {
|
||||
'result': 'no_connection',
|
||||
'log': AppLog(
|
||||
type: 'login',
|
||||
dateTime: DateTime.now(),
|
||||
message: 'SocketException'
|
||||
)
|
||||
};
|
||||
} on TimeoutException {
|
||||
return {'result': 'no_connection', 'message': 'TimeoutException'};
|
||||
return {
|
||||
'result': 'no_connection',
|
||||
'log': AppLog(
|
||||
type: 'login',
|
||||
dateTime: DateTime.now(),
|
||||
message: 'TimeoutException'
|
||||
)
|
||||
};
|
||||
} on HandshakeException {
|
||||
return {'result': 'ssl_error', 'message': 'HandshakeException'};
|
||||
return {
|
||||
'result': 'ssl_error',
|
||||
'message': 'HandshakeException',
|
||||
'log': AppLog(
|
||||
type: 'login',
|
||||
dateTime: DateTime.now(),
|
||||
message: 'TimeoutException'
|
||||
)
|
||||
};
|
||||
} catch (e) {
|
||||
return {'result': 'error', 'message': e.toString()};
|
||||
return {
|
||||
'result': 'error',
|
||||
'log': AppLog(
|
||||
type: 'login',
|
||||
dateTime: DateTime.now(),
|
||||
message: e.toString()
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -275,11 +275,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
Navigator.pop(context);
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog({
|
||||
'type': 'login',
|
||||
'time': DateTime.now().toString(),
|
||||
'message': result['message']
|
||||
});
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.connectionNotCreated),
|
||||
|
@ -289,11 +285,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
}
|
||||
}
|
||||
else if (result['result'] == 'invalid_username_password') {
|
||||
appConfigProvider.addLog({
|
||||
'type': 'login',
|
||||
'time': DateTime.now().toString(),
|
||||
'message': result['message']
|
||||
});
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.invalidUsernamePassword),
|
||||
|
@ -302,11 +294,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
);
|
||||
}
|
||||
else if (result['result'] == 'many_attempts') {
|
||||
appConfigProvider.addLog({
|
||||
'type': 'login',
|
||||
'time': DateTime.now().toString(),
|
||||
'message': result['message']
|
||||
});
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.tooManyAttempts),
|
||||
|
@ -315,11 +303,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
);
|
||||
}
|
||||
else if (result['result'] == 'no_connection') {
|
||||
appConfigProvider.addLog({
|
||||
'type': 'login',
|
||||
'time': DateTime.now().toString(),
|
||||
'message': result['message']
|
||||
});
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.cantReachServer),
|
||||
|
@ -328,11 +312,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
);
|
||||
}
|
||||
else if (result['result'] == 'ssl_error') {
|
||||
appConfigProvider.addLog({
|
||||
'type': 'login',
|
||||
'time': DateTime.now().toString(),
|
||||
'message': result['message']
|
||||
});
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.sslError),
|
||||
|
@ -341,11 +321,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
);
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog({
|
||||
'type': 'login',
|
||||
'time': DateTime.now().toString(),
|
||||
'message': result['message']
|
||||
});
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.unknownError),
|
||||
|
@ -383,7 +359,8 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
);
|
||||
}
|
||||
}
|
||||
else if (result['result'] == 'error' && result['message'] == 'invalid_username_password') {
|
||||
else if (result['result'] == 'invalid_username_password') {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.invalidUsernamePassword),
|
||||
|
@ -391,7 +368,8 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
)
|
||||
);
|
||||
}
|
||||
else if (result['result'] == 'error' && result['message'] == 'many_attempts') {
|
||||
else if (result['result'] == 'many_attempts') {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.tooManyAttempts),
|
||||
|
@ -399,7 +377,8 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
)
|
||||
);
|
||||
}
|
||||
else if (result['result'] == 'error' && result['message'] == 'no_connection') {
|
||||
else if (result['result'] == 'no_connection') {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.cantReachServer),
|
||||
|
@ -407,7 +386,8 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
)
|
||||
);
|
||||
}
|
||||
else if (result['result'] == 'error' && result['message'] == 'ssl_error') {
|
||||
else if (result['result'] == 'ssl_error') {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.sslError),
|
||||
|
@ -416,6 +396,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
);
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.unknownError),
|
||||
|
|
|
@ -72,11 +72,7 @@ class ServersList extends StatelessWidget {
|
|||
serversProvider.setServerStatusLoad(1);
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog({
|
||||
'type': 'login',
|
||||
'time': DateTime.now().toString(),
|
||||
'message': result['message']
|
||||
});
|
||||
appConfigProvider.addLog(result['log']);
|
||||
serversProvider.setServerStatusLoad(2);
|
||||
}
|
||||
|
||||
|
@ -84,11 +80,7 @@ class ServersList extends StatelessWidget {
|
|||
}
|
||||
else {
|
||||
process.close();
|
||||
appConfigProvider.addLog({
|
||||
'type': 'login',
|
||||
'time': DateTime.now().toString(),
|
||||
'message': result['message']
|
||||
});
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.cannotConnect),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue