Skip to content

Commit

Permalink
added button to open log file
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Feb 16, 2024
1 parent ba7784e commit 7ff1783
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/utils/loggingWrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:path/path.dart';

import 'utils.dart';

final _logFileName = join(dirname(Platform.resolvedExecutable), "log.txt");
final logFileName = join(dirname(Platform.resolvedExecutable), "log.txt");

void loggingWrapper(void Function() run) {
// log all output to file
Expand Down Expand Up @@ -57,7 +57,7 @@ void _logErrorToFile(FlutterErrorDetails err) {
Future<void> _saveLogBuffer() async {
var logBuffer = _logBuffer;
_logBuffer = [];
var file = File(_logFileName);
var file = File(logFileName);
var logFile = await file.open(mode: FileMode.append);
await logFile.writeString("${logBuffer.join("\n")}\n");
await logFile.close();
Expand Down
16 changes: 16 additions & 0 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import '../stateManagement/miscValues.dart';
import '../stateManagement/openFiles/types/xml/xmlProps/xmlProp.dart';
import '../widgets/misc/contextMenuBuilder.dart';
import '../widgets/theme/customTheme.dart';
import 'assetDirFinder.dart';

const uuidGen = Uuid();

Expand Down Expand Up @@ -658,6 +659,21 @@ void openInVsCode(String path) {
}
}

void openInTextEditor(String path) async {
if (await hasVsCode())
openInVsCode(path);
else if (Platform.isWindows) {
await Process.run("notepad", [path], runInShell: true);
} else if (Platform.isMacOS) {
await Process.run("open", [path], runInShell: true);
} else if (Platform.isLinux) {
await Process.run("gedit", [path], runInShell: true);
} else {
showToast("Unsupported platform :(");
throw Exception("Unsupported platform");
}
}

Future<String?> findDttDirOfDat(String extractedDatDir) async {
var datName = basenameWithoutExtension(extractedDatDir);
var parentDir = dirname(extractedDatDir);
Expand Down
11 changes: 11 additions & 0 deletions lib/widgets/statusbar/messageLog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:async';
import 'package:flutter/material.dart';

import '../../stateManagement/events/statusInfo.dart';
import '../../utils/loggingWrapper.dart';
import '../../utils/utils.dart';
import '../misc/ChangeNotifierWidget.dart';
import '../theme/customTheme.dart';
Expand Down Expand Up @@ -189,6 +190,16 @@ class _MessageLogDialogState extends ChangeNotifierState<_MessageLogDialog> {
.then((_) => showToast("Copied ${pluralStr(messageLog.length, "message")} to clipboard")),
),
),
Tooltip(
message: "Open logs file",
waitDuration: const Duration(milliseconds: 500),
child: IconButton(
icon: const Icon(Icons.open_in_new, size: 18,),
padding: EdgeInsets.zero,
splashRadius: 15,
onPressed: () => openInTextEditor(logFileName),
),
),
],
),
),
Expand Down

0 comments on commit 7ff1783

Please sign in to comment.