From 459e882ab6d9b71d5a7887d32b3a3818a48d6411 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 23 May 2024 09:20:11 -0600 Subject: [PATCH] app data dir fix --- lib/app_config.dart | 2 ++ lib/main.dart | 7 ++-- lib/utilities/stack_file_system.dart | 38 +++++++++++++------- scripts/app_config/configure_stack_duo.sh | 1 + scripts/app_config/configure_stack_wallet.sh | 1 + 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/app_config.dart b/lib/app_config.dart index abdf2ac9b..131c7ff5b 100644 --- a/lib/app_config.dart +++ b/lib/app_config.dart @@ -9,6 +9,8 @@ abstract class AppConfig { static const prefix = _prefix; static const suffix = _suffix; + static String get appDefaultDataDirName => _appDataDirName; + static List get coins => _supportedCoins; static CryptoCurrency getCryptoCurrencyFor(String coinIdentifier) => diff --git a/lib/main.dart b/lib/main.dart index 0e0127afe..39adfd952 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -28,6 +28,8 @@ import 'package:hive_flutter/hive_flutter.dart'; import 'package:isar/isar.dart'; import 'package:keyboard_dismisser/keyboard_dismisser.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:window_size/window_size.dart'; + import 'app_config.dart'; import 'db/db_version_migration.dart'; import 'db/hive/db.dart'; @@ -75,7 +77,6 @@ import 'utilities/stack_file_system.dart'; import 'utilities/util.dart'; import 'wallets/isar/providers/all_wallets_info_provider.dart'; import 'widgets/crypto_notifications.dart'; -import 'package:window_size/window_size.dart'; final openedFromSWBFileStringStateProvider = StateProvider((ref) => null); @@ -87,9 +88,11 @@ void main(List args) async { WidgetsFlutterBinding.ensureInitialized(); if (Util.isDesktop && args.length == 2 && args.first == "-d") { - StackFileSystem.overrideDir = args.last; + StackFileSystem.setDesktopOverrideDir(args.last); } + // TODO set external libs file paths (bad external lib design workaround) + final loadCoinlibFuture = loadCoinlib(); GoogleFonts.config.allowRuntimeFetching = false; diff --git a/lib/utilities/stack_file_system.dart b/lib/utilities/stack_file_system.dart index a5b58794d..b5f28e48a 100644 --- a/lib/utilities/stack_file_system.dart +++ b/lib/utilities/stack_file_system.dart @@ -11,40 +11,52 @@ import 'dart:io'; import 'package:path_provider/path_provider.dart'; + +import '../app_config.dart'; import 'logger.dart'; import 'util.dart'; abstract class StackFileSystem { - static String? overrideDir; + static String? _overrideDesktopDirPath; + static bool _overrideDirSet = false; + static void setDesktopOverrideDir(String dirPath) { + if (_overrideDirSet) { + throw Exception( + "Attempted to change StackFileSystem._overrideDir unexpectedly", + ); + } + _overrideDesktopDirPath = dirPath; + _overrideDirSet = true; + } static Future applicationRootDirectory() async { Directory appDirectory; - // if this is changed, the directories in libmonero must also be changed!!!!! - const dirName = "stackwallet"; - // todo: can merge and do same as regular linux home dir? if (Logging.isArmLinux) { appDirectory = await getApplicationDocumentsDirectory(); - appDirectory = Directory("${appDirectory.path}/.$dirName"); + appDirectory = + Directory("${appDirectory.path}/.${AppConfig.appDefaultDataDirName}"); } else if (Platform.isLinux) { - if (overrideDir != null) { - appDirectory = Directory(overrideDir!); + if (_overrideDesktopDirPath != null) { + appDirectory = Directory(_overrideDesktopDirPath!); } else { - appDirectory = Directory("${Platform.environment['HOME']}/.$dirName"); + appDirectory = Directory( + "${Platform.environment['HOME']}/.${AppConfig.appDefaultDataDirName}"); } } else if (Platform.isWindows) { - if (overrideDir != null) { - appDirectory = Directory(overrideDir!); + if (_overrideDesktopDirPath != null) { + appDirectory = Directory(_overrideDesktopDirPath!); } else { appDirectory = await getApplicationSupportDirectory(); } } else if (Platform.isMacOS) { - if (overrideDir != null) { - appDirectory = Directory(overrideDir!); + if (_overrideDesktopDirPath != null) { + appDirectory = Directory(_overrideDesktopDirPath!); } else { appDirectory = await getLibraryDirectory(); - appDirectory = Directory("${appDirectory.path}/$dirName"); + appDirectory = Directory( + "${appDirectory.path}/${AppConfig.appDefaultDataDirName}"); } } else if (Platform.isIOS) { // todo: check if we need different behaviour here diff --git a/scripts/app_config/configure_stack_duo.sh b/scripts/app_config/configure_stack_duo.sh index 99e60e4cd..3b597d287 100755 --- a/scripts/app_config/configure_stack_duo.sh +++ b/scripts/app_config/configure_stack_duo.sh @@ -33,6 +33,7 @@ part of 'app_config.dart'; const _prefix = "Stack"; const _separator = " "; const _suffix = "Duo"; +const _appDataDirName = "stackduo"; final List _supportedCoins = List.unmodifiable([ Bitcoin(CryptoCurrencyNetwork.main), diff --git a/scripts/app_config/configure_stack_wallet.sh b/scripts/app_config/configure_stack_wallet.sh index acd13fb22..b6f7d066b 100755 --- a/scripts/app_config/configure_stack_wallet.sh +++ b/scripts/app_config/configure_stack_wallet.sh @@ -35,6 +35,7 @@ part of 'app_config.dart'; const _prefix = "Stack"; const _separator = " "; const _suffix = "Wallet"; +const _appDataDirName = "stackwallet"; final List _supportedCoins = List.unmodifiable([ Bitcoin(CryptoCurrencyNetwork.main),