Skip to content

Commit ac29176

Browse files
committed
Implemented enabling and disabling debug mode.
- 7 taps on version number will prompt to enable the debug mode - by clicking on exit from debug button to prompt disable mode
1 parent 27b1681 commit ac29176

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

GoInfoGame/GoInfoGame/Login/View/PosmLogin.swift

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ struct PosmLoginView: View {
1717

1818
@State private var selectedEnvironment: APIEnvironment = .production
1919
@State private var showAlert = false
20+
@State private var debugMode: Bool = false
21+
@State private var showEnableDebugModeAlert: Bool = false
22+
@State private var showDisableDebugModeAlert: Bool = false
2023

2124
var body: some View {
2225
NavigationStack {
@@ -59,29 +62,29 @@ struct PosmLoginView: View {
5962
.padding(10)
6063
.cornerRadius(10)
6164
.padding(.horizontal, 40)
62-
#if DEBUG
63-
Menu {
64-
ForEach(APIEnvironment.allCases, id: \.self) { environment in
65-
Button(action: {
66-
selectedEnvironment = environment
67-
APIConfiguration.shared.environment = environment
68-
}) {
69-
Text(environment.rawValue)
65+
if debugMode {
66+
Menu {
67+
ForEach(APIEnvironment.allCases, id: \.self) { environment in
68+
Button(action: {
69+
selectedEnvironment = environment
70+
APIConfiguration.shared.environment = environment
71+
}) {
72+
Text(environment.rawValue)
73+
}
7074
}
75+
} label: {
76+
HStack {
77+
Text("Environment: \(selectedEnvironment.rawValue)")
78+
.foregroundColor(.black)
79+
Image(systemName: "chevron.down")
80+
}
81+
.padding()
82+
.background(Color(.systemGray6))
83+
.cornerRadius(10)
7184
}
72-
} label: {
73-
HStack {
74-
Text("Environment: \(selectedEnvironment.rawValue)")
75-
.foregroundColor(.black)
76-
Image(systemName: "chevron.down")
77-
}
78-
.padding()
79-
.background(Color(.systemGray6))
80-
.cornerRadius(10)
85+
.padding(.horizontal, 40)
8186
}
82-
.padding(.horizontal, 40)
8387

84-
#endif
8588
Button(action: {
8689
APIConfiguration.shared.environment = selectedEnvironment
8790
viewModel.performLogin(for: selectedEnvironment)
@@ -138,7 +141,23 @@ struct PosmLoginView: View {
138141
}
139142

140143
Spacer()
144+
if debugMode {
145+
Button {
146+
showDisableDebugModeAlert = true
147+
} label: {
148+
Text("Exit debug mode")
149+
.font(FontFamily.Lato.bold.swiftUIFont(size: 16))
150+
.foregroundColor(Asset.Colors.d74BA827Pink.swiftUIColor)
151+
}
152+
.padding(.bottom, 5)
153+
}
141154
appVersionText
155+
.accessibilityRespondsToUserInteraction()
156+
.onTapGesture(count: 7, perform: {
157+
if !debugMode {
158+
showEnableDebugModeAlert = true
159+
}
160+
})
142161
}
143162
.padding([.top], 0)
144163

@@ -166,6 +185,27 @@ struct PosmLoginView: View {
166185
} message: {
167186
Text("Would you like to use Face ID or Touch ID for faster logins?")
168187
}
188+
.alert("Debug mode", isPresented: $showEnableDebugModeAlert) {
189+
Button("Enable") {
190+
debugMode = true
191+
}
192+
Button("Not Now", role: .cancel) {
193+
194+
}
195+
} message: {
196+
Text("Do you want to enable debug mode?")
197+
}
198+
.alert("Debug mode", isPresented: $showDisableDebugModeAlert) {
199+
Button("Disable") {
200+
selectedEnvironment = .production
201+
debugMode = false
202+
}
203+
Button("Not Now", role: .cancel) {
204+
205+
}
206+
} message: {
207+
Text("Do you want to disable debug mode?")
208+
}
169209
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("SessionExpired"))) { notification in
170210
showAlert = true
171211
}

0 commit comments

Comments
 (0)