blob: b0107ebf136fefed312f7bca2e8e9e61b4120098 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* Copyright © 2020 WireGuard LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package com.wireguard.android.util
import androidx.datastore.preferences.edit
import androidx.datastore.preferences.preferencesKey
import androidx.datastore.preferences.preferencesSetKey
import androidx.datastore.preferences.remove
import com.wireguard.android.Application
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
object UserKnobs {
private val DISABLE_KERNEL_MODULE = preferencesKey<Boolean>("disable_kernel_module")
val disableKernelModule: Flow<Boolean>
get() = Application.getPreferencesDataStore().data.map {
it[DISABLE_KERNEL_MODULE] ?: false
}
suspend fun setDisableKernelModule(disable: Boolean?) {
Application.getPreferencesDataStore().edit {
if (disable == null)
it.remove(DISABLE_KERNEL_MODULE)
else
it[DISABLE_KERNEL_MODULE] = disable
}
}
private val MULTIPLE_TUNNELS = preferencesKey<Boolean>("multiple_tunnels")
val multipleTunnels: Flow<Boolean>
get() = Application.getPreferencesDataStore().data.map {
it[MULTIPLE_TUNNELS] ?: false
}
private val DARK_THEME = preferencesKey<Boolean>("dark_theme")
val darkTheme: Flow<Boolean>
get() = Application.getPreferencesDataStore().data.map {
it[DARK_THEME] ?: false
}
private val ALLOW_REMOTE_CONTROL_INTENTS = preferencesKey<Boolean>("allow_remote_control_intents")
val allowRemoteControlIntents: Flow<Boolean>
get() = Application.getPreferencesDataStore().data.map {
it[ALLOW_REMOTE_CONTROL_INTENTS] ?: false
}
private val RESTORE_ON_BOOT = preferencesKey<Boolean>("restore_on_boot")
val restoreOnBoot: Flow<Boolean>
get() = Application.getPreferencesDataStore().data.map {
it[RESTORE_ON_BOOT] ?: false
}
private val LAST_USED_TUNNEL = preferencesKey<String>("last_used_tunnel")
val lastUsedTunnel: Flow<String?>
get() = Application.getPreferencesDataStore().data.map {
it[LAST_USED_TUNNEL]
}
suspend fun setLastUsedTunnel(lastUsedTunnel: String?) {
Application.getPreferencesDataStore().edit {
if (lastUsedTunnel == null)
it.remove(LAST_USED_TUNNEL)
else
it[LAST_USED_TUNNEL] = lastUsedTunnel
}
}
private val RUNNING_TUNNELS = preferencesSetKey<String>("enabled_configs")
val runningTunnels: Flow<Set<String>>
get() = Application.getPreferencesDataStore().data.map {
it[RUNNING_TUNNELS] ?: emptySet()
}
suspend fun setRunningTunnels(runningTunnels: Set<String>) {
Application.getPreferencesDataStore().edit {
if (runningTunnels.isEmpty())
it.remove(RUNNING_TUNNELS)
else
it[RUNNING_TUNNELS] = runningTunnels
}
}
}
|