fix(store): harden extension repo registry handling

- Persist registry URL inside store_cache.json and restore it on init so
  the disk cache survives app restarts instead of being wiped every launch
- Fall back to the cached registry when the fetched body fails to parse,
  matching the existing network/HTTP error fallbacks
- Detect HTML responses and surface a clear message instead of the raw
  Go JSON error (invalid character '<') seen in issue #474
- Validate the registry loads before persisting a new URL, and roll the
  backend back to the previous URL on failure, so a broken link never
  survives a restart or Android auto-backup restore
This commit is contained in:
zarzet
2026-07-09 18:19:08 +07:00
parent 6b30eba947
commit 8abb9d119b
3 changed files with 99 additions and 12 deletions
+18 -2
View File
@@ -265,23 +265,39 @@ class StoreNotifier extends Notifier<StoreState> {
state = state.copyWith(isLoading: true, clearError: true);
final previousUrl = state.registryUrl;
try {
await PlatformBridge.setStoreRegistryUrl(trimmed);
final resolvedUrl = await PlatformBridge.getStoreRegistryUrl();
// Validate the registry actually loads before persisting the URL, so a
// broken link never survives an app restart (or a backup restore).
final extensions = await PlatformBridge.getStoreExtensions(
forceRefresh: true,
);
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_registryUrlPrefKey, resolvedUrl);
state = state.copyWith(
registryUrl: resolvedUrl,
extensions: const [],
extensions: extensions.map((e) => StoreExtension.fromJson(e)).toList(),
isLoading: false,
);
_log.i('Registry URL set to: $resolvedUrl');
await refresh(forceRefresh: true);
} catch (e) {
_log.e('Failed to set registry URL: $e');
try {
if (previousUrl.isNotEmpty) {
await PlatformBridge.setStoreRegistryUrl(previousUrl);
} else {
await PlatformBridge.clearStoreRegistryUrl();
}
} catch (restoreError) {
_log.w('Failed to restore previous registry URL: $restoreError');
}
state = state.copyWith(isLoading: false, error: e.toString());
}
}