Skip to content

Commit a629a84

Browse files
committed
Remove broken proxy functionality and replace dev preferences with datastore
1 parent 79f73cf commit a629a84

11 files changed

Lines changed: 99 additions & 337 deletions

File tree

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
package acr.browser.lightning.utils
22

3-
import acr.browser.lightning.preference.DeveloperPreferences
3+
import acr.browser.lightning.concurrency.CoroutineDispatchers
4+
import acr.browser.lightning.preference.DeveloperPreferenceStore
5+
import kotlinx.coroutines.CoroutineScope
6+
import kotlinx.coroutines.launch
47
import leakcanary.LeakCanary
58
import javax.inject.Inject
69

710
/**
811
* Sets up LeakCanary.
912
*/
10-
class LeakCanaryUtils @Inject constructor(private val developerPreferences: DeveloperPreferences) {
13+
class LeakCanaryUtils @Inject constructor(
14+
private val developerPreferenceStore: DeveloperPreferenceStore,
15+
private val appCoroutineScope: CoroutineScope,
16+
private val coroutineDispatchers: CoroutineDispatchers,
17+
) {
1118

1219
/**
1320
* Setup LeakCanary
1421
*/
1522
fun setup() {
16-
LeakCanary.config = LeakCanary.config.copy(
17-
dumpHeap = developerPreferences.useLeakCanary
18-
)
23+
appCoroutineScope.launch(coroutineDispatchers.io) {
24+
LeakCanary.config = LeakCanary.config.copy(
25+
dumpHeap = developerPreferenceStore.useLeakCanary.get()
26+
)
27+
}
1928
}
2029

2130
}

app/src/main/java/acr/browser/lightning/BrowserApp.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import acr.browser.lightning.browser.di.AppComponent
44
import acr.browser.lightning.browser.di.DaggerAppComponent
55
import acr.browser.lightning.browser.di.DatabaseScheduler
66
import acr.browser.lightning.browser.di.injector
7-
import acr.browser.lightning.browser.proxy.ProxyAdapter
87
import acr.browser.lightning.database.bookmark.BookmarkExporter
98
import acr.browser.lightning.database.bookmark.BookmarkRepository
109
import acr.browser.lightning.device.BuildInfo
@@ -47,9 +46,6 @@ class BrowserApp : Application() {
4746
@Inject
4847
internal lateinit var buildInfo: BuildInfo
4948

50-
@Inject
51-
internal lateinit var proxyAdapter: ProxyAdapter
52-
5349
@Inject
5450
internal lateinit var cleanup: Cleanup
5551

@@ -126,8 +122,6 @@ class BrowserApp : Application() {
126122
if (buildInfo.buildType == BuildType.DEBUG) {
127123
WebView.setWebContentsDebuggingEnabled(true)
128124
}
129-
130-
registerActivityLifecycleCallbacks(proxyAdapter)
131125
}
132126

133127
/**

app/src/main/java/acr/browser/lightning/browser/BrowserActivity.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import acr.browser.lightning.extensions.takeIfInstance
4949
import acr.browser.lightning.extensions.tint
5050
import acr.browser.lightning.search.SuggestionsAdapter
5151
import acr.browser.lightning.ssl.createSslDrawableForState
52-
import acr.browser.lightning.utils.ProxyUtils
5352
import acr.browser.lightning.utils.value
5453
import android.content.Intent
5554
import android.content.pm.ActivityInfo
@@ -134,9 +133,6 @@ abstract class BrowserActivity : ThemableBrowserActivity() {
134133
@Inject
135134
internal lateinit var uiConfiguration: UiConfiguration
136135

137-
@Inject
138-
internal lateinit var proxyUtils: ProxyUtils
139-
140136
@Inject
141137
internal lateinit var themeProvider: ThemeProvider
142138

app/src/main/java/acr/browser/lightning/browser/proxy/ProxyAdapter.kt

Lines changed: 0 additions & 44 deletions
This file was deleted.

app/src/main/java/acr/browser/lightning/browser/proxy/ProxyChoice.kt

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package acr.browser.lightning.preference
2+
3+
import acr.browser.lightning.preference.datastore.NonNullPreferenceStore
4+
import android.app.Application
5+
import androidx.datastore.migrations.SharedPreferencesMigration
6+
import androidx.datastore.migrations.SharedPreferencesView
7+
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
8+
import androidx.datastore.preferences.core.Preferences
9+
import androidx.datastore.preferences.core.booleanPreferencesKey
10+
import androidx.datastore.preferences.preferencesDataStoreFile
11+
import javax.inject.Inject
12+
import javax.inject.Singleton
13+
14+
/**
15+
* Preferences related to development debugging.
16+
*/
17+
@Singleton
18+
class DeveloperPreferenceStore @Inject constructor(
19+
private val application: Application
20+
) {
21+
22+
private val dataStore = PreferenceDataStoreFactory.create(
23+
migrations = listOf(
24+
SharedPreferencesMigration(
25+
produceSharedPreferences = {
26+
application.getSharedPreferences(FILE_NAME, 0)
27+
},
28+
) { sharedPreferences: SharedPreferencesView, preferences: Preferences ->
29+
preferences.toMutablePreferences().apply {
30+
set(keyUseLeakCanary, sharedPreferences.getBoolean(LEAK_CANARY, false))
31+
}
32+
}
33+
),
34+
produceFile = {
35+
application.preferencesDataStoreFile(FILE_NAME)
36+
}
37+
)
38+
39+
private val keyUseLeakCanary = booleanPreferencesKey(LEAK_CANARY)
40+
// private val keyCheckedForTor = booleanPreferencesKey(INITIAL_CHECK_FOR_TOR)
41+
// private val keyCheckedForI2P = booleanPreferencesKey(INITIAL_CHECK_FOR_I2P)
42+
43+
val useLeakCanary = NonNullPreferenceStore(
44+
keyUseLeakCanary,
45+
dataStore,
46+
false
47+
)
48+
49+
// val checkedForTor = NonNullPreferenceStore(
50+
// keyCheckedForTor,
51+
// dataStore,
52+
// false
53+
// )
54+
55+
// val checkedForI2P = NonNullPreferenceStore(
56+
// keyCheckedForI2P,
57+
// dataStore,
58+
// false
59+
// )
60+
61+
// var checkedForI2P by preferences.booleanPreference(INITIAL_CHECK_FOR_I2P, false)
62+
63+
companion object {
64+
private const val FILE_NAME = "developer_settings"
65+
66+
private const val LEAK_CANARY = "leakCanary"
67+
// private const val INITIAL_CHECK_FOR_TOR = "checkForTor"
68+
// private const val INITIAL_CHECK_FOR_I2P = "checkForI2P"
69+
}
70+
}

app/src/main/java/acr/browser/lightning/preference/DeveloperPreferences.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/src/main/java/acr/browser/lightning/settings/fragment/DebugSettingsFragment.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,33 @@ package acr.browser.lightning.settings.fragment
33
import acr.browser.lightning.R
44
import acr.browser.lightning.browser.di.injector
55
import acr.browser.lightning.extensions.snackbar
6-
import acr.browser.lightning.preference.DeveloperPreferences
6+
import acr.browser.lightning.preference.DeveloperPreferenceStore
77
import android.os.Bundle
8+
import kotlinx.coroutines.runBlocking
89
import javax.inject.Inject
910

1011
class DebugSettingsFragment : AbstractSettingsFragment() {
1112

12-
@Inject internal lateinit var developerPreferences: DeveloperPreferences
13+
@Inject internal lateinit var developerPreferenceStore: DeveloperPreferenceStore
1314

1415
override fun providePreferencesXmlResource() = R.xml.preference_debug
1516

1617
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
1718
super.onCreatePreferences(savedInstanceState, rootKey)
1819
injector.inject(this)
1920

20-
togglePreference(
21-
preference = LEAK_CANARY,
22-
isChecked = developerPreferences.useLeakCanary,
23-
onCheckChange = { change ->
24-
activity?.snackbar(R.string.app_restart)
25-
developerPreferences.useLeakCanary = change
26-
}
27-
)
21+
runBlocking {
22+
togglePreference(
23+
preference = LEAK_CANARY,
24+
isChecked = developerPreferenceStore.useLeakCanary.get(),
25+
onCheckChange = { change ->
26+
activity?.snackbar(R.string.app_restart)
27+
runBlocking {
28+
developerPreferenceStore.useLeakCanary.set(change)
29+
}
30+
}
31+
)
32+
}
2833
}
2934

3035
companion object {

0 commit comments

Comments
 (0)