generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathDeveloperOptionsScreen.swift
176 lines (154 loc) · 6.23 KB
/
DeveloperOptionsScreen.swift
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// Copyright 2022-2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.
//
import SwiftUI
struct DeveloperOptionsScreen: View {
@ObservedObject var context: DeveloperOptionsScreenViewModel.Context
@State private var showConfetti = false
@State private var elementCallURLOverrideString: String
init(context: DeveloperOptionsScreenViewModel.Context) {
self.context = context
elementCallURLOverrideString = context.elementCallBaseURLOverride?.absoluteString ?? ""
}
var body: some View {
Form {
Section("Logging") {
LogLevelConfigurationView(logLevel: $context.logLevel)
}
Section {
Picker("Discovery", selection: $context.slidingSyncDiscovery) {
Text("Proxy only").tag(AppSettings.SlidingSyncDiscovery.proxy)
Text("Automatic").tag(AppSettings.SlidingSyncDiscovery.native)
Text("Force Native ⚠️").tag(AppSettings.SlidingSyncDiscovery.forceNative)
}
} header: {
Text("Sliding Sync")
} footer: {
Text(context.viewState.slidingSyncFooter)
}
Section("Room List") {
Toggle(isOn: $context.hideUnreadMessagesBadge) {
Text("Hide grey dots")
}
Toggle(isOn: $context.fuzzyRoomListSearchEnabled) {
Text("Fuzzy searching")
}
}
Section("Timeline") {
Toggle(isOn: $context.hideTimelineMedia) {
Text("Hide image & video previews")
}
Toggle(isOn: $context.frequentEmojisEnabled) {
Text("Show frequently used emojis")
}
}
Section("Join rules") {
Toggle(isOn: $context.knockingEnabled) {
Text("Knocking")
Text("Experimental, still using mocked data")
}
}
Section {
Toggle(isOn: $context.enableOnlySignedDeviceIsolationMode) {
Text("Exclude insecure devices when sending/receiving messages")
Text("Requires app reboot")
}
} header: {
Text("Trust and Decoration")
} footer: {
Text("This setting controls how end-to-end encryption (E2EE) keys are exchanged. Enabling it will prevent the inclusion of devices that have not been explicitly verified by their owners.")
}
Section {
TextField(context.viewState.elementCallBaseURL.absoluteString, text: $elementCallURLOverrideString)
.autocorrectionDisabled(true)
.autocapitalization(.none)
.foregroundColor(URL(string: elementCallURLOverrideString) == nil ? .red : .primary)
.submitLabel(.done)
.onSubmit {
if elementCallURLOverrideString.isEmpty {
context.elementCallBaseURLOverride = nil
} else if let url = URL(string: elementCallURLOverrideString) {
context.elementCallBaseURLOverride = url
}
}
} header: {
Text("Element Call")
} footer: {
if context.elementCallBaseURLOverride == nil {
Text("The call URL may be overridden by your homeserver.")
}
}
Section {
Button {
showConfetti = true
} label: {
Text("🥳")
.frame(maxWidth: .infinity)
.alignmentGuide(.listRowSeparatorLeading) { _ in 0 } // Fix separator alignment
}
Button {
fatalError("This crash is a test.")
} label: {
Text("💥")
.frame(maxWidth: .infinity)
}
}
Section {
Button(role: .destructive) {
context.send(viewAction: .clearCache)
} label: {
Text("Clear cache")
.frame(maxWidth: .infinity)
}
}
}
.overlay(effectsView)
.compoundList()
.navigationTitle(L10n.commonDeveloperOptions)
.navigationBarTitleDisplayMode(.inline)
}
@ViewBuilder
private var effectsView: some View {
if showConfetti {
EffectsView(effect: .confetti)
.ignoresSafeArea()
.allowsHitTesting(false)
.task { await removeConfettiAfterDelay() }
}
}
private func removeConfettiAfterDelay() async {
try? await Task.sleep(for: .seconds(4))
showConfetti = false
}
}
private struct LogLevelConfigurationView: View {
@Binding var logLevel: TracingConfiguration.LogLevel
var body: some View {
Picker(selection: $logLevel) {
ForEach(logLevels, id: \.self) { logLevel in
Text(logLevel.title)
}
} label: {
Text("Log level")
Text("Requires app reboot")
}
}
/// Allows the picker to work with associated values
private var logLevels: [TracingConfiguration.LogLevel] {
[.error, .warn, .info, .debug, .trace]
}
}
// MARK: - Previews
struct DeveloperOptionsScreen_Previews: PreviewProvider {
static let viewModel = DeveloperOptionsScreenViewModel(developerOptions: ServiceLocator.shared.settings,
elementCallBaseURL: ServiceLocator.shared.settings.elementCallBaseURL,
isUsingNativeSlidingSync: true)
static var previews: some View {
NavigationStack {
DeveloperOptionsScreen(context: viewModel.context)
}
}
}