fix(sources): the custom-source switch stopped turning itself off

Two defects in how the data source settings were read.

The switch reported a state nobody had chosen. `useCustomTLE` was ANDed with
`tleUrl != Sources.defaultTleUrl`, so an operator who enabled custom sources and then
typed the default URL by hand saw the switch flip itself off. It now reports what they set.

The example.com placeholder rewrite ran on every read. A 4.4.7-era build could persist
`https://example.com/tle.txt`, and the fix for that rewrote the value each time it was
read - so the stored value and the returned value disagreed indefinitely and nothing ever
settled it. It is now a one-time migration following migrateRCFormats, which writes the
correction back and records that it has run.

Not addressed here, and the reason the settings screen still misleads: a custom TLE URL
replaces only the source keyed "All" and the other 27 hardcoded sources are still fetched
unconditionally, so "use custom sources" actually means "my source plus 27 others". Which
way that should go is a decision about intent rather than a defect to patch, and upstream
fetches all of its sources unconditionally, which is where the behaviour came from.
This commit is contained in:
mckero committed 2026-08-26 01:35:02 +00:00
1 parent 758dc6d567
commit e8e67b74cd
1 file changed
+36 -10
@@ -455,18 +455,44 @@ class SettingsRepo(
_dataSourcesSettings.value = settings _dataSourcesSettings.value = settings
} }
/** Placeholders a 4.4.7-era build could persist. Neither is a reachable address. */
private val placeholderTleUrl = "https://example.com/tle.txt"
private val placeholderRadioUrl = "https://example.com/radio.json"
private val keyPlaceholderUrlsMigrated = "placeholderUrlsMigrated"
/**
* Replace the example.com placeholders an old build could store.
*
* Runs once, following the pattern of migrateRCFormats. This used to be a rewrite applied on
* every read, so the stored value and the returned value disagreed indefinitely and nothing
* ever settled the difference.
*/
private fun migratePlaceholderUrls() {
if (preferences.getBoolean(keyPlaceholderUrlsMigrated, false)) return
preferences.edit {
if (preferences.getString(keyTleUrl, null) == placeholderTleUrl) {
putString(keyTleUrl, Sources.defaultTleUrl)
putBoolean(keyUseCustomTle, false)
}
if (preferences.getString(keyTransceiversUrl, null) == placeholderRadioUrl) {
putString(keyTransceiversUrl, Sources.defaultTransceiversUrl)
putBoolean(keyUseCustomTransceivers, false)
}
putBoolean(keyPlaceholderUrlsMigrated, true)
}
}
private fun getDataSourcesSettings(): DataSourcesSettings { private fun getDataSourcesSettings(): DataSourcesSettings {
// 4.4.8 fix: legacy example.com placeholder URLs count as unconfigured -> replaced with the real default URL and the switch forced off, migratePlaceholderUrls()
// otherwise the online All/SatNOGS sources would point at the wrong address and fail to update // The switch is reported as the operator set it. It used to be ANDed with
val storedTleUrl = preferences.getString(keyTleUrl, Sources.defaultTleUrl) ?: Sources.defaultTleUrl // `url != default`, so typing the default URL by hand switched custom sources off by
val storedTxUrl = preferences.getString(keyTransceiversUrl, Sources.defaultTransceiversUrl) ?: Sources.defaultTransceiversUrl // itself and the settings screen showed a state nobody had chosen.
val tleUrl = if (storedTleUrl == "https://example.com/tle.txt") Sources.defaultTleUrl else storedTleUrl
val txUrl = if (storedTxUrl == "https://example.com/radio.json") Sources.defaultTransceiversUrl else storedTxUrl
return DataSourcesSettings( return DataSourcesSettings(
useCustomTLE = preferences.getBoolean(keyUseCustomTle, false) && tleUrl != Sources.defaultTleUrl, useCustomTLE = preferences.getBoolean(keyUseCustomTle, false),
useCustomTransceivers = preferences.getBoolean(keyUseCustomTransceivers, false) && txUrl != Sources.defaultTransceiversUrl, useCustomTransceivers = preferences.getBoolean(keyUseCustomTransceivers, false),
tleUrl = tleUrl, tleUrl = preferences.getString(keyTleUrl, Sources.defaultTleUrl) ?: Sources.defaultTleUrl,
transceiversUrl = txUrl transceiversUrl = preferences.getString(keyTransceiversUrl, Sources.defaultTransceiversUrl)
?: Sources.defaultTransceiversUrl
) )
} }