writeSettingsToPod function
Write settings to POD (silently, in background). Note: This is only called when user is logged in (from settings dialog close).
Implementation
Future<bool> writeSettingsToPod(Map<String, dynamic> data) async {
try {
final fp = await getSettingsFilePath();
final url = await getFileUrl(fp);
final (:accessToken, :dPopToken) = await getTokensForResource(url, 'PUT');
final r = await http.put(
Uri.parse(url),
headers: {
'Accept': '*/*',
'Authorization': 'DPoP $accessToken',
'Connection': 'keep-alive',
'Content-Type': 'application/json',
'DPoP': dPopToken,
},
body: jsonEncode(data),
);
final success = r.statusCode >= 200 && r.statusCode < 300;
if (success) {
PodDirectoryService.invalidateCache('data');
PodDirectoryService.notifyChange();
}
return success;
} catch (e) {
debugPrint('Error writing settings to POD: $e');
return false;
}
}