Skip to content

Commit

Permalink
Files passed as arguments are now opened; Fixed incorrect logging pat…
Browse files Browse the repository at this point in the history
…h in some situations
  • Loading branch information
ArthurHeitmann committed Feb 16, 2024
1 parent aab0608 commit ba7784e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
26 changes: 16 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'background/IdLookup.dart';
import 'background/wemFilesIndexer.dart';
import 'keyboardEvents/globalShortcutsWrapper.dart';
import 'stateManagement/beforeExitCleanup.dart';
import 'stateManagement/openFiles/openFilesManager.dart';
import 'stateManagement/openFiles/types/xml/sync/syncServer.dart';
import 'stateManagement/preferencesData.dart';
import 'utils/assetDirFinder.dart';
Expand All @@ -25,11 +26,11 @@ import 'widgets/theme/customTheme.dart';
import 'widgets/theme/nierTheme.dart';
import 'widgets/titlebar/Titlebar.dart';

void main() {
loggingWrapper(init);
void main(List<String> args) {
loggingWrapper(() => init(args));
}

void init() async {
void init(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();

runApp(const SplashScreen());
Expand All @@ -41,25 +42,25 @@ void init() async {
minimumSize: Size(400, 200),
titleBarStyle: TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
unawaited(windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
var windowPos = await windowManager.getPosition();
if (windowPos.dy < 50)
await windowManager.setPosition(windowPos.translate(0, 50));
// await windowManager.focus();
});
}));
}
else if (isMobile) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
await ensureHasStoragePermission();
}

startSyncServer();
findAssetsDir();
idLookup.init();
unawaited(findAssetsDir());
unawaited(idLookup.init());
await PreferencesData().load();
wemFilesLookup.updateIndex();
FlutterWindowClose.setWindowShouldCloseHandler(beforeExitConfirmation);
unawaited(wemFilesLookup.updateIndex());
unawaited(FlutterWindowClose.setWindowShouldCloseHandler(beforeExitConfirmation));

ErrorWidget.builder = (FlutterErrorDetails details) {
return Center(
Expand All @@ -86,6 +87,11 @@ void init() async {
};

runApp(const MyApp());

unawaited(waitForNextFrame().then((_) {
for (var arg in args)
areasManager.openFile(arg);
}));
}

final _rootKey = GlobalKey<ScaffoldState>(debugLabel: "RootGlobalKey");
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/assetDirFinder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const _assetsDirSubDirs = { "fonts", "MrubyDecompiler" };
Future<bool> findAssetsDir() async {
if (assetsDir != null)
return true;
var path = Directory.current.path;
var path = dirname(Platform.resolvedExecutable);
// search cwd breadth first
List<String> searchPathsQueue = [path];
while (searchPathsQueue.isNotEmpty) {
Expand Down
6 changes: 3 additions & 3 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(Directory.current.path, "log.txt");
final _logFileName = join(dirname(Platform.resolvedExecutable), "log.txt");

void loggingWrapper(void Function() run) {
// log all output to file
Expand Down Expand Up @@ -38,15 +38,15 @@ List<String> _logBuffer = [];

void _logToFile(String line) {
var now = DateTime.now();
var time = "${now.hour}:${now.minute}:${now.second}.${now.millisecond}";
var time = "${now.hour.toString().padLeft(2, "0")}:${now.minute.toString().padLeft(2, "0")}:${now.second.toString().padLeft(2, "0")}.${now.millisecond}";
var logLine = "$time: $line";
_logBuffer.add(logLine);
_saveLogBufferThrottled();
}

void _logErrorToFile(FlutterErrorDetails err) {
var now = DateTime.now();
var time = "${now.hour}:${now.minute}:${now.second}.${now.millisecond}";
var time = "${now.hour.toString().padLeft(2, "0")}:${now.minute.toString().padLeft(2, "0")}:${now.second.toString().padLeft(2, "0")}.${now.millisecond}";
var logLine = "$time: ERROR: ${err.exceptionAsString()}"
"\n"
"${err.stack.toString()}";
Expand Down

0 comments on commit ba7784e

Please sign in to comment.