Use alternative storage dir if user-accessible one is null (#2392)

This commit is contained in:
Imran Remtulla
2025-11-08 16:17:33 -05:00
parent 0ba2ec04f1
commit 44950032f7
2 changed files with 9 additions and 10 deletions

View File

@@ -498,6 +498,10 @@ Future<PackageInfo?> getInstalledInfo(
return null;
}
Future<Directory> getAppStorageDir() async =>
await getExternalStorageDirectory() ??
await getApplicationDocumentsDirectory();
class AppsProvider with ChangeNotifier {
// In memory App state (should always be kept in sync with local storage versions)
Map<String, AppInMemory> apps = {};
@@ -534,15 +538,11 @@ class AppsProvider with ChangeNotifier {
iconsCacheDir.createSync();
}
} else {
APKDir = Directory(
'${(await getExternalStorageDirectory())!.path}/apks',
);
APKDir = Directory('${(await getAppStorageDir()).path}/apks');
if (!APKDir.existsSync()) {
APKDir.createSync();
}
iconsCacheDir = Directory(
'${(await getExternalStorageDirectory())!.path}/icons',
);
iconsCacheDir = Directory('${(await getAppStorageDir()).path}/icons');
if (!iconsCacheDir.existsSync()) {
iconsCacheDir.createSync();
}
@@ -1002,7 +1002,7 @@ class AppsProvider with ChangeNotifier {
}
Future<String> getStorageRootPath() async {
return '/${(await getExternalStorageDirectory())!.uri.pathSegments.sublist(0, 3).join('/')}';
return '/${(await getAppStorageDir()).uri.pathSegments.sublist(0, 3).join('/')}';
}
Future<void> moveObbFile(File file, String appId) async {
@@ -1449,7 +1449,7 @@ class AppsProvider with ChangeNotifier {
Future<Directory> getAppsDir() async {
Directory appsDir = Directory(
'${(await getExternalStorageDirectory())!.path}/app_data',
'${(await getAppStorageDir()).path}/app_data',
);
if (!appsDir.existsSync()) {
appsDir.createSync();

View File

@@ -9,7 +9,6 @@ import 'package:obtainium/app_sources/github.dart';
import 'package:obtainium/main.dart';
import 'package:obtainium/providers/apps_provider.dart';
import 'package:obtainium/providers/source_provider.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shared_storage/shared_storage.dart' as saf;
@@ -35,7 +34,7 @@ class SettingsProvider with ChangeNotifier {
// Not done in constructor as we want to be able to await it
Future<void> initializeSettings() async {
prefs = await SharedPreferences.getInstance();
defaultAppDir = (await getExternalStorageDirectory())!.path;
defaultAppDir = (await getAppStorageDir()).path;
notifyListeners();
}