DevMode: Add password

This commit is contained in:
naturecodevoid
2023-02-22 12:18:42 -08:00
parent 13f9a9d1bf
commit 3ea478ad05
3 changed files with 79 additions and 30 deletions

View File

@@ -250,8 +250,12 @@ internal enum L10n {
internal static let console = L10n.tr("Localizable", "DevModeView.console", fallback: "Console") internal static let console = L10n.tr("Localizable", "DevModeView.console", fallback: "Console")
/// Data File Explorer /// Data File Explorer
internal static let dataExplorer = L10n.tr("Localizable", "DevModeView.dataExplorer", fallback: "Data File Explorer") internal static let dataExplorer = L10n.tr("Localizable", "DevModeView.dataExplorer", fallback: "Data File Explorer")
/// Incorrect password.
internal static let incorrectPassword = L10n.tr("Localizable", "DevModeView.incorrectPassword", fallback: "Incorrect password.")
/// minimuxer debug actions /// minimuxer debug actions
internal static let minimuxer = L10n.tr("Localizable", "DevModeView.minimuxer", fallback: "minimuxer debug actions") internal static let minimuxer = L10n.tr("Localizable", "DevModeView.minimuxer", fallback: "minimuxer debug actions")
/// Password
internal static let password = L10n.tr("Localizable", "DevModeView.password", fallback: "Password")
/// SideStore's Developer Mode gives access to a menu with some debugging actions commonly used by developers. **However, some of them can break SideStore if used in the wrong way.** /// SideStore's Developer Mode gives access to a menu with some debugging actions commonly used by developers. **However, some of them can break SideStore if used in the wrong way.**
/// ///
/// You should only enable Developer Mode if you meet one of the following requirements: /// You should only enable Developer Mode if you meet one of the following requirements:

View File

@@ -176,6 +176,8 @@ You should only enable Developer Mode if you meet one of the following requireme
- You were asked to do this when you reported a bug or helped a developer test a change - You were asked to do this when you reported a bug or helped a developer test a change
**_We will not provide support if you break SideStore with Developer Mode._**"; **_We will not provide support if you break SideStore with Developer Mode._**";
"DevModeView.password" = "Password";
"DevModeView.incorrectPassword" = "Incorrect password.";
"DevModeView.read" = "Read the text!"; "DevModeView.read" = "Read the text!";
"DevModeView.console" = "Console"; "DevModeView.console" = "Console";
"DevModeView.dataExplorer" = "Data File Explorer"; "DevModeView.dataExplorer" = "Data File Explorer";

View File

@@ -9,18 +9,25 @@
import SwiftUI import SwiftUI
import LocalConsole import LocalConsole
// Yes, we know the password is right here. It's also in CONTRIBUTING.md. It's not supposed to be a secret, just something to hopefully prevent people breaking SideStore with dev mode and then complaining to us.
let DEV_MODE_PASSWORD = "devmode"
struct DevModePrompt: View { struct DevModePrompt: View {
@Binding var isShowingDevModePrompt: Bool @Binding var isShowingDevModePrompt: Bool
@Binding var isShowingDevModeMenu: Bool @Binding var isShowingDevModeMenu: Bool
@State var countdown = 0 @State var countdown = 0
@State var isShowingPasswordAlert = false
@State var isShowingIncorrectPasswordAlert = false
@State var password = ""
var button: some View { var button: some View {
SwiftUI.Button(action: { SwiftUI.Button(action: {
UserDefaults.standard.isDevModeEnabled = true if #available(iOS 15.0, *) {
isShowingDevModePrompt = false isShowingPasswordAlert = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { } else {
isShowingDevModeMenu = true // iOS 14 doesn't support .alert, so just go straight to dev mode without asking for a password
enableDevMode()
} }
}) { }) {
Text(countdown <= 0 ? L10n.Action.enable + " " + L10n.DevModeView.title : L10n.DevModeView.read + " (\(countdown))") Text(countdown <= 0 ? L10n.Action.enable + " " + L10n.DevModeView.title : L10n.DevModeView.read + " (\(countdown))")
@@ -41,8 +48,7 @@ struct DevModePrompt: View {
} }
} }
var body: some View { var view: some View {
NavigationView {
ScrollView { ScrollView {
VStack { VStack {
text text
@@ -71,6 +77,43 @@ struct DevModePrompt: View {
tickCountdown() tickCountdown()
} }
} }
var body: some View {
NavigationView {
if #available(iOS 15.0, *) {
view
.alert(L10n.DevModeView.password, isPresented: $isShowingPasswordAlert) {
TextField("Password", text: $password)
.autocapitalization(.none)
.autocorrectionDisabled(true)
SwiftUI.Button("Submit", action: {
if password == DEV_MODE_PASSWORD {
enableDevMode()
} else {
isShowingIncorrectPasswordAlert = true
}
})
}
.alert(L10n.DevModeView.incorrectPassword, isPresented: $isShowingIncorrectPasswordAlert) {
SwiftUI.Button("Try again", action: {
isShowingIncorrectPasswordAlert = false
isShowingPasswordAlert = true
})
SwiftUI.Button("Cancel", action: {
isShowingIncorrectPasswordAlert = false
isShowingDevModePrompt = false
})
}
} else {
view
}
}
}
func enableDevMode() {
UserDefaults.standard.isDevModeEnabled = true
isShowingDevModePrompt = false
isShowingDevModeMenu = true
} }
func tickCountdown() { func tickCountdown() {