app data dir fix

This commit is contained in:
julian 2024-05-23 09:20:11 -06:00
parent ec5fc6d2a5
commit 459e882ab6
5 changed files with 34 additions and 15 deletions

View file

@ -9,6 +9,8 @@ abstract class AppConfig {
static const prefix = _prefix;
static const suffix = _suffix;
static String get appDefaultDataDirName => _appDataDirName;
static List<CryptoCurrency> get coins => _supportedCoins;
static CryptoCurrency getCryptoCurrencyFor(String coinIdentifier) =>

View file

@ -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<String?>((ref) => null);
@ -87,9 +88,11 @@ void main(List<String> 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;

View file

@ -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<Directory> 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

View file

@ -33,6 +33,7 @@ part of 'app_config.dart';
const _prefix = "Stack";
const _separator = " ";
const _suffix = "Duo";
const _appDataDirName = "stackduo";
final List<CryptoCurrency> _supportedCoins = List.unmodifiable([
Bitcoin(CryptoCurrencyNetwork.main),

View file

@ -35,6 +35,7 @@ part of 'app_config.dart';
const _prefix = "Stack";
const _separator = " ";
const _suffix = "Wallet";
const _appDataDirName = "stackwallet";
final List<CryptoCurrency> _supportedCoins = List.unmodifiable([
Bitcoin(CryptoCurrencyNetwork.main),