Skip to content

Commit 79f43f0

Browse files
committed
feat(debug): view log in app
1 parent 7da5500 commit 79f43f0

File tree

9 files changed

+134
-24
lines changed

9 files changed

+134
-24
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:tsdm_client/i18n/strings.g.dart';
3+
import 'package:tsdm_client/instance.dart';
4+
import 'package:tsdm_client/utils/clipboard.dart';
5+
6+
/// Debug page for show all caught log since this start.
7+
class DebugLogPage extends StatefulWidget {
8+
/// Constructor.
9+
const DebugLogPage({super.key});
10+
11+
@override
12+
State<DebugLogPage> createState() => _DebugLogPageState();
13+
}
14+
15+
class _DebugLogPageState extends State<DebugLogPage> {
16+
@override
17+
Widget build(BuildContext context) {
18+
final tr = context.t.debugLogPage;
19+
// return Scaffold(
20+
// appBar: AppBar(
21+
// title: Text('aaa'),
22+
// ),
23+
// body: Text(talker.history.map((e) => e.generateTextMessage()).join('\n')),
24+
// );
25+
26+
return FutureBuilder(
27+
future: Future.value(
28+
talker.history.map((e) => e.generateTextMessage()).join('\n'),
29+
),
30+
builder: (context, snapshot) {
31+
if (snapshot.hasError) {
32+
return Scaffold(
33+
appBar: AppBar(title: Text(tr.title)),
34+
body: Center(child: Text(snapshot.error!.toString())),
35+
);
36+
}
37+
38+
if (!snapshot.hasData) {
39+
return Scaffold(
40+
appBar: AppBar(title: Text(tr.title)),
41+
body: const Center(child: CircularProgressIndicator()),
42+
);
43+
}
44+
45+
final logData = snapshot.data!;
46+
47+
return Scaffold(
48+
appBar: AppBar(
49+
title: Text(tr.title),
50+
actions: [
51+
IconButton(
52+
icon: const Icon(Icons.copy_outlined),
53+
onPressed: () async => copyToClipboard(context, logData),
54+
),
55+
],
56+
),
57+
body: SingleChildScrollView(child: Text(logData)),
58+
);
59+
},
60+
);
61+
}
62+
}

lib/features/settings/view/settings_page.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,10 @@ class _SettingsPageState extends State<SettingsPage> {
709709
);
710710
},
711711
),
712+
SectionListTile(
713+
title: Text(tr.viewLog.title),
714+
onTap: () async => context.pushNamed(ScreenPaths.debugLog),
715+
),
712716
SectionListTile(
713717
title: Text(tr.exportLog.title),
714718
subtitle: _logExportPath == null

lib/i18n/strings.i18n.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
"exportLog": {
195195
"title": "Export log",
196196
"detail": "Log has been exported to ${path: String}"
197+
},
198+
"viewLog": {
199+
"title": "View log"
197200
}
198201
},
199202
"othersSection": {
@@ -762,5 +765,9 @@
762765
"bm": "You received ${noticeCount: int} notice, ${pmCount: int} PMs, ${bmCount: int} BMs\n[BM]${msg: String}"
763766
}
764767
}
768+
},
769+
"debugLogPage": {
770+
"title": "Log",
771+
"copyLogToClipboard": "Log copied to clipboard"
765772
}
766773
}

lib/i18n/strings_zh-CN.i18n.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
"exportLog": {
195195
"title": "导出日志",
196196
"detail": "日志已导出到 ${path: String}"
197+
},
198+
"viewLog": {
199+
"title": "查看日志"
197200
}
198201
},
199202
"othersSection": {
@@ -762,5 +765,9 @@
762765
"bm": "收到了${noticeCount: int}条提醒,${pmCount: int}条私信,${bmCount: int}条公共消息\n[公共消息]${msg: String}"
763766
}
764767
}
768+
},
769+
"debugLogPage": {
770+
"title": "日志",
771+
"copyLogToClipboard": "日志已复制到剪切板"
765772
}
766773
}

lib/i18n/strings_zh-TW.i18n.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
"exportLog": {
195195
"title": "匯出日誌",
196196
"detail": "日誌已匯出到 ${path: String}"
197+
},
198+
"viewLog": {
199+
"title": "查看日誌"
197200
}
198201
},
199202
"othersSection": {
@@ -762,5 +765,9 @@
762765
"bm": "收到了${noticeCount: int}條提醒,${pmCount: int}條私信,${bmCount: int}條公用訊息\n[公用訊息]${msg: String}"
763766
}
764767
}
768+
},
769+
"debugLogPage": {
770+
"title": "日誌",
771+
"copyLogToClipboard": "日誌已複製到剪切板"
765772
}
766773
}

lib/main.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:collection/collection.dart';
24
import 'package:flutter/material.dart';
35
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
@@ -16,11 +18,15 @@ import 'package:tsdm_client/utils/platform.dart';
1618
import 'package:tsdm_client/utils/window_configs.dart';
1719
import 'package:window_manager/window_manager.dart';
1820

19-
Future<void> main(List<String> args) async {
21+
Future<void> main(List<String> args) async =>
22+
runZonedGuarded(() async => _boot(args), _ensureHandled);
23+
24+
Future<void> _boot(List<String> args) async {
25+
WidgetsFlutterBinding.ensureInitialized();
26+
2027
parseCmdArgs(args);
2128

2229
talker.debug('start app...');
23-
WidgetsFlutterBinding.ensureInitialized();
2430
await initProviders();
2531

2632
final settings = getIt.get<SettingsRepository>().currentSettings;
@@ -101,3 +107,6 @@ Future<void> main(List<String> args) async {
101107
),
102108
);
103109
}
110+
111+
void _ensureHandled(Object exception, StackTrace? stackTrace) =>
112+
talker.handle(exception, stackTrace);

