refactor: Update SDK
This commit is contained in:
parent
b55a81e4ef
commit
91f52956f0
26 changed files with 57 additions and 187 deletions
|
|
@ -25,7 +25,7 @@ class PublicRoomListItem extends StatelessWidget {
|
|||
|
||||
Future<String> _joinRoomAndWait(BuildContext context) async {
|
||||
final roomId =
|
||||
await Matrix.of(context).client.joinRoomOrAlias(publicRoomEntry.roomId);
|
||||
await Matrix.of(context).client.joinRoom(publicRoomEntry.roomId);
|
||||
if (Matrix.of(context).client.getRoomById(roomId) == null) {
|
||||
await Matrix.of(context)
|
||||
.client
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class LogViewer extends StatefulWidget {
|
||||
@override
|
||||
|
|
@ -26,12 +24,10 @@ class _LogViewerState extends State<LogViewer> {
|
|||
IconButton(
|
||||
icon: Icon(Icons.zoom_in_outlined),
|
||||
onPressed: () => setState(() => fontSize++),
|
||||
tooltip: L10n.of(context).zoomIn,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.zoom_out_outlined),
|
||||
onPressed: () => setState(() => fontSize--),
|
||||
tooltip: L10n.of(context).zoomOut,
|
||||
),
|
||||
PopupMenuButton<Level>(
|
||||
itemBuilder: (context) => Level.values
|
||||
|
|
@ -48,141 +44,22 @@ class _LogViewerState extends State<LogViewer> {
|
|||
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,
|
||||
),
|
||||
),
|
||||
child: Text(outputEvents[i].toDisplayString()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AnsiParser {
|
||||
// ignore: constant_identifier_names
|
||||
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;
|
||||
final text = StringBuffer();
|
||||
var code = 0;
|
||||
List<int> codes;
|
||||
|
||||
// ignore: prefer_final_locals
|
||||
for (var i = 0, n = s.length; i < n; i++) {
|
||||
final 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);
|
||||
final 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;
|
||||
}
|
||||
extension on LogEvent {
|
||||
String toDisplayString() {
|
||||
var str = '# $title';
|
||||
if (exception != null) {
|
||||
str += ' - ${exception.toString()}';
|
||||
}
|
||||
|
||||
spans.add(createSpan(text.toString()));
|
||||
}
|
||||
|
||||
void handleCodes(List<int> codes) {
|
||||
if (codes.isEmpty) {
|
||||
codes.add(0);
|
||||
if (stackTrace != null) {
|
||||
str += '\n${stackTrace.toString()}';
|
||||
}
|
||||
|
||||
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,
|
||||
),
|
||||
);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
final statusMsg = await store.getItem(SettingKeys.ownStatusMessage);
|
||||
if (statusMsg?.isNotEmpty ?? false) {
|
||||
Logs().v('Send cached status message: "$statusMsg"');
|
||||
await client.sendPresence(
|
||||
await client.setPresence(
|
||||
client.userID,
|
||||
PresenceType.online,
|
||||
statusMsg: statusMsg,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class MessageReactions extends StatelessWidget {
|
|||
if (evt != null) {
|
||||
showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => evt.redact(),
|
||||
future: () => evt.redactEvent(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue