mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-03 01:28:17 +08:00
committed by
GitHub
parent
56756c5c85
commit
41c8e1a538
@@ -11,8 +11,7 @@ import 'package:flutter/widgets.dart';
|
||||
/// Adapted from [WidgetsFlutterBinding]
|
||||
///
|
||||
class ScaledWidgetsFlutterBinding extends WidgetsFlutterBinding {
|
||||
ScaledWidgetsFlutterBinding._({double scaleFactor = 1.0})
|
||||
: _scaleFactor = scaleFactor;
|
||||
ScaledWidgetsFlutterBinding._({this._scaleFactor = 1.0});
|
||||
|
||||
/// Calculate scale factor from device size.
|
||||
double _scaleFactor;
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:PiliPlus/plugin/pl_player/utils/fullscreen.dart';
|
||||
import 'package:PiliPlus/router/app_pages.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
import 'package:PiliPlus/services/download/download_service.dart';
|
||||
import 'package:PiliPlus/services/logger.dart';
|
||||
import 'package:PiliPlus/services/service_locator.dart';
|
||||
import 'package:PiliPlus/utils/cache_manager.dart';
|
||||
import 'package:PiliPlus/utils/calc_window_position.dart';
|
||||
@@ -201,32 +202,12 @@ void main() async {
|
||||
'${NativePlayer.apiVersion >> 16}.${NativePlayer.apiVersion & 0xFFFF}',
|
||||
};
|
||||
final fileHandler = await JsonFileHandler.init();
|
||||
final Catcher2Options debugConfig = Catcher2Options(
|
||||
SilentReportMode(),
|
||||
[
|
||||
?fileHandler,
|
||||
ConsoleHandler(
|
||||
enableDeviceParameters: false,
|
||||
enableApplicationParameters: false,
|
||||
enableCustomParameters: true,
|
||||
),
|
||||
],
|
||||
customParameters: customParameters,
|
||||
);
|
||||
|
||||
final Catcher2Options releaseConfig = Catcher2Options(
|
||||
SilentReportMode(),
|
||||
[
|
||||
?fileHandler,
|
||||
ConsoleHandler(enableCustomParameters: true),
|
||||
],
|
||||
customParameters: customParameters,
|
||||
);
|
||||
|
||||
Catcher2(
|
||||
debugConfig: debugConfig,
|
||||
releaseConfig: releaseConfig,
|
||||
rootWidget: const MyApp(),
|
||||
[?fileHandler, const ConsoleHandler()],
|
||||
const MyApp(),
|
||||
logger: logger,
|
||||
customParameters: customParameters,
|
||||
);
|
||||
} else {
|
||||
runApp(const MyApp());
|
||||
|
||||
@@ -15,7 +15,6 @@ import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/widgets/vote.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/extension/num_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/string_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/theme_ext.dart';
|
||||
import 'package:PiliPlus/utils/image_utils.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
|
||||
@@ -56,25 +56,20 @@ class _FavFolderSortPageState extends State<FavFolderSortPage>
|
||||
);
|
||||
}
|
||||
|
||||
void onReorder(int oldIndex, int newIndex) {
|
||||
void onReorderItem(int oldIndex, int newIndex) {
|
||||
if (oldIndex == 0 || newIndex == 0) {
|
||||
SmartDialog.showToast('默认收藏夹不支持排序');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newIndex > oldIndex) {
|
||||
newIndex -= 1;
|
||||
}
|
||||
|
||||
final tabsItem = sortList.removeAt(oldIndex);
|
||||
sortList.insert(newIndex, tabsItem);
|
||||
sortList.insert(newIndex, sortList.removeAt(oldIndex));
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget get _buildBody {
|
||||
return ReorderableListView.builder(
|
||||
onReorder: onReorder,
|
||||
onReorderItem: onReorderItem,
|
||||
proxyDecorator: proxyDecorator,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemCount: sortList.length,
|
||||
|
||||
@@ -81,11 +81,7 @@ class _FavSortPageState extends State<FavSortPage> with ReorderMixin {
|
||||
);
|
||||
}
|
||||
|
||||
void onReorder(int oldIndex, int newIndex) {
|
||||
if (newIndex > oldIndex) {
|
||||
newIndex -= 1;
|
||||
}
|
||||
|
||||
void onReorderItem(int oldIndex, int newIndex) {
|
||||
final oldItem = sortList[oldIndex];
|
||||
final newItem = sortList.getOrNull(
|
||||
oldIndex > newIndex ? newIndex - 1 : newIndex, // might be Negative
|
||||
@@ -94,15 +90,14 @@ class _FavSortPageState extends State<FavSortPage> with ReorderMixin {
|
||||
'${newItem == null ? '0:0' : '${newItem.id}:${newItem.type}'}:${oldItem.id}:${oldItem.type}',
|
||||
);
|
||||
|
||||
final tabsItem = sortList.removeAt(oldIndex);
|
||||
sortList.insert(newIndex, tabsItem);
|
||||
sortList.insert(newIndex, sortList.removeAt(oldIndex));
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget get _buildBody {
|
||||
final child = ReorderableListView.builder(
|
||||
onReorder: onReorder,
|
||||
onReorderItem: onReorderItem,
|
||||
proxyDecorator: proxyDecorator,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding:
|
||||
|
||||
@@ -71,20 +71,14 @@ class _FollowTagSortPageState extends State<FollowTagSortPage>
|
||||
);
|
||||
}
|
||||
|
||||
void onReorder(int oldIndex, int newIndex) {
|
||||
if (newIndex > oldIndex) {
|
||||
newIndex -= 1;
|
||||
}
|
||||
|
||||
final tabsItem = _customTags.removeAt(oldIndex);
|
||||
_customTags.insert(newIndex, tabsItem);
|
||||
|
||||
void onReorderItem(int oldIndex, int newIndex) {
|
||||
_customTags.insert(newIndex, _customTags.removeAt(oldIndex));
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget get _buildBody {
|
||||
return ReorderableListView.builder(
|
||||
onReorder: onReorder,
|
||||
onReorderItem: onReorderItem,
|
||||
proxyDecorator: proxyDecorator,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.only(
|
||||
|
||||
@@ -52,8 +52,7 @@ class _BarSetPageState extends State<BarSetPage> with ReorderMixin {
|
||||
SmartDialog.showToast('重置成功,下次启动时生效');
|
||||
}
|
||||
|
||||
void onReorder(int oldIndex, int newIndex) {
|
||||
if (newIndex > oldIndex) newIndex -= 1;
|
||||
void onReorderItem(int oldIndex, int newIndex) {
|
||||
list.insert(newIndex, list.removeAt(oldIndex));
|
||||
setState(() {});
|
||||
}
|
||||
@@ -71,7 +70,7 @@ class _BarSetPageState extends State<BarSetPage> with ReorderMixin {
|
||||
],
|
||||
),
|
||||
body: ReorderableListView(
|
||||
onReorder: onReorder,
|
||||
onReorderItem: onReorderItem,
|
||||
proxyDecorator: proxyDecorator,
|
||||
footer: Padding(
|
||||
padding:
|
||||
|
||||
@@ -11,8 +11,8 @@ import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:catcher_2/model/platform_type.dart';
|
||||
import 'package:catcher_2/model/report.dart' as catcher;
|
||||
import 'package:catcher_2/catcher_2.dart';
|
||||
import 'package:catcher_2/utils/log_printer.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@@ -27,25 +27,25 @@ class LogsPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LogsPageState extends State<LogsPage> {
|
||||
List<Report> logsContent = [];
|
||||
Report? latestLog;
|
||||
List<_ExpandedItem<Report>> logsContent = [];
|
||||
_ExpandedItem<_DeviceInfo>? _deviceInfo;
|
||||
late bool enableLog = Pref.enableLog;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_initDeviceInfo();
|
||||
getLog();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (latestLog != null) {
|
||||
final time = latestLog!.dateTime;
|
||||
if (DateTime.now().difference(time) >= const Duration(days: 14)) {
|
||||
LoggerUtils.clearLogs();
|
||||
}
|
||||
void _initDeviceInfo() {
|
||||
if (Catcher2.instance case final c?) {
|
||||
_deviceInfo = _ExpandedItem((
|
||||
c.deviceParameters,
|
||||
c.applicationParameters,
|
||||
c.customParameters,
|
||||
));
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> getLog() async {
|
||||
@@ -53,19 +53,18 @@ class _LogsPageState extends State<LogsPage> {
|
||||
logsContent = (await logsPath.readAsLines()).reversed.map((i) {
|
||||
try {
|
||||
final log = Report.fromJson(jsonDecode(i));
|
||||
latestLog ??= log;
|
||||
return log;
|
||||
return _ExpandedItem(log);
|
||||
} catch (e, s) {
|
||||
return Report(
|
||||
'Parse log failed: $e\n\n\n$i',
|
||||
s,
|
||||
DateTime.now(),
|
||||
const {},
|
||||
const {},
|
||||
const {},
|
||||
null,
|
||||
PlatformType.unknown,
|
||||
null,
|
||||
return _ExpandedItem(
|
||||
Report(
|
||||
'Parse log failed: $e\n\n\n$i',
|
||||
s,
|
||||
DateTime.now(),
|
||||
const {},
|
||||
const {},
|
||||
const {},
|
||||
null,
|
||||
),
|
||||
);
|
||||
}
|
||||
}).toList();
|
||||
@@ -119,7 +118,7 @@ class _LogsPageState extends State<LogsPage> {
|
||||
onTap: () => Timer.periodic(
|
||||
const Duration(milliseconds: 3500),
|
||||
(timer) {
|
||||
Utils.reportError('Manual');
|
||||
Utils.reportError('Manual', StackTrace.current);
|
||||
if (timer.tick > 3) {
|
||||
timer.cancel();
|
||||
if (mounted) getLog();
|
||||
@@ -146,10 +145,7 @@ class _LogsPageState extends State<LogsPage> {
|
||||
child: const Text('错误反馈'),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
latestLog = null;
|
||||
clearLogs();
|
||||
},
|
||||
onTap: clearLogs,
|
||||
child: const Text('清空日志'),
|
||||
),
|
||||
],
|
||||
@@ -157,7 +153,7 @@ class _LogsPageState extends State<LogsPage> {
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
),
|
||||
body: logsContent.isNotEmpty
|
||||
body: logsContent.isNotEmpty || _deviceInfo != null
|
||||
? Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: padding.left + 12,
|
||||
@@ -165,11 +161,11 @@ class _LogsPageState extends State<LogsPage> {
|
||||
),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
if (latestLog != null)
|
||||
if (_deviceInfo != null)
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const .only(bottom: 12),
|
||||
child: InfoCard(report: latestLog!),
|
||||
child: _InfoCard(info: _deviceInfo!),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
@@ -177,7 +173,7 @@ class _LogsPageState extends State<LogsPage> {
|
||||
sliver: SliverList.separated(
|
||||
itemCount: logsContent.length,
|
||||
itemBuilder: (context, index) =>
|
||||
ReportCard(report: logsContent[index]),
|
||||
_ReportCard(report: logsContent[index]),
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 12),
|
||||
),
|
||||
),
|
||||
@@ -189,10 +185,16 @@ class _LogsPageState extends State<LogsPage> {
|
||||
}
|
||||
}
|
||||
|
||||
class InfoCard extends StatelessWidget {
|
||||
final Report report;
|
||||
typedef _DeviceInfo = (
|
||||
Map<String, dynamic>,
|
||||
Map<String, dynamic>,
|
||||
Map<String, dynamic>,
|
||||
);
|
||||
|
||||
const InfoCard({super.key, required this.report});
|
||||
class _InfoCard extends StatelessWidget {
|
||||
final _ExpandedItem<_DeviceInfo> info;
|
||||
|
||||
const _InfoCard({required this.info});
|
||||
|
||||
Widget _buildMapSection(
|
||||
Color color,
|
||||
@@ -210,11 +212,7 @@ class InfoCard extends StatelessWidget {
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
fontSize: 15,
|
||||
),
|
||||
style: TextStyle(fontWeight: .bold, color: color, fontSize: 15),
|
||||
),
|
||||
...map.entries.map(
|
||||
(entry) => Text.rich(
|
||||
@@ -250,58 +248,47 @@ class InfoCard extends StatelessWidget {
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'相关信息',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15,
|
||||
),
|
||||
style: TextStyle(fontWeight: .bold, fontSize: 15),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
overflow: .ellipsis,
|
||||
),
|
||||
),
|
||||
iconButton(
|
||||
size: 34,
|
||||
iconSize: 22,
|
||||
tooltip: info.isExpanded ? '收起' : '展开',
|
||||
icon: Icon(
|
||||
report.isExpanded ? Icons.expand_less : Icons.expand_more,
|
||||
info.isExpanded ? Icons.expand_less : Icons.expand_more,
|
||||
),
|
||||
onPressed: () {
|
||||
report.isExpanded = !report.isExpanded;
|
||||
info.isExpanded = !info.isExpanded;
|
||||
(context as Element).markNeedsBuild();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
if (report.isExpanded) ...[
|
||||
_buildMapSection(
|
||||
colorScheme.primary,
|
||||
'设备信息',
|
||||
report.deviceParameters,
|
||||
),
|
||||
_buildMapSection(
|
||||
colorScheme.primary,
|
||||
'应用信息',
|
||||
report.applicationParameters,
|
||||
),
|
||||
_buildMapSection(
|
||||
colorScheme.primary,
|
||||
'编译信息',
|
||||
report.customParameters,
|
||||
),
|
||||
if (info.isExpanded) ...[
|
||||
_buildMapSection(colorScheme.primary, '设备信息', info.item.$1),
|
||||
_buildMapSection(colorScheme.primary, '应用信息', info.item.$2),
|
||||
_buildMapSection(colorScheme.primary, '编译信息', info.item.$3),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
class ReportCard extends StatelessWidget {
|
||||
final Report report;
|
||||
class _ReportCard extends StatelessWidget {
|
||||
final _ExpandedItem<Report> report;
|
||||
|
||||
const ReportCard({super.key, required this.report});
|
||||
const _ReportCard({required this.report});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = ColorScheme.of(context);
|
||||
late final stackTrace = report.stackTrace.toString().trim();
|
||||
final dateTime = DateFormatUtils.longFormatDs.format(report.dateTime);
|
||||
late final stackTrace = PrettyLogPrinter.formatStackString(
|
||||
report.item.stackTrace?.toString(),
|
||||
-1,
|
||||
);
|
||||
final dateTime = DateFormatUtils.longFormatDs.format(report.item.dateTime);
|
||||
return _card([
|
||||
Row(
|
||||
crossAxisAlignment: .start,
|
||||
@@ -312,13 +299,10 @@ class ReportCard extends StatelessWidget {
|
||||
crossAxisAlignment: .start,
|
||||
children: [
|
||||
Text(
|
||||
report.error.toString(),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15,
|
||||
),
|
||||
report.item.error.toString(),
|
||||
style: const TextStyle(fontWeight: .bold, fontSize: 15),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
overflow: .ellipsis,
|
||||
),
|
||||
Text(
|
||||
dateTime,
|
||||
@@ -334,6 +318,7 @@ class ReportCard extends StatelessWidget {
|
||||
iconButton(
|
||||
size: 34,
|
||||
iconSize: 22,
|
||||
tooltip: '复制',
|
||||
onPressed: () {
|
||||
Utils.copyText('```\n$report```', needToast: false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -343,14 +328,12 @@ class ReportCard extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.copy_outlined,
|
||||
size: 16,
|
||||
),
|
||||
icon: const Icon(Icons.copy_outlined, size: 16),
|
||||
),
|
||||
iconButton(
|
||||
size: 34,
|
||||
iconSize: 22,
|
||||
tooltip: report.isExpanded ? '收起' : '展开',
|
||||
icon: Icon(
|
||||
report.isExpanded ? Icons.expand_less : Icons.expand_more,
|
||||
),
|
||||
@@ -373,16 +356,14 @@ class ReportCard extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
padding: const .all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surface,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
border: Border.all(
|
||||
color: colorScheme.outline.withValues(alpha: 0.5),
|
||||
),
|
||||
borderRadius: const .all(.circular(8)),
|
||||
border: .all(color: colorScheme.outline.withValues(alpha: 0.5)),
|
||||
),
|
||||
child: SelectableText(
|
||||
report.error.toString(),
|
||||
report.item.error.toString(),
|
||||
style: TextStyle(
|
||||
fontFamily: 'Monospace',
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
@@ -390,7 +371,7 @@ class ReportCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
// stackTrace may be null or String("null") or blank
|
||||
if (stackTrace.isNotEmpty && stackTrace != 'null') ...[
|
||||
if (stackTrace != null && stackTrace.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'堆栈跟踪',
|
||||
@@ -402,21 +383,29 @@ class ReportCard extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
padding: const .all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surface,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
border: Border.all(
|
||||
color: colorScheme.outline.withValues(alpha: 0.5),
|
||||
),
|
||||
borderRadius: const .all(.circular(8)),
|
||||
border: .all(color: colorScheme.outline.withValues(alpha: 0.5)),
|
||||
),
|
||||
child: SelectableText(
|
||||
stackTrace,
|
||||
style: TextStyle(
|
||||
fontFamily: 'Monospace',
|
||||
fontSize: 13,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
child: SelectableText.rich(
|
||||
TextSpan(
|
||||
children: stackTrace
|
||||
.map(
|
||||
(i) => TextSpan(
|
||||
text: '$i\n',
|
||||
style: i.contains('(package:${Constants.appName}')
|
||||
? TextStyle(
|
||||
color: colorScheme.onSurface,
|
||||
fontWeight: .w600,
|
||||
)
|
||||
: TextStyle(color: colorScheme.onSurfaceVariant),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
style: const TextStyle(fontFamily: 'Monospace', fontSize: 13),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -437,45 +426,12 @@ Widget _card(List<Widget> contents) {
|
||||
);
|
||||
}
|
||||
|
||||
class Report extends catcher.Report {
|
||||
Report(
|
||||
super.error,
|
||||
super.stackTrace,
|
||||
super.dateTime,
|
||||
super.deviceParameters,
|
||||
super.applicationParameters,
|
||||
super.customParameters,
|
||||
super.errorDetails,
|
||||
super.platformType,
|
||||
super.screenshot,
|
||||
);
|
||||
|
||||
class _ExpandedItem<T> {
|
||||
bool isExpanded = false;
|
||||
final T item;
|
||||
|
||||
factory Report.fromJson(Map<String, dynamic> json) => Report(
|
||||
json['error'],
|
||||
json['stackTrace'],
|
||||
DateTime.tryParse(json['dateTime'] ?? '') ?? DateTime(1970),
|
||||
json['deviceParameters'] ?? const {},
|
||||
json['applicationParameters'] ?? const {},
|
||||
json['customParameters'] ?? const {},
|
||||
null,
|
||||
PlatformType.values.byName(json['platformType']),
|
||||
null,
|
||||
);
|
||||
|
||||
static String _params2String(Map<String, dynamic> params) {
|
||||
return params.entries
|
||||
.map((entry) => '${entry.key}: ${entry.value}\n')
|
||||
.join();
|
||||
}
|
||||
_ExpandedItem(this.item);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '------- DEVICE INFO -------\n${_params2String(deviceParameters)}'
|
||||
'------- APP INFO -------\n${_params2String(applicationParameters)}'
|
||||
'------- ERROR -------\n$error\n'
|
||||
'------- STACK TRACE -------\n${stackTrace.toString().trim()}\n'
|
||||
'------- CUSTOM INFO -------\n${_params2String(customParameters)}';
|
||||
}
|
||||
String toString() => item.toString();
|
||||
}
|
||||
|
||||
@@ -317,8 +317,8 @@ class _DanmakuTip extends SingleChildRenderObjectWidget {
|
||||
|
||||
class _RenderDanmakuTip extends RenderProxyBox {
|
||||
_RenderDanmakuTip({
|
||||
required double offset,
|
||||
}) : _offset = offset;
|
||||
required this._offset,
|
||||
});
|
||||
|
||||
double _offset;
|
||||
double get offset => _offset;
|
||||
|
||||
@@ -2,30 +2,19 @@ import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/utils/json_file_handler.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:catcher_2/catcher_2.dart';
|
||||
import 'package:catcher_2/utils/log_printer.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
final logger = PiliLogger();
|
||||
|
||||
class PiliLogger extends Logger {
|
||||
PiliLogger() : super();
|
||||
|
||||
@override
|
||||
void log(
|
||||
Level level,
|
||||
dynamic message, {
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
DateTime? time,
|
||||
}) {
|
||||
if (level == Level.error || level == Level.fatal) {
|
||||
Catcher2.reportCheckedError(error, stackTrace);
|
||||
}
|
||||
super.log(level, message, error: error, stackTrace: stackTrace, time: time);
|
||||
}
|
||||
}
|
||||
final logger = Logger(
|
||||
filter: ProductionFilter(),
|
||||
printer: PrettyLogPrinter(
|
||||
dateTimeFormat: PrettyLogPrinter.toEncodableFallback,
|
||||
),
|
||||
level: kDebugMode ? .trace : .warning,
|
||||
);
|
||||
|
||||
abstract final class LoggerUtils {
|
||||
static File? _logFile;
|
||||
|
||||
@@ -49,7 +49,7 @@ class PackageHeaderRes extends PackageHeader {
|
||||
|
||||
static PackageHeaderRes? fromBytesData(Uint8List data) {
|
||||
if (data.length < 10) {
|
||||
logger.i('数据不足以解析PackageHeader');
|
||||
logger.w('数据不足以解析PackageHeader');
|
||||
return null;
|
||||
}
|
||||
final byteData = ByteData.sublistView(data);
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/services/logger.dart' show LoggerUtils;
|
||||
import 'package:catcher_2/model/platform_type.dart';
|
||||
import 'package:catcher_2/model/report.dart';
|
||||
import 'package:catcher_2/model/report_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/services/logger.dart';
|
||||
import 'package:catcher_2/catcher_2.dart';
|
||||
|
||||
class JsonFileHandler extends ReportHandler {
|
||||
final bool enableDeviceParameters;
|
||||
@@ -48,7 +45,7 @@ class JsonFileHandler extends ReportHandler {
|
||||
handleWhenRejected: handleWhenRejected,
|
||||
);
|
||||
} catch (e, s) {
|
||||
debugPrintStack(stackTrace: s, label: e.toString());
|
||||
logger.e('Init log file', error: e, stackTrace: s);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -62,18 +59,24 @@ class JsonFileHandler extends ReportHandler {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> handle(Report report, BuildContext? context) async {
|
||||
Future<bool> handle(Report report) async {
|
||||
try {
|
||||
await _processReport(report);
|
||||
return true;
|
||||
} catch (exc, stackTrace) {
|
||||
_printLog('Exception occurred: $exc stack: $stackTrace');
|
||||
logger.e(
|
||||
'Write Json Exception occurred',
|
||||
error: exc,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _processReport(Report report) {
|
||||
_printLog('Writing report to file');
|
||||
if (printLogs) {
|
||||
logger.d('Writing report to file');
|
||||
}
|
||||
final json = report.toJson(
|
||||
enableDeviceParameters: enableDeviceParameters,
|
||||
enableApplicationParameters: enableApplicationParameters,
|
||||
@@ -82,22 +85,4 @@ class JsonFileHandler extends ReportHandler {
|
||||
);
|
||||
return add((raf) => raf.writeString('${jsonEncode(json)}\n'));
|
||||
}
|
||||
|
||||
void _printLog(String log) {
|
||||
if (printLogs) {
|
||||
logger.info(log);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<PlatformType> getSupportedPlatforms() => const [
|
||||
PlatformType.android,
|
||||
PlatformType.iOS,
|
||||
PlatformType.linux,
|
||||
PlatformType.macOS,
|
||||
PlatformType.windows,
|
||||
];
|
||||
|
||||
@override
|
||||
bool shouldHandleWhenRejected() => handleWhenRejected;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user