lib/routes/app_routes.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import 'package:tsdm_client/features/rate/view/rate_post_page.dart';
2525
import 'package:tsdm_client/features/root/view/root_page.dart';
2626
import 'package:tsdm_client/features/search/view/search_page.dart';
2727
import 'package:tsdm_client/features/settings/view/about_page.dart';
28+
import 'package:tsdm_client/features/settings/view/debug_log_page.dart';
2829
import 'package:tsdm_client/features/settings/view/settings_page.dart';
2930
import 'package:tsdm_client/features/settings/view/thread_card_appearance.dart';
3031
import 'package:tsdm_client/features/settings/widgets/app_license_page.dart';
@@ -335,6 +336,11 @@ final router = GoRouter(
335336
parentNavigatorKey: _rootRouteKey,
336337
builder: (_) => const AutoCheckinPage(),
337338
),
339+
AppRoute(
340+
path: ScreenPaths.debugLog,
341+
parentNavigatorKey: _rootRouteKey,
342+
builder: (_) => const DebugLogPage(),
343+
),
338344
],
339345
);
340346

lib/routes/screen_paths.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ class ScreenPaths {
174174

175175
/// Page to show auto checkin detail information.
176176
static const String autoCheckinDetail = '/autoCheckinDetail';
177+
178+
/// Page to show logs for debugging.
179+
static const String debugLog = '/debugLog';
177180
}
178181

179182
/// Route path for a screen.

lib/themes/app_themes.dart

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,32 @@ class AppTheme {
3333
drawerRadius: 0,
3434
);
3535

36-
static CardTheme _buildCardTheme() => const CardTheme(
36+
static CardTheme _buildCardTheme() =>
37+
const CardTheme(
3738
elevation: 0,
3839
);
3940

40-
static ChipThemeData _buildChipTheme() => const ChipThemeData(
41+
static ChipThemeData _buildChipTheme() =>
42+
const ChipThemeData(
4143
padding: EdgeInsets.all(2),
4244
);
4345

4446
/// Global theme for [ListTile].
45-
static ListTileThemeData _buildListTileTheme() => const ListTileThemeData(
47+
static ListTileThemeData _buildListTileTheme() =>
48+
const ListTileThemeData(
4649
visualDensity: VisualDensity.standard,
4750
contentPadding: EdgeInsets.symmetric(horizontal: 10),
4851
horizontalTitleGap: 10,
4952
);
5053

5154
/// Global theme for [TabBar].
52-
static TabBarTheme _buildTabBarTheme() => const TabBarTheme(
55+
static TabBarTheme _buildTabBarTheme() =>
56+
const TabBarTheme(
5357
dividerHeight: 0,
5458
);
5559

5660
static NavigationDrawerThemeData _buildNavigationDrawerTheme(
57-
ColorScheme? colorScheme,
58-
) =>
61+
ColorScheme? colorScheme,) =>
5962
NavigationDrawerThemeData(
6063
labelTextStyle: WidgetStateProperty.resolveWith((state) {
6164
if (state.contains(WidgetState.selected)) {
@@ -78,16 +81,17 @@ class AppTheme {
7881
seedScheme = ColorScheme.fromSeed(seedColor: seedColor);
7982
}
8083
return FlexThemeData.light(
84+
fontFamily: 'Microsoft YaHei UI',
8185
colors: seedScheme != null
8286
? FlexSchemeColor(
83-
primary: seedScheme.primary,
84-
primaryContainer: seedScheme.primaryContainer,
85-
secondary: seedScheme.secondary,
86-
secondaryContainer: seedScheme.secondaryContainer,
87-
tertiary: seedScheme.tertiary,
88-
tertiaryContainer: seedScheme.tertiaryContainer,
89-
error: seedScheme.error,
90-
)
87+
primary: seedScheme.primary,
88+
primaryContainer: seedScheme.primaryContainer,
89+
secondary: seedScheme.secondary,
90+
secondaryContainer: seedScheme.secondaryContainer,
91+
tertiary: seedScheme.tertiary,
92+
tertiaryContainer: seedScheme.tertiaryContainer,
93+
error: seedScheme.error,
94+
)
9195
: null,
9296
scheme: seedColor == null ? FlexScheme.bahamaBlue : null,
9397
tabBarStyle: FlexTabBarStyle.forBackground,
@@ -116,16 +120,17 @@ class AppTheme {
116120
);
117121
}
118122
return FlexThemeData.dark(
123+
fontFamily: '更纱黑体 UI SC',
119124
colors: seedScheme != null
120125
? FlexSchemeColor(
121-
primary: seedScheme.primary,
122-
primaryContainer: seedScheme.primaryContainer,
123-
secondary: seedScheme.secondary,
124-
secondaryContainer: seedScheme.secondaryContainer,
125-
tertiary: seedScheme.tertiary,
126-
tertiaryContainer: seedScheme.tertiaryContainer,
127-
error: seedScheme.error,
128-
)
126+
primary: seedScheme.primary,
127+
primaryContainer: seedScheme.primaryContainer,
128+
secondary: seedScheme.secondary,
129+
secondaryContainer: seedScheme.secondaryContainer,
130+
tertiary: seedScheme.tertiary,
131+
tertiaryContainer: seedScheme.tertiaryContainer,
132+
error: seedScheme.error,
133+
)
129134
: null,
130135
scheme: seedColor == null ? FlexScheme.bahamaBlue : null,
131136
tabBarStyle: FlexTabBarStyle.forBackground,

0 commit comments

Comments
 (0)