Added import/export

This commit is contained in:
Imran Remtulla
2022-08-26 19:48:42 -04:00
parent 9459c96d48
commit 10f1c3abe5
2 changed files with 154 additions and 4 deletions

View File

@@ -132,7 +132,7 @@ class AppsProvider with ChangeNotifier {
await InstallPlugin.installApk(downloadFile.path, 'dev.imranr.obtainium');
apps[appId]!.app.installedVersion = apps[appId]!.app.latestVersion;
saveApp(apps[appId]!.app);
await saveApp(apps[appId]!.app);
}
Future<Directory> getAppsDir() async {
@@ -236,6 +236,40 @@ class AppsProvider with ChangeNotifier {
return updateAppIds;
}
Future<String> exportApps() async {
Directory? exportDir = Directory('/storage/emulated/0/Download');
String path = 'Downloads';
if (!exportDir.existsSync()) {
exportDir = await getExternalStorageDirectory();
path = exportDir!.path;
}
File export = File(
'${exportDir!.path}/obtainium-export-${DateTime.now().millisecondsSinceEpoch}.json');
export.writeAsStringSync(
jsonEncode(apps.values.map((e) => e.app.toJson()).toList()));
return path;
}
Future<int> importApps(String appsJSON) async {
// FilePickerResult? result = await FilePicker.platform.pickFiles();
// if (result != null) {
// String appsJSON = File(result.files.single.path!).readAsStringSync();
List<App> importedApps = (jsonDecode(appsJSON) as List<dynamic>)
.map((e) => App.fromJson(e))
.toList();
for (App a in importedApps) {
a.installedVersion =
apps.containsKey(a.id) ? apps[a]?.app.installedVersion : null;
await saveApp(a);
}
notifyListeners();
return importedApps.length;
// } else {
// User canceled the picker
// }
}
@override
void dispose() {
IsolateNameServer.removePortNameMapping('downloader_send_port');