allow setting custom app root dir on desktop via cli args

This commit is contained in:
julian 2023-11-16 12:03:15 -06:00
parent 2811063699
commit 09a452b4ca
2 changed files with 24 additions and 5 deletions

View file

@ -81,9 +81,13 @@ final openedFromSWBFileStringStateProvider =
// main() is the entry point to the app. It initializes Hive (local database), // 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 // runs the MyApp widget and checks for new users, caching the value in the
// miscellaneous box for later use // miscellaneous box for later use
void main() async { void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
if (Util.isDesktop && args.length == 2 && args.first == "-d") {
StackFileSystem.overrideDir = args.last;
}
final loadCoinlibFuture = loadCoinlib(); final loadCoinlibFuture = loadCoinlib();
GoogleFonts.config.allowRuntimeFetching = false; GoogleFonts.config.allowRuntimeFetching = false;

View file

@ -15,6 +15,8 @@ import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
abstract class StackFileSystem { abstract class StackFileSystem {
static String? overrideDir;
static Future<Directory> applicationRootDirectory() async { static Future<Directory> applicationRootDirectory() async {
Directory appDirectory; Directory appDirectory;
@ -23,12 +25,25 @@ abstract class StackFileSystem {
appDirectory = await getApplicationDocumentsDirectory(); appDirectory = await getApplicationDocumentsDirectory();
appDirectory = Directory("${appDirectory.path}/.stackwallet"); appDirectory = Directory("${appDirectory.path}/.stackwallet");
} else if (Platform.isLinux) { } 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) { } else if (Platform.isWindows) {
appDirectory = await getApplicationSupportDirectory(); if (overrideDir != null) {
appDirectory = Directory(overrideDir!);
} else {
appDirectory = await getApplicationSupportDirectory();
}
} else if (Platform.isMacOS) { } else if (Platform.isMacOS) {
appDirectory = await getLibraryDirectory(); if (overrideDir != null) {
appDirectory = Directory("${appDirectory.path}/stackwallet"); appDirectory = Directory(overrideDir!);
} else {
appDirectory = await getLibraryDirectory();
appDirectory = Directory("${appDirectory.path}/stackwallet");
}
} else if (Platform.isIOS) { } else if (Platform.isIOS) {
// todo: check if we need different behaviour here // todo: check if we need different behaviour here
if (Util.isDesktop) { if (Util.isDesktop) {