mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-28 05:10:14 +08:00
tweaks (#1142)
* opt: unused layout * mod: semantics * opt: DanmakuMsg type * opt: avoid cast * opt: unnecessary_lambdas * opt: use isEven * opt: logger * opt: invalid common page * tweak * opt: unify DynController
This commit is contained in:
committed by
GitHub
parent
56ffc2781f
commit
5f8313901b
@@ -10,7 +10,7 @@ import 'package:get/get_utils/get_utils.dart';
|
||||
|
||||
Future<VideoPlayerServiceHandler> initAudioService() async {
|
||||
return AudioService.init(
|
||||
builder: () => VideoPlayerServiceHandler(),
|
||||
builder: VideoPlayerServiceHandler.new,
|
||||
config: const AudioServiceConfig(
|
||||
androidNotificationChannelId: 'com.example.piliplus.audio',
|
||||
androidNotificationChannelName: 'Audio Service PiliPlus',
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
final _loggerFactory = PiliLogger();
|
||||
|
||||
PiliLogger getLogger<T>() {
|
||||
return _loggerFactory;
|
||||
}
|
||||
|
||||
class PiliLogger extends Logger {
|
||||
PiliLogger() : super();
|
||||
|
||||
@override
|
||||
Future<void> log(
|
||||
Level level,
|
||||
dynamic message, {
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
DateTime? time,
|
||||
}) async {
|
||||
if (level == Level.error || level == Level.fatal) {
|
||||
// 添加至文件末尾
|
||||
File logFile = await getLogsPath();
|
||||
logFile.writeAsString(
|
||||
"**${DateTime.now()}** \n $message \n $stackTrace",
|
||||
mode: FileMode.writeOnlyAppend,
|
||||
);
|
||||
}
|
||||
super.log(level, "$message", error: error, stackTrace: stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
Future<File> getLogsPath() async {
|
||||
String dir = (await getApplicationDocumentsDirectory()).path;
|
||||
final String filename = p.join(dir, ".pili_logs");
|
||||
final File file = File(filename);
|
||||
if (!file.existsSync()) {
|
||||
await file.create(recursive: true);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
Future<bool> clearLogs() async {
|
||||
final File file = await getLogsPath();
|
||||
try {
|
||||
await file.writeAsString('');
|
||||
} catch (e) {
|
||||
// if (kDebugMode) debugPrint('Error clearing file: $e');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
57
lib/services/logger.dart
Normal file
57
lib/services/logger.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'dart:io';
|
||||
|
||||
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
|
||||
Future<void> log(
|
||||
Level level,
|
||||
dynamic message, {
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
DateTime? time,
|
||||
}) async {
|
||||
if (level == Level.error || level == Level.fatal) {
|
||||
// 添加至文件末尾
|
||||
File logFile = await LoggerUtils.getLogsPath();
|
||||
logFile.writeAsString(
|
||||
"**${DateTime.now()}** \n $message \n $stackTrace",
|
||||
mode: FileMode.writeOnlyAppend,
|
||||
);
|
||||
}
|
||||
super.log(level, "$message", error: error, stackTrace: stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
class LoggerUtils {
|
||||
static File? _logFile;
|
||||
|
||||
static Future<File> getLogsPath() async {
|
||||
if (_logFile != null) return _logFile!;
|
||||
|
||||
String dir = (await getApplicationDocumentsDirectory()).path;
|
||||
final String filename = p.join(dir, ".pili_logs");
|
||||
final File file = File(filename);
|
||||
if (!file.existsSync()) {
|
||||
await file.create(recursive: true);
|
||||
}
|
||||
return _logFile = file;
|
||||
}
|
||||
|
||||
static Future<bool> clearLogs() async {
|
||||
final file = await getLogsPath();
|
||||
try {
|
||||
await file.writeAsBytes(const [], flush: true);
|
||||
} catch (e) {
|
||||
// if (kDebugMode) debugPrint('Error clearing file: $e');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user