forked from eatvio/eatvio_app
31 lines
1.1 KiB
Dart
31 lines
1.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:eatvio_app/core/app_config.dart';
|
|
import 'package:eatvio_app/core/locator_service.dart';
|
|
import 'package:eatvio_app/core/prefs.dart';
|
|
import 'package:eatvio_app/core/prefs_keys.dart';
|
|
|
|
/// Подставляет сохранённый base URL до создания HTTP-клиента.
|
|
///
|
|
/// Действующий адрес также пишется в [PrefsKeys.apiBaseUrl], чтобы нативный
|
|
/// decline мог собрать `POST /video-call/decline`, когда Flutter не запущен.
|
|
void applyCachedBaseUrl() {
|
|
if (!sl.isRegistered<Prefs>() || !sl.isRegistered<AppConfig>()) {
|
|
return;
|
|
}
|
|
final cached = sl<Prefs>().getString(PrefsKeys.customBaseUrl)?.trim();
|
|
if (cached != null && cached.isNotEmpty) {
|
|
sl<AppConfig>().setBaseUrl(cached);
|
|
return;
|
|
}
|
|
_persistApiBaseUrl(sl<AppConfig>().baseUrl);
|
|
}
|
|
|
|
void _persistApiBaseUrl(String baseUrl) {
|
|
final normalized = baseUrl.trim();
|
|
if (normalized.isEmpty || !sl.isRegistered<Prefs>()) {
|
|
return;
|
|
}
|
|
unawaited(sl<Prefs>().setString(PrefsKeys.apiBaseUrl, normalized));
|
|
}
|