1package com.peachpasswords.sync23import android.content.Context4import dagger.hilt.android.qualifiers.ApplicationContext5import javax.inject.Inject6import javax.inject.Singleton7891011121314151617181920@Singleton21class RelaySettingsStore @Inject constructor(22 @ApplicationContext context: Context,23) : RelayPolicy {24 private val prefs = context.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)2526 override fun isRelayEnabled(): Boolean = prefs.getBoolean(KEY_ENABLED, true)2728 fun setRelayEnabled(enabled: Boolean) {29 prefs.edit().putBoolean(KEY_ENABLED, enabled).apply()30 }3132 fun relayUrl(): String = prefs.getString(KEY_URL, null)33 ?.let { runCatching { Rendezvous.normalizeRelayUrl(it) }.getOrNull() }34 ?: Rendezvous.DEFAULT_RELAY_URL3536 fun setRelayUrl(input: String): String {37 val normalized = Rendezvous.normalizeRelayUrl(input)38 prefs.edit().putString(KEY_URL, normalized).apply()39 return normalized40 }4142 fun isLanOnly(): Boolean = prefs.getBoolean(KEY_LAN_ONLY, false)4344 fun setLanOnly(lanOnly: Boolean) {45 prefs.edit().putBoolean(KEY_LAN_ONLY, lanOnly).apply()46 }4748 companion object {49 const val PREFS_FILE = "peach_relay_settings"50 const val KEY_ENABLED = "relay_enabled"51 const val KEY_URL = "relay_url"52 const val KEY_LAN_ONLY = "lan_only"5354 fun readRelayUrl(context: Context): String =55 context.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)56 .getString(KEY_URL, null)57 ?.let { runCatching { Rendezvous.normalizeRelayUrl(it) }.getOrNull() }58 ?: Rendezvous.DEFAULT_RELAY_URL59 }60}