mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-30 21:13:28 +01:00 
			
		
		
		
	Ability to share selective exports (#1752)
This commit is contained in:
		| @@ -917,6 +917,27 @@ class AppsPageState extends State<AppsPage> { | |||||||
|                                 }, |                                 }, | ||||||
|                           child: Text(tr('shareAppConfigLinks'))), |                           child: Text(tr('shareAppConfigLinks'))), | ||||||
|                       const Divider(), |                       const Divider(), | ||||||
|  |                       TextButton( | ||||||
|  |                           onPressed: selectedAppIds.isEmpty | ||||||
|  |                               ? null | ||||||
|  |                               : () { | ||||||
|  |                                   var exportJSON = jsonEncode( | ||||||
|  |                                       appsProvider.generateExportJSON( | ||||||
|  |                                           appIds: selectedApps | ||||||
|  |                                               .map((e) => e.id) | ||||||
|  |                                               .toList(), | ||||||
|  |                                           overrideExportSettings: false)); | ||||||
|  |                                   XFile f = XFile.fromData( | ||||||
|  |                                       Uint8List.fromList( | ||||||
|  |                                           utf8.encode(exportJSON)), | ||||||
|  |                                       mimeType: 'application/json', | ||||||
|  |                                       name: | ||||||
|  |                                           '${tr('obtainiumExportHyphenatedLowercase')}-${selectedApps.length}-${DateTime.now().millisecondsSinceEpoch}'); | ||||||
|  |                                   Share.shareXFiles([f]); | ||||||
|  |                                 }, | ||||||
|  |                           child: Text( | ||||||
|  |                               '${tr('share')} - ${tr('obtainiumExport')}')), | ||||||
|  |                       const Divider(), | ||||||
|                       TextButton( |                       TextButton( | ||||||
|                           onPressed: () { |                           onPressed: () { | ||||||
|                             appsProvider |                             appsProvider | ||||||
|   | |||||||
| @@ -1501,6 +1501,34 @@ class AppsProvider with ChangeNotifier { | |||||||
|     return updateAppIds; |     return updateAppIds; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   Map<String, dynamic> generateExportJSON( | ||||||
|  |       {List<String>? appIds, bool? overrideExportSettings}) { | ||||||
|  |     Map<String, dynamic> finalExport = {}; | ||||||
|  |     finalExport['apps'] = apps.values | ||||||
|  |         .where((e) { | ||||||
|  |           if (appIds == null) { | ||||||
|  |             return true; | ||||||
|  |           } else { | ||||||
|  |             return appIds.contains(e.app.id); | ||||||
|  |           } | ||||||
|  |         }) | ||||||
|  |         .map((e) => e.app.toJson()) | ||||||
|  |         .toList(); | ||||||
|  |     bool shouldExportSettings = settingsProvider.exportSettings; | ||||||
|  |     if (overrideExportSettings != null) { | ||||||
|  |       shouldExportSettings = overrideExportSettings; | ||||||
|  |     } | ||||||
|  |     if (shouldExportSettings) { | ||||||
|  |       finalExport['settings'] = Map<String, Object?>.fromEntries( | ||||||
|  |           (settingsProvider.prefs | ||||||
|  |                   ?.getKeys() | ||||||
|  |                   .map((key) => MapEntry(key, settingsProvider.prefs?.get(key))) | ||||||
|  |                   .toList()) ?? | ||||||
|  |               []); | ||||||
|  |     } | ||||||
|  |     return finalExport; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   Future<String?> export( |   Future<String?> export( | ||||||
|       {bool pickOnly = false, isAuto = false, SettingsProvider? sp}) async { |       {bool pickOnly = false, isAuto = false, SettingsProvider? sp}) async { | ||||||
|     SettingsProvider settingsProvider = sp ?? this.settingsProvider; |     SettingsProvider settingsProvider = sp ?? this.settingsProvider; | ||||||
| @@ -1531,17 +1559,7 @@ class AppsProvider with ChangeNotifier { | |||||||
|     } |     } | ||||||
|     String? returnPath; |     String? returnPath; | ||||||
|     if (!pickOnly) { |     if (!pickOnly) { | ||||||
|       Map<String, dynamic> finalExport = {}; |       Map<String, dynamic> finalExport = generateExportJSON(); | ||||||
|       finalExport['apps'] = apps.values.map((e) => e.app.toJson()).toList(); |  | ||||||
|       if (settingsProvider.exportSettings) { |  | ||||||
|         finalExport['settings'] = Map<String, Object?>.fromEntries( |  | ||||||
|             (settingsProvider.prefs |  | ||||||
|                     ?.getKeys() |  | ||||||
|                     .map((key) => |  | ||||||
|                         MapEntry(key, settingsProvider.prefs?.get(key))) |  | ||||||
|                     .toList()) ?? |  | ||||||
|                 []); |  | ||||||
|       } |  | ||||||
|       var result = await saf.createFile(exportDir, |       var result = await saf.createFile(exportDir, | ||||||
|           displayName: |           displayName: | ||||||
|               '${tr('obtainiumExportHyphenatedLowercase')}-${DateTime.now().toIso8601String().replaceAll(':', '-')}${isAuto ? '-auto' : ''}.json', |               '${tr('obtainiumExportHyphenatedLowercase')}-${DateTime.now().toIso8601String().replaceAll(':', '-')}${isAuto ? '-auto' : ''}.json', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user