mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-19 05:00:21 +02:00
@@ -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) {
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user