From d3b6c64e8b1b72adce340f8f7513878b5b32ee33 Mon Sep 17 00:00:00 2001 From: rzuasti Date: Sun, 31 May 2026 09:17:15 -0400 Subject: [PATCH] Apply Settings changes to the live BackendAPI without restart Settings._save wrote new base_url/api_key to prefs but the BackendAPI singleton kept the Dio it built at first access, so URL/key changes only took effect after an app restart. Expose reconfigureFromPrefs() on BackendAPI and call it from Settings._save so subsequent requests pick up the new config immediately. Co-Authored-By: Claude Opus 4.7 --- frontend/lib/settings/settings.dart | 1 + frontend/lib/utils/oott_api.dart | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/frontend/lib/settings/settings.dart b/frontend/lib/settings/settings.dart index 1868c6c..ae85215 100644 --- a/frontend/lib/settings/settings.dart +++ b/frontend/lib/settings/settings.dart @@ -71,6 +71,7 @@ class _SettingsState extends State { if (!_formKey.currentState!.validate()) return; PrefUtil.setValue('base_url', _baseUrlController.text); PrefUtil.setValue('api_key', XOR().xorEncode(_apiKeyController.text)); + BackendAPI.instance.reconfigureFromPrefs(); context.read().setTheme(_selectedTheme); UISnackbars.showSuccess(context, 'Settings saved successfully'); } diff --git a/frontend/lib/utils/oott_api.dart b/frontend/lib/utils/oott_api.dart index c116cb8..ddd0773 100644 --- a/frontend/lib/utils/oott_api.dart +++ b/frontend/lib/utils/oott_api.dart @@ -57,6 +57,10 @@ class BackendAPI { static BackendAPI get instance => _instance; BackendAPI._internal() { + reconfigureFromPrefs(); + } + + void reconfigureFromPrefs() { _baseUrl = PrefUtil.getValue("base_url", "http://localhost:3000/api") as String; _apiKey = XOR().xorDecode(PrefUtil.getValue("api_key", "") as String);