Pick export dir + auto-export (#283, #600)

This commit is contained in:
Imran Remtulla
2023-09-10 22:35:28 -04:00
parent 6e735b1763
commit 53cf4d0234
19 changed files with 41 additions and 81 deletions

View File

@@ -255,7 +255,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "Remover App?",
"other": "Remover Apps?"

View File

@@ -252,7 +252,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "Želite li ukloniti aplikaciju?",
"other": "Želite li ukloniti aplikacije?"

View File

@@ -252,7 +252,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "App entfernen?",
"other": "Apps entfernen?"

View File

@@ -255,7 +255,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "Remove App?",
"other": "Remove Apps?"

View File

@@ -252,7 +252,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "¿Eliminar Aplicación?",
"other": "¿Eliminar Aplicaciones?"

View File

@@ -252,7 +252,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "برنامه حذف شود؟",
"other": "برنامه ها حذف شوند؟"

View File

@@ -252,7 +252,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "Supprimer l'application ?",
"other": "Supprimer les applications ?"

View File

@@ -251,7 +251,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "Eltávolítja az alkalmazást?",
"other": "Eltávolítja az alkalmazást?"

View File

@@ -252,7 +252,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "Rimuovere l'app?",
"other": "Rimuovere le app?"

View File

@@ -253,7 +253,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "アプリを削除しますか?",
"other": "アプリを削除しますか?"

View File

@@ -258,7 +258,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "Usunąć aplikację?",
"few": "Usunąć aplikacje?",

View File

@@ -252,7 +252,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "Удалить приложение?",
"other": "Удалить приложения?"

View File

@@ -253,7 +253,7 @@
"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)",
"autoExportOnChanges": "Auto-export on changes",
"removeAppQuestion": {
"one": "是否删除应用?",
"other": "是否删除应用?"

View File

@@ -19,7 +19,7 @@ import 'package:easy_localization/src/easy_localization_controller.dart';
// ignore: implementation_imports
import 'package:easy_localization/src/localization.dart';
const String currentVersion = '0.14.12';
const String currentVersion = '0.14.13';
const String currentReleaseTag =
'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES

View File

@@ -74,11 +74,6 @@ class AppsPageState extends State<AppsPage> {
setState(() {
refreshingSince = null;
});
if (settingsProvider.autoExportOnUpdateCheckKeepNum > 0) {
appsProvider.exportApps(isAuto: true).then((value) {
appsProvider.trimAutoExports();
});
}
});
}

View File

@@ -337,36 +337,19 @@ class _ImportExportPageState extends State<ImportExportPage> {
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);
}
])
GeneratedFormSwitch(
'autoExportOnChanges',
label: tr('autoExportOnChanges'),
defaultValue:
settingsProvider.autoExportOnChanges,
)
]
],
onValueChanges: (value, valid, isBuilding) {
if (valid && !isBuilding) {
if (value[
'autoExportOnUpdateCheckKeepNum'] !=
null) {
settingsProvider
.autoExportOnUpdateCheckKeepNum =
int.parse(value[
'autoExportOnUpdateCheckKeepNum']);
if (value['autoExportOnChanges'] != null) {
settingsProvider.autoExportOnChanges =
value['autoExportOnChanges'] == true;
}
}
}),

View File

@@ -16,7 +16,6 @@ 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';
@@ -917,6 +916,7 @@ class AppsProvider with ChangeNotifier {
}
}
notifyListeners();
await exportApps(isAuto: true);
}
Future<void> removeApps(List<String> appIds) async {
@@ -938,6 +938,7 @@ class AppsProvider with ChangeNotifier {
}
if (appIds.isNotEmpty) {
notifyListeners();
await exportApps(isAuto: true);
}
}
@@ -1097,6 +1098,17 @@ class AppsProvider with ChangeNotifier {
Future<String?> exportApps({bool pickOnly = false, isAuto = false}) async {
if (isAuto) {
logs.add('Started auto-export.');
var exportDir = settingsProvider.exportDir;
if (exportDir != null) {
var files = await saf.listFiles(exportDir,
columns: [saf.DocumentFileColumn.id]).toList();
if (files.isNotEmpty) {
for (var f in files) {
saf.delete(f.uri);
}
logs.add('Previous auto-export deleted.');
}
}
}
var exportDir = settingsProvider.exportDir;
if (exportDir == null || pickOnly) {
@@ -1122,32 +1134,6 @@ class AppsProvider with ChangeNotifier {
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);
});
}
}
}
Future<int> importApps(String appsJSON) async {
List<App> importedApps = (jsonDecode(appsJSON) as List<dynamic>)
.map((e) => App.fromJson(e))
@@ -1431,10 +1417,6 @@ 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) {

View File

@@ -391,12 +391,12 @@ class SettingsProvider with ChangeNotifier {
}
}
int get autoExportOnUpdateCheckKeepNum {
return prefs?.getInt('autoExportOnUpdateCheckKeepNum') ?? 0;
bool get autoExportOnChanges {
return prefs?.getBool('autoExportOnChanges') ?? false;
}
set autoExportOnUpdateCheckKeepNum(int val) {
prefs?.setInt('autoExportOnUpdateCheckKeepNum', val);
set autoExportOnChanges(bool val) {
prefs?.setBool('autoExportOnChanges', val);
notifyListeners();
}
}

View File

@@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.14.12+204 # When changing this, update the tag in main() accordingly
version: 0.14.13+205 # When changing this, update the tag in main() accordingly
environment:
sdk: '>=3.0.0 <4.0.0'