feat(calls): Тяжело...... Звонки. Вроде полностью. Почти.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export 'file_log_output_stub.dart'
|
||||
if (dart.library.io) 'file_log_output_io.dart';
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class FileLogOutput extends LogOutput {
|
||||
FileLogOutput._();
|
||||
|
||||
static final FileLogOutput instance = FileLogOutput._();
|
||||
|
||||
RandomAccessFile? _raf;
|
||||
String? _path;
|
||||
final List<String> _buffer = [];
|
||||
|
||||
static final RegExp _ansi = RegExp('\x1B\\[[0-9;]*m');
|
||||
|
||||
String? get path => _path;
|
||||
|
||||
Future<void> start() async {
|
||||
if (_raf != null) return;
|
||||
try {
|
||||
final dir = await getApplicationSupportDirectory();
|
||||
final file = File('${dir.path}/komet_calls.log');
|
||||
final raf = await file.open(mode: FileMode.write);
|
||||
_path = file.path;
|
||||
_raf = raf;
|
||||
_write('=== komet log ${file.path} ===');
|
||||
for (final line in _buffer) {
|
||||
_write(line);
|
||||
}
|
||||
_buffer.clear();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
void _write(String line) {
|
||||
try {
|
||||
_raf?.writeStringSync('$line\n');
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@override
|
||||
void output(OutputEvent event) {
|
||||
if (_raf == null) {
|
||||
for (final line in event.lines) {
|
||||
if (_buffer.length < 20000) _buffer.add(line.replaceAll(_ansi, ''));
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (final line in event.lines) {
|
||||
_write(line.replaceAll(_ansi, ''));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> destroy() async {
|
||||
try {
|
||||
await _raf?.close();
|
||||
} catch (_) {}
|
||||
_raf = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
class FileLogOutput extends LogOutput {
|
||||
FileLogOutput._();
|
||||
|
||||
static final FileLogOutput instance = FileLogOutput._();
|
||||
|
||||
String? get path => null;
|
||||
|
||||
Future<void> start() async {}
|
||||
|
||||
@override
|
||||
void output(OutputEvent event) {}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../frontend/widgets/call_link_handler.dart';
|
||||
import '../../frontend/widgets/custom_notification.dart';
|
||||
|
||||
Future<void> openExternalUrl(BuildContext context, String url) async {
|
||||
if (await tryHandleCallLink(context, url)) return;
|
||||
if (!context.mounted) return;
|
||||
|
||||
final uri = Uri.tryParse(url);
|
||||
if (uri == null) {
|
||||
showCustomNotification(context, 'Некорректная ссылка');
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
import 'file_log_output.dart';
|
||||
|
||||
Level _minimumLogLevel() {
|
||||
const raw = String.fromEnvironment('KOMET_LOG_LEVEL', defaultValue: '');
|
||||
switch (raw.toLowerCase()) {
|
||||
@@ -41,8 +43,13 @@ final logger = Logger(
|
||||
filter: _logFilter(),
|
||||
level: _minimumLogLevel(),
|
||||
printer: KometLogPrinter(),
|
||||
output: MultiOutput([ConsoleOutput(), FileLogOutput.instance]),
|
||||
);
|
||||
|
||||
Future<void> startFileLogging() => FileLogOutput.instance.start();
|
||||
|
||||
String? get logFilePath => FileLogOutput.instance.path;
|
||||
|
||||
int _importanceSortKey(Level level) {
|
||||
final v = level.value;
|
||||
if (v >= 5999) {
|
||||
|
||||
Reference in New Issue
Block a user