mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
feat: Import and export manager settings (#2268)
This commit is contained in:
@ -222,6 +222,53 @@ class SettingsViewModel extends BaseViewModel {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> exportSettings() async {
|
||||
try {
|
||||
final String settings = _managerAPI.exportSettings();
|
||||
final Directory tempDir = await getTemporaryDirectory();
|
||||
final String filePath = '${tempDir.path}/manager_settings.json';
|
||||
final File file = File(filePath);
|
||||
await file.writeAsString(settings);
|
||||
final String? result = await FlutterFileDialog.saveFile(
|
||||
params: SaveFileDialogParams(
|
||||
sourceFilePath: file.path,
|
||||
fileName: 'manager_settings.json',
|
||||
mimeTypesFilter: ['application/json'],
|
||||
),
|
||||
);
|
||||
if (result != null) {
|
||||
_toast.showBottom(t.settingsView.exportedSettings);
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> importSettings() async {
|
||||
try {
|
||||
final String? result = await FlutterFileDialog.pickFile(
|
||||
params: const OpenFileDialogParams(
|
||||
fileExtensionsFilter: ['json'],
|
||||
),
|
||||
);
|
||||
if (result != null) {
|
||||
final File inFile = File(result);
|
||||
final String settings = inFile.readAsStringSync();
|
||||
inFile.delete();
|
||||
_managerAPI.importSettings(settings);
|
||||
_toast.showBottom(t.settingsView.importedSettings);
|
||||
_toast.showBottom(t.settingsView.restartAppForChanges);
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
}
|
||||
_toast.showBottom(t.settingsView.jsonSelectorErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> exportPatches() async {
|
||||
try {
|
||||
final File outFile = File(_managerAPI.storedPatchesFile);
|
||||
|
@ -14,6 +14,30 @@ class SExportSection extends StatelessWidget {
|
||||
return SettingsSection(
|
||||
title: t.settingsView.exportSectionTitle,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
title: Text(
|
||||
t.settingsView.exportSettingsLabel,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
subtitle: Text(t.settingsView.exportSettingsHint),
|
||||
onTap: () => _settingsViewModel.exportSettings(),
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
title: Text(
|
||||
t.settingsView.importSettingsLabel,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
subtitle: Text(t.settingsView.importSettingsHint),
|
||||
onTap: () => _settingsViewModel.importSettings(),
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
title: Text(
|
||||
@ -114,7 +138,6 @@ class SExportSection extends StatelessWidget {
|
||||
subtitle: Text(t.settingsView.regenerateKeystoreHint),
|
||||
onTap: () => _showDeleteKeystoreDialog(context),
|
||||
),
|
||||
// SManageKeystorePasswordUI(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user