mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-29 20:20:14 +02:00
Enable auto-export on update checks
This commit is contained in:
@@ -254,6 +254,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "Remover App?",
|
||||
"other": "Remover Apps?"
|
||||
|
@@ -111,7 +111,7 @@
|
||||
"dark": "Tamna",
|
||||
"light": "Svijetla",
|
||||
"followSystem": "Pratite sistem",
|
||||
"obtainium": "Obtainium",
|
||||
"obtainium": "Obtainium",
|
||||
"materialYou": "Material You",
|
||||
"useBlackTheme": "Koristite čisto crnu tamnu temu",
|
||||
"appSortBy": "Aplikacije sortirane po",
|
||||
@@ -251,7 +251,9 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"removeAppQuestion": {
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "Želite li ukloniti aplikaciju?",
|
||||
"other": "Želite li ukloniti aplikacije?"
|
||||
},
|
||||
|
@@ -251,6 +251,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "App entfernen?",
|
||||
"other": "Apps entfernen?"
|
||||
|
@@ -254,6 +254,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "Remove App?",
|
||||
"other": "Remove Apps?"
|
||||
|
@@ -251,6 +251,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "¿Eliminar Aplicación?",
|
||||
"other": "¿Eliminar Aplicaciones?"
|
||||
|
@@ -251,6 +251,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "برنامه حذف شود؟",
|
||||
"other": "برنامه ها حذف شوند؟"
|
||||
|
@@ -251,6 +251,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "Supprimer l'application ?",
|
||||
"other": "Supprimer les applications ?"
|
||||
|
@@ -250,6 +250,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "Eltávolítja az alkalmazást?",
|
||||
"other": "Eltávolítja az alkalmazást?"
|
||||
|
@@ -251,6 +251,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "Rimuovere l'app?",
|
||||
"other": "Rimuovere le app?"
|
||||
|
@@ -252,6 +252,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "アプリを削除しますか?",
|
||||
"other": "アプリを削除しますか?"
|
||||
|
@@ -257,6 +257,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "Usunąć aplikację?",
|
||||
"few": "Usunąć aplikacje?",
|
||||
|
@@ -251,6 +251,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "Удалить приложение?",
|
||||
"other": "Удалить приложения?"
|
||||
|
@@ -252,6 +252,8 @@
|
||||
"versionExtractionRegEx": "Version Extraction RegEx",
|
||||
"matchGroupToUse": "Match Group to Use",
|
||||
"highlightTouchTargets": "Highlight less obvious touch targets",
|
||||
"pickExportDir": "Pick Export Directory",
|
||||
"autoExportOnUpdateCheckKeepNum": "Auto-export on update check (keep last N auto-exports)",
|
||||
"removeAppQuestion": {
|
||||
"one": "是否删除应用?",
|
||||
"other": "是否删除应用?"
|
||||
|
@@ -124,10 +124,7 @@ class HTML extends AppSource {
|
||||
additionalValidators: [
|
||||
(value) {
|
||||
value ??= '1';
|
||||
if (int.tryParse(value) == null) {
|
||||
return tr('invalidInput');
|
||||
}
|
||||
return null;
|
||||
return intValidator(value);
|
||||
}
|
||||
])
|
||||
]
|
||||
|
@@ -74,6 +74,11 @@ class AppsPageState extends State<AppsPage> {
|
||||
setState(() {
|
||||
refreshingSince = null;
|
||||
});
|
||||
if (settingsProvider.autoExportOnUpdateCheckKeepNum > 0) {
|
||||
appsProvider.exportApps(isAuto: true).then((value) {
|
||||
appsProvider.trimAutoExports();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -104,8 +104,12 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
|
||||
runObtainiumExport() {
|
||||
HapticFeedback.selectionClick();
|
||||
appsProvider.exportApps().then((String path) {
|
||||
showError(tr('exportedTo', args: [path]), context);
|
||||
appsProvider
|
||||
.exportApps(pickOnly: settingsProvider.exportDir == null)
|
||||
.then((String? result) {
|
||||
if (result != null) {
|
||||
showError(tr('exportedTo', args: [result]), context);
|
||||
}
|
||||
}).catchError((e) {
|
||||
showError(e, context);
|
||||
});
|
||||
@@ -310,7 +314,10 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
importInProgress
|
||||
? null
|
||||
: runObtainiumExport,
|
||||
child: Text(tr('obtainiumExport')))),
|
||||
child: Text(tr(
|
||||
settingsProvider.exportDir != null
|
||||
? 'obtainiumExport'
|
||||
: 'pickExportDirKeepLastN')))),
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
@@ -323,6 +330,48 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
child: Text(tr('obtainiumImport'))))
|
||||
],
|
||||
),
|
||||
if (settingsProvider.exportDir != null)
|
||||
Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
GeneratedForm(
|
||||
items: [
|
||||
[
|
||||
GeneratedFormTextField(
|
||||
'autoExportOnUpdateCheckKeepNum',
|
||||
label: tr(
|
||||
'autoExportOnUpdateCheckKeepNum'),
|
||||
required: false,
|
||||
defaultValue: settingsProvider
|
||||
.autoExportOnUpdateCheckKeepNum
|
||||
.toString(),
|
||||
textInputType: const TextInputType
|
||||
.numberWithOptions(),
|
||||
additionalValidators: [
|
||||
(value) {
|
||||
value ??= settingsProvider
|
||||
.autoExportOnUpdateCheckKeepNum
|
||||
.toString();
|
||||
return intValidator(value,
|
||||
positive: true);
|
||||
}
|
||||
])
|
||||
]
|
||||
],
|
||||
onValueChanges: (value, valid, isBuilding) {
|
||||
if (valid && !isBuilding) {
|
||||
if (value[
|
||||
'autoExportOnUpdateCheckKeepNum'] !=
|
||||
null) {
|
||||
settingsProvider
|
||||
.autoExportOnUpdateCheckKeepNum =
|
||||
int.parse(value[
|
||||
'autoExportOnUpdateCheckKeepNum']);
|
||||
}
|
||||
}
|
||||
}),
|
||||
],
|
||||
),
|
||||
if (importInProgress)
|
||||
const Column(
|
||||
children: [
|
||||
@@ -399,7 +448,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
fontStyle: FontStyle.italic, fontSize: 12)),
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
)
|
||||
),
|
||||
],
|
||||
)))
|
||||
]));
|
||||
|
@@ -16,6 +16,7 @@ import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:obtainium/app_sources/html.dart';
|
||||
import 'package:obtainium/components/generated_form.dart';
|
||||
import 'package:obtainium/components/generated_form_modal.dart';
|
||||
import 'package:obtainium/custom_errors.dart';
|
||||
@@ -31,6 +32,7 @@ import 'package:obtainium/providers/source_provider.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:android_intent_plus/android_intent.dart';
|
||||
import 'package:flutter_archive/flutter_archive.dart';
|
||||
import 'package:shared_storage/shared_storage.dart' as saf;
|
||||
|
||||
final pm = AndroidPackageManager();
|
||||
|
||||
@@ -167,7 +169,8 @@ class AppsProvider with ChangeNotifier {
|
||||
if (cacheDirs?.isNotEmpty ?? false) {
|
||||
APKDir = cacheDirs!.first;
|
||||
} else {
|
||||
APKDir = Directory('${await settingsProvider.getAppDir()}/apks');
|
||||
APKDir =
|
||||
Directory('${(await getExternalStorageDirectory())!.path}/apks');
|
||||
if (!APKDir.existsSync()) {
|
||||
APKDir.createSync();
|
||||
}
|
||||
@@ -676,7 +679,7 @@ class AppsProvider with ChangeNotifier {
|
||||
|
||||
Future<Directory> getAppsDir() async {
|
||||
Directory appsDir =
|
||||
Directory('${await settingsProvider.getAppDir()}/app_data');
|
||||
Directory('${(await getExternalStorageDirectory())!.path}/app_data');
|
||||
if (!appsDir.existsSync()) {
|
||||
appsDir.createSync();
|
||||
}
|
||||
@@ -1091,32 +1094,58 @@ class AppsProvider with ChangeNotifier {
|
||||
return updateAppIds;
|
||||
}
|
||||
|
||||
Future<String> exportApps() async {
|
||||
if ((await DeviceInfoPlugin().androidInfo).version.sdkInt <= 29) {
|
||||
if (await Permission.storage.isDenied) {
|
||||
await Permission.storage.request();
|
||||
Future<String?> exportApps({bool pickOnly = false, isAuto = false}) async {
|
||||
if (isAuto) {
|
||||
logs.add('Started auto-export.');
|
||||
}
|
||||
var exportDir = settingsProvider.exportDir;
|
||||
if (exportDir == null || pickOnly) {
|
||||
await settingsProvider.pickExportDirKeepLastN();
|
||||
exportDir = settingsProvider.exportDir;
|
||||
}
|
||||
if (exportDir == null) {
|
||||
throw ObtainiumError(tr('unexpectedError'));
|
||||
}
|
||||
String? returnPath;
|
||||
if (!pickOnly) {
|
||||
var result = await saf.createFile(exportDir,
|
||||
displayName:
|
||||
'${tr('obtainiumExportHyphenatedLowercase')}-${DateTime.now().toIso8601String().replaceAll(':', '-')}${isAuto ? '-auto' : ''}.json',
|
||||
mimeType: 'application/json',
|
||||
content: jsonEncode(apps.values.map((e) => e.app.toJson()).toList()));
|
||||
if (result == null) {
|
||||
throw ObtainiumError(tr('unexpectedError'));
|
||||
}
|
||||
if (await Permission.storage.isDenied) {
|
||||
throw ObtainiumError(tr('storagePermissionDenied'));
|
||||
returnPath =
|
||||
exportDir.pathSegments.join('/').replaceFirst('tree/primary:', '');
|
||||
}
|
||||
return returnPath;
|
||||
}
|
||||
|
||||
Future<void> trimAutoExports() async {
|
||||
var exportDir = settingsProvider.exportDir;
|
||||
if (exportDir != null) {
|
||||
var files = await saf
|
||||
.listFiles(exportDir, columns: [saf.DocumentFileColumn.id]).toList();
|
||||
var maxCount = settingsProvider.autoExportOnUpdateCheckKeepNum;
|
||||
if (files.length > maxCount) {
|
||||
files.sort((a, b) {
|
||||
if (a.name == null) {
|
||||
return -1;
|
||||
} else if (b.name == null) {
|
||||
return 1;
|
||||
} else {
|
||||
return compareAlphaNumeric(a.name!, b.name!);
|
||||
}
|
||||
});
|
||||
files = files.reversed.toList();
|
||||
logs.add(
|
||||
'Deleting auto-exports older than ${files[maxCount - 1].uri.pathSegments.last}.');
|
||||
files.sublist(maxCount).forEach((f) {
|
||||
saf.delete(f.uri);
|
||||
});
|
||||
}
|
||||
}
|
||||
Directory? exportDir = Directory('/storage/emulated/0/Download');
|
||||
String path = 'Downloads'; // TODO: See if hardcoding this can be avoided
|
||||
var downloadsAccessible = false;
|
||||
try {
|
||||
downloadsAccessible = exportDir.existsSync();
|
||||
} catch (e) {
|
||||
logs.add('Error accessing Downloads (will use fallback): $e');
|
||||
}
|
||||
if (!downloadsAccessible) {
|
||||
exportDir = Directory(await settingsProvider.getAppDir());
|
||||
path = exportDir.path;
|
||||
}
|
||||
File export = File(
|
||||
'${exportDir.path}/${tr('obtainiumExportHyphenatedLowercase')}-${DateTime.now().millisecondsSinceEpoch}.json');
|
||||
export.writeAsStringSync(
|
||||
jsonEncode(apps.values.map((e) => e.app.toJson()).toList()));
|
||||
return path;
|
||||
}
|
||||
|
||||
Future<int> importApps(String appsJSON) async {
|
||||
@@ -1402,6 +1431,10 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
|
||||
if (toNotify.isNotEmpty) {
|
||||
notificationsProvider.notify(UpdateNotification(toNotify));
|
||||
}
|
||||
if (appsProvider.settingsProvider.autoExportOnUpdateCheckKeepNum > 0) {
|
||||
await appsProvider.exportApps(isAuto: true);
|
||||
await appsProvider.trimAutoExports();
|
||||
}
|
||||
}
|
||||
// If you're done checking and found some silently installable updates, schedule another task which will run in install mode
|
||||
if (didCompleteChecking && toInstall.isNotEmpty) {
|
||||
|
@@ -1,7 +1,6 @@
|
||||
// Exposes functions used to save/load app settings
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -363,52 +362,41 @@ class SettingsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<String> getAppDir() async {
|
||||
return prefs?.getString('appDir') ?? defaultAppDir!;
|
||||
Uri? get exportDir {
|
||||
var uriString = prefs?.getString('exportDir');
|
||||
if (uriString != null) {
|
||||
return Uri.parse(uriString);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
pickAppDir({bool useDefault = false}) async {
|
||||
Future<void> pickExportDirKeepLastN({bool remove = false}) async {
|
||||
var existingSAFPerms = (await saf.persistedUriPermissions()) ?? [];
|
||||
var currentAppDir = await getAppDir();
|
||||
if (currentAppDir != defaultAppDir) {
|
||||
currentAppDir = currentAppDir.replaceFirst(
|
||||
'/storage/emulated/0/', '/tree/primary%3A');
|
||||
var currentOneWayDataSyncDir = exportDir;
|
||||
Uri? newOneWayDataSyncDir;
|
||||
if (!remove) {
|
||||
newOneWayDataSyncDir = (await saf.openDocumentTree());
|
||||
}
|
||||
String? newAppDir;
|
||||
if (!useDefault) {
|
||||
var target = (await saf.openDocumentTree());
|
||||
if (target != null) {
|
||||
newAppDir = target.path
|
||||
.replaceFirst('/tree/primary%3A', '/storage/emulated/0/');
|
||||
if (currentOneWayDataSyncDir?.path != newOneWayDataSyncDir?.path) {
|
||||
if (newOneWayDataSyncDir == null) {
|
||||
prefs?.remove('exportDir');
|
||||
} else {
|
||||
prefs?.setString('exportDir', newOneWayDataSyncDir.toString());
|
||||
}
|
||||
} else {
|
||||
newAppDir = defaultAppDir;
|
||||
}
|
||||
newAppDir ??= defaultAppDir;
|
||||
if (currentAppDir != newAppDir) {
|
||||
moveDirectoryContents(Directory(currentAppDir), Directory(newAppDir!));
|
||||
prefs?.setString('appDir', newAppDir);
|
||||
notifyListeners();
|
||||
}
|
||||
for (var e in existingSAFPerms) {
|
||||
await saf.releasePersistableUriPermission(e.uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void moveDirectoryContents(Directory sourceDir, Directory destinationDir) {
|
||||
if (!destinationDir.existsSync()) {
|
||||
destinationDir.createSync(recursive: true);
|
||||
int get autoExportOnUpdateCheckKeepNum {
|
||||
return prefs?.getInt('autoExportOnUpdateCheckKeepNum') ?? 0;
|
||||
}
|
||||
List<FileSystemEntity> contents = sourceDir.listSync();
|
||||
for (FileSystemEntity entity in contents) {
|
||||
String newPath = '${destinationDir.path}/${entity.uri.pathSegments.last}';
|
||||
if (entity is File) {
|
||||
entity.renameSync(newPath);
|
||||
} else if (entity is Directory) {
|
||||
Directory newDestinationDir = Directory(newPath);
|
||||
moveDirectoryContents(entity, newDestinationDir);
|
||||
entity.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
set autoExportOnUpdateCheckKeepNum(int val) {
|
||||
prefs?.setInt('autoExportOnUpdateCheckKeepNum', val);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
@@ -521,6 +521,20 @@ regExValidator(String? value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
intValidator(String? value, {bool positive = false}) {
|
||||
if (value == null) {
|
||||
return tr('invalidInput');
|
||||
}
|
||||
var num = int.tryParse(value);
|
||||
if (num == null) {
|
||||
return tr('invalidInput');
|
||||
}
|
||||
if (positive && num <= 0) {
|
||||
return tr('invalidInput');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class SourceProvider {
|
||||
// Add more source classes here so they are available via the service
|
||||
List<AppSource> get sources => [
|
||||
|
Reference in New Issue
Block a user