Allow excluding secret values from export file (#2430)

This commit is contained in:
Imran Remtulla
2025-08-01 15:52:39 -04:00
parent 75430573f3
commit 8204a16e90
32 changed files with 89 additions and 19 deletions

View File

@@ -1965,7 +1965,7 @@ class AppsProvider with ChangeNotifier {
Map<String, dynamic> generateExportJSON({
List<String>? appIds,
bool? overrideExportSettings,
int? overrideExportSettings,
}) {
Map<String, dynamic> finalExport = {};
finalExport['apps'] = apps.values
@@ -1978,15 +1978,18 @@ class AppsProvider with ChangeNotifier {
})
.map((e) => e.app.toJson())
.toList();
bool shouldExportSettings = settingsProvider.exportSettings;
int shouldExportSettings = settingsProvider.exportSettings;
if (overrideExportSettings != null) {
shouldExportSettings = overrideExportSettings;
}
if (shouldExportSettings) {
if (shouldExportSettings > 0) {
var settingsValueKeys = settingsProvider.prefs?.getKeys();
if (shouldExportSettings < 2) {
settingsValueKeys?.removeWhere((k) => k.endsWith('-creds'));
}
finalExport['settings'] = Map<String, Object?>.fromEntries(
(settingsProvider.prefs
?.getKeys()
.map((key) => MapEntry(key, settingsProvider.prefs?.get(key)))
(settingsValueKeys
?.map((key) => MapEntry(key, settingsProvider.prefs?.get(key)))
.toList()) ??
[],
);

View File

@@ -453,12 +453,19 @@ class SettingsProvider with ChangeNotifier {
notifyListeners();
}
bool get exportSettings {
return prefs?.getBool('exportSettings') ?? false;
int get exportSettings {
try {
return prefs?.getInt('exportSettings') ??
1; // 0 for no, 1 for yes but no secrets, 2 for everything
} catch (e) {
var val = prefs?.getBool('exportSettings') == true ? 1 : 0;
prefs?.setInt('exportSettings', val);
return val;
}
}
set exportSettings(bool val) {
prefs?.setBool('exportSettings', val);
set exportSettings(int val) {
prefs?.setInt('exportSettings', val > 2 || val < 0 ? 1 : val);
notifyListeners();
}