mod: clear outdated logs

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-12 16:42:35 +08:00
parent 6c9cd8b120
commit 08a47e6c1d
2 changed files with 13 additions and 0 deletions

View File

@@ -234,6 +234,7 @@ Commit Hash: ${BuildConfig.commitHash}''',
onLongPress: clearLogs,
leading: const Icon(Icons.bug_report_outlined),
title: const Text('错误日志'),
subtitle: Text('长按清除日志', style: subTitleStyle),
trailing: Icon(Icons.arrow_forward, size: 16, color: outline),
),
ListTile(

View File

@@ -15,6 +15,7 @@ class _LogsPageState extends State<LogsPage> {
late File logsPath;
late String fileContent;
List logsContent = [];
DateTime? latestLog;
@override
void initState() {
@@ -22,6 +23,16 @@ class _LogsPageState extends State<LogsPage> {
super.initState();
}
@override
void dispose() {
if (latestLog != null) {
if (DateTime.now().difference(latestLog!) >= Duration(days: 14)) {
clearLogs();
}
}
super.dispose();
}
void getPath() async {
logsPath = await getLogsPath();
fileContent = await logsPath.readAsString();
@@ -53,6 +64,7 @@ class _LogsPageState extends State<LogsPage> {
date = DateTime.parse(
l.split("Crash occurred on")[1].trim(), //.split('.')[0],
);
latestLog ??= date;
} catch (e) {
debugPrint(e.toString());
date = l.toString();