forgot fs changes

This commit is contained in:
zlshames
2024-08-21 16:15:38 -04:00
parent 920b98046e
commit de330be3f1
2 changed files with 22 additions and 49 deletions

View File

@ -26,6 +26,17 @@ class FilesystemService extends GetxService {
late final Uint8List unplayableVideoIcon;
final RxBool fontExistsOnDisk = false.obs;
Future<String> get downloadsDirectory async {
if (kIsWeb) throw "Cannot get downloads directory on web!";
String filePath = "/storage/emulated/0/Download/";
if (kIsDesktop) {
filePath = (await getDownloadsDirectory())!.path;
}
return filePath;
}
Future<void> init({bool headless = false}) async {
if (!kIsWeb) {
//ignore: unnecessary_cast, we need this as a workaround
@ -144,4 +155,14 @@ class FilesystemService extends GetxService {
Logger.info("Created file ${basename(element.path)}");
}
});
Future<String> saveToDownloads(File file) async {
if (kIsWeb) throw "Cannot save file on web!";
final String filename = basename(file.path);
final String downloadsDir = await downloadsDirectory;
final String newPath = join(downloadsDir, filename);
await file.copy(newPath);
return newPath;
}
}

View File

@ -7,54 +7,6 @@ import 'package:bluebubbles/utils/logger/logger.dart' as BlueBubblesLogger;
class LogStreamOutput extends LogOutput {
@override
void output(OutputEvent event) {
List<String> lines = List.from(event.lines);
// For "boxed" logs, print them as-is.
// For not-boxed logs, print them as a single line.
if ([Level.fatal, Level.error, Level.trace].contains(event.level)) {
StackTrace? trace = event.origin.stackTrace;
bool hasTrace = trace != null && trace.toString().isNotEmpty;
if (!hasTrace) {
trace = StackTrace.current;
}
String traceStr = trace.toString();
// Only take the last 3 lines of the trace
if (traceStr.trim().isNotEmpty) {
// If there is no trace, (so we are using the current trace),
// we need to omit the first 5 lines of the trace, as they are
// part of the logger itself.
List<String> traceLines = traceStr.split('\n').where((txt) => txt != '<asynchronous suspension>').toList();
if (!hasTrace) {
traceLines = traceLines.sublist(5);
}
traceLines = (traceLines.length > 4) ? traceLines.sublist(0, 4) : traceLines;
traceStr = traceLines.map((e) => e).join('\n');
// Insert the trace into the box
lines.add('');
lines.add('Traceback:');
lines.add(traceStr);
}
lines[0] = '[${event.level.name.toUpperCase()}] ${lines[1]}';
lines.removeAt(1);
// Add the level to the date entry
// lines[1] = '${lines[1]} [${event.level.name.toUpperCase()}]';
return BlueBubblesLogger.Logger.logStream.sink.add(lines.join('\n'));
}
// Remove the first item (date)
lines.removeAt(0);
// If it's just a single-line log, print it as a single line.
// If there are multiple lines, print it as a block.
if (lines.length == 1) {
BlueBubblesLogger.Logger.logStream.sink.add("[${event.level.name.toUpperCase()}] ${lines.first}");
} else {
BlueBubblesLogger.Logger.logStream.sink.add("[${event.level.name.toUpperCase()}] ->\n${lines.join('\n')}");
}
return BlueBubblesLogger.Logger.logStream.sink.add(event.lines.join('\n'));
}
}