From 09a452b4ca3eade7546e1d8c801038b435852845 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 16 Nov 2023 12:03:15 -0600 Subject: [PATCH] allow setting custom app root dir on desktop via cli args --- lib/main.dart | 6 +++++- lib/utilities/stack_file_system.dart | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 6970bd67c..7ac3170b6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -81,9 +81,13 @@ final openedFromSWBFileStringStateProvider = // main() is the entry point to the app. It initializes Hive (local database), // runs the MyApp widget and checks for new users, caching the value in the // miscellaneous box for later use -void main() async { +void main(List args) async { WidgetsFlutterBinding.ensureInitialized(); + if (Util.isDesktop && args.length == 2 && args.first == "-d") { + StackFileSystem.overrideDir = args.last; + } + final loadCoinlibFuture = loadCoinlib(); GoogleFonts.config.allowRuntimeFetching = false; diff --git a/lib/utilities/stack_file_system.dart b/lib/utilities/stack_file_system.dart index 4fb3e4617..4cbbbf437 100644 --- a/lib/utilities/stack_file_system.dart +++ b/lib/utilities/stack_file_system.dart @@ -15,6 +15,8 @@ import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/util.dart'; abstract class StackFileSystem { + static String? overrideDir; + static Future applicationRootDirectory() async { Directory appDirectory; @@ -23,12 +25,25 @@ abstract class StackFileSystem { appDirectory = await getApplicationDocumentsDirectory(); appDirectory = Directory("${appDirectory.path}/.stackwallet"); } else if (Platform.isLinux) { - appDirectory = Directory("${Platform.environment['HOME']}/.stackwallet"); + if (overrideDir != null) { + appDirectory = Directory(overrideDir!); + } else { + appDirectory = + Directory("${Platform.environment['HOME']}/.stackwallet"); + } } else if (Platform.isWindows) { - appDirectory = await getApplicationSupportDirectory(); + if (overrideDir != null) { + appDirectory = Directory(overrideDir!); + } else { + appDirectory = await getApplicationSupportDirectory(); + } } else if (Platform.isMacOS) { - appDirectory = await getLibraryDirectory(); - appDirectory = Directory("${appDirectory.path}/stackwallet"); + if (overrideDir != null) { + appDirectory = Directory(overrideDir!); + } else { + appDirectory = await getLibraryDirectory(); + appDirectory = Directory("${appDirectory.path}/stackwallet"); + } } else if (Platform.isIOS) { // todo: check if we need different behaviour here if (Util.isDesktop) {