mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-23 02:24:12 +01:00
chore: Update SDK and logviewer
This commit is contained in:
parent
184bf07920
commit
45b9c4f26c
@ -15,7 +15,6 @@ import 'package:flushbar/flushbar.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:logger_flutter/logger_flutter.dart';
|
||||
import 'package:universal_html/prefer_universal/html.dart' as html;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
@ -308,7 +307,6 @@ class MatrixState extends State<Matrix> {
|
||||
}
|
||||
|
||||
void initMatrix() {
|
||||
LogConsole.init();
|
||||
clientName =
|
||||
'${AppConfig.applicationName} ${kIsWeb ? 'Web' : Platform.operatingSystem}';
|
||||
final Set verificationMethods = <KeyVerificationMethod>{
|
||||
|
183
lib/views/log_view.dart
Normal file
183
lib/views/log_view.dart
Normal file
@ -0,0 +1,183 @@
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
class LogViewer extends StatefulWidget {
|
||||
@override
|
||||
_LogViewerState createState() => _LogViewerState();
|
||||
}
|
||||
|
||||
class _LogViewerState extends State<LogViewer> {
|
||||
Level logLevel = Level.debug;
|
||||
double fontSize = 14;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final outputEvents = Logs()
|
||||
.outputEvents
|
||||
.where((e) => e.level.index >= logLevel.index)
|
||||
.toList();
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
title: Text(logLevel.toString()),
|
||||
leading: BackButton(),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.zoom_in_outlined),
|
||||
onPressed: () => setState(() => fontSize++),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.zoom_out_outlined),
|
||||
onPressed: () => setState(() => fontSize--),
|
||||
),
|
||||
PopupMenuButton<Level>(
|
||||
itemBuilder: (context) => Level.values
|
||||
.map((level) => PopupMenuItem(
|
||||
child: Text(level.toString()),
|
||||
value: level,
|
||||
))
|
||||
.toList(),
|
||||
onSelected: (Level level) => setState(() => logLevel = level),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: outputEvents.length,
|
||||
itemBuilder: (context, i) => SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(fontSize: fontSize),
|
||||
children: _AnsiParser(outputEvents[i].lines.join('\n')).spans,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AnsiParser {
|
||||
static const TEXT = 0, BRACKET = 1, CODE = 2;
|
||||
final String text;
|
||||
|
||||
Color foreground;
|
||||
Color background;
|
||||
List<TextSpan> spans;
|
||||
|
||||
_AnsiParser(this.text) {
|
||||
final s = this.text;
|
||||
spans = [];
|
||||
var state = TEXT;
|
||||
StringBuffer buffer;
|
||||
var text = StringBuffer();
|
||||
var code = 0;
|
||||
List<int> codes;
|
||||
|
||||
for (var i = 0, n = s.length; i < n; i++) {
|
||||
var c = s[i];
|
||||
|
||||
switch (state) {
|
||||
case TEXT:
|
||||
if (c == '\u001b') {
|
||||
state = BRACKET;
|
||||
buffer = StringBuffer(c);
|
||||
code = 0;
|
||||
codes = [];
|
||||
} else {
|
||||
text.write(c);
|
||||
}
|
||||
break;
|
||||
|
||||
case BRACKET:
|
||||
buffer.write(c);
|
||||
if (c == '[') {
|
||||
state = CODE;
|
||||
} else {
|
||||
state = TEXT;
|
||||
text.write(buffer);
|
||||
}
|
||||
break;
|
||||
|
||||
case CODE:
|
||||
buffer.write(c);
|
||||
var codeUnit = c.codeUnitAt(0);
|
||||
if (codeUnit >= 48 && codeUnit <= 57) {
|
||||
code = code * 10 + codeUnit - 48;
|
||||
continue;
|
||||
} else if (c == ';') {
|
||||
codes.add(code);
|
||||
code = 0;
|
||||
continue;
|
||||
} else {
|
||||
if (text.isNotEmpty) {
|
||||
spans.add(createSpan(text.toString()));
|
||||
text.clear();
|
||||
}
|
||||
state = TEXT;
|
||||
if (c == 'm') {
|
||||
codes.add(code);
|
||||
handleCodes(codes);
|
||||
} else {
|
||||
text.write(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spans.add(createSpan(text.toString()));
|
||||
}
|
||||
|
||||
void handleCodes(List<int> codes) {
|
||||
if (codes.isEmpty) {
|
||||
codes.add(0);
|
||||
}
|
||||
|
||||
switch (codes[0]) {
|
||||
case 0:
|
||||
foreground = getColor(0, true);
|
||||
background = getColor(0, false);
|
||||
break;
|
||||
case 38:
|
||||
foreground = getColor(codes[2], true);
|
||||
break;
|
||||
case 39:
|
||||
foreground = getColor(0, true);
|
||||
break;
|
||||
case 48:
|
||||
background = getColor(codes[2], false);
|
||||
break;
|
||||
case 49:
|
||||
background = getColor(0, false);
|
||||
}
|
||||
}
|
||||
|
||||
Color getColor(int colorCode, bool foreground) {
|
||||
switch (colorCode) {
|
||||
case 0:
|
||||
return foreground ? Colors.black : Colors.transparent;
|
||||
case 12:
|
||||
return Colors.lightBlue[300];
|
||||
case 208:
|
||||
return Colors.orange[300];
|
||||
case 196:
|
||||
return Colors.red[300];
|
||||
case 199:
|
||||
return Colors.pink[300];
|
||||
default:
|
||||
return Colors.white;
|
||||
}
|
||||
}
|
||||
|
||||
TextSpan createSpan(String text) {
|
||||
return TextSpan(
|
||||
text: text,
|
||||
style: TextStyle(
|
||||
color: foreground,
|
||||
backgroundColor: background,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:fluffychat/components/dialogs/bootstrap_dialog.dart';
|
||||
import 'package:fluffychat/views/log_view.dart';
|
||||
import 'package:fluffychat/views/settings_3pid.dart';
|
||||
import 'package:fluffychat/views/settings_notifications.dart';
|
||||
import 'package:fluffychat/views/settings_style.dart';
|
||||
@ -17,7 +18,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:logger_flutter/logger_flutter.dart';
|
||||
|
||||
import '../components/adaptive_page_layout.dart';
|
||||
import '../components/content_banner.dart';
|
||||
@ -599,13 +599,7 @@ class _SettingsState extends State<Settings> {
|
||||
),
|
||||
),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
LogConsole(
|
||||
showCloseButton: true,
|
||||
dark: true,
|
||||
),
|
||||
),
|
||||
AppRoute.defaultRoute(context, LogViewer()),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
|
18
pubspec.lock
18
pubspec.lock
@ -195,7 +195,7 @@ packages:
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: b5cf8cacb6d9f96f04d110091e879e88249ec3ca
|
||||
resolved-ref: "0ed5c449190362b1334bdc586c0a672881703053"
|
||||
url: "https://gitlab.com/famedly/famedlysdk.git"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
@ -526,14 +526,7 @@ packages:
|
||||
name: logger
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.0"
|
||||
logger_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: logger_flutter
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.1"
|
||||
version: "0.9.4"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -858,13 +851,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.6"
|
||||
sensors:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sensors
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.2+6"
|
||||
sentry:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -64,7 +64,6 @@ dependencies:
|
||||
flutter_cache_manager: ^2.0.0
|
||||
open_noti_settings: ^0.0.4
|
||||
emoji_picker: ^0.1.0
|
||||
logger_flutter: ^0.7.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
Reference in New Issue
Block a user