readSettingsFromPod function
Read settings from POD. Returns null if not logged in or if no settings exist.
Implementation
Future<Map<String, dynamic>?> readSettingsFromPod() async {
try {
// Quick sync check - avoid slow async checkLoggedIn()
if (!authStateNotifier.value) return null;
final fp = await getSettingsFilePath();
final url = await getFileUrl(fp);
final (:accessToken, :dPopToken) = await getTokensForResource(url, 'GET');
final r = await http.get(
Uri.parse(url),
headers: {
'Accept': 'application/json, */*',
'Authorization': 'DPoP $accessToken',
'Connection': 'keep-alive',
'DPoP': dPopToken,
},
);
if (r.statusCode == 200 && r.body.trim().isNotEmpty) {
final decoded = jsonDecode(r.body);
if (decoded is Map<String, dynamic>) return decoded;
}
return null;
} catch (e) {
debugPrint('Error reading settings from POD: $e');
return null;
}
}