Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show dev environment indicator in Sync Settings #2265

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion DuckDuckGo/SyncSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ class SyncSettingsViewController: UIHostingController<SyncSettingsView> {
self.syncService = syncService
self.syncBookmarksAdapter = syncBookmarksAdapter

let viewModel = SyncSettingsViewModel()
let viewModel = SyncSettingsViewModel(
isOnDevEnvironment: { syncService.serverEnvironment == .development },
switchToProdEnvironment: {
syncService.updateServerEnvironment(.production)
UserDefaults.standard.set(ServerEnvironment.production.description, forKey: UserDefaultsWrapper<String>.Key.syncEnvironment.rawValue)
}
)

super.init(rootView: SyncSettingsView(model: viewModel))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,16 @@ public class SyncSettingsViewModel: ObservableObject {
@Published var recoveryCode = ""

public weak var delegate: SyncManagementViewModelDelegate?

public init() { }
private(set) var isOnDevEnvironment: Bool
private(set) var switchToProdEnvironment: () -> Void = {}

public init(isOnDevEnvironment: @escaping () -> Bool, switchToProdEnvironment: @escaping () -> Void) {
self.isOnDevEnvironment = isOnDevEnvironment()
self.switchToProdEnvironment = { [weak self] in
switchToProdEnvironment()
self?.isOnDevEnvironment = isOnDevEnvironment()
}
}

func disableSync() {
isBusy = true
Expand Down
34 changes: 34 additions & 0 deletions LocalPackages/SyncUI/Sources/SyncUI/Views/SyncSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public struct SyncSettingsView: View {
let timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
@State var isSyncWithSetUpSheetVisible = false
@State var isRecoverSyncedDataSheetVisible = false
@State var isEnvironmentSwitcherInstructionsVisible = false

public init(model: SyncSettingsViewModel) {
self.model = model
Expand Down Expand Up @@ -121,6 +122,8 @@ extension SyncSettingsView {
}
Spacer()
}
} header: {
devEnvironmentIndicator()
} footer: {
HStack {
Spacer()
Expand Down Expand Up @@ -265,6 +268,7 @@ extension SyncSettingsView {
.fill(.green)
.frame(width: 8)
.padding(.bottom, 1)
devEnvironmentIndicator()
}
} footer: {
Text(UserText.turnSyncOffSectionFooter)
Expand Down Expand Up @@ -344,6 +348,36 @@ extension SyncSettingsView {
}
}

@ViewBuilder
func devEnvironmentIndicator() -> some View {
if model.isOnDevEnvironment {
Button(action: {
isEnvironmentSwitcherInstructionsVisible.toggle()
}, label: {
if #available(iOS 15.0, *) {
Text("Dev environment")
.daxFootnoteRegular()
.padding(.horizontal, 10)
.padding(.vertical, 2)
.foregroundColor(.white)
.background(Color.red40)
.clipShape(RoundedRectangle(cornerRadius: 10))
} else {
Text("Dev environment")
}
})
.alert(isPresented: $isEnvironmentSwitcherInstructionsVisible) {
Alert(
title: Text("You're using Sync Development environment"),
primaryButton: .default(Text("Keep Development")),
secondaryButton: .destructive(Text("Switch to Production"), action: model.switchToProdEnvironment)
)
}
} else {
EmptyView()
}
}

enum LimitedItemType {
case bookmarks
case credentials
Expand Down
Loading