From a0970db6fa3a8539906ac71fb86264ea0bcf9694 Mon Sep 17 00:00:00 2001 From: Nora Trapp Date: Mon, 26 Sep 2022 07:19:56 -0700 Subject: [PATCH] Allow configuring proxy in onboarding --- .../ProxySettingsViewController.swift | 25 ++++++++++++++++++- .../OnboardingPhoneNumberViewController.swift | 22 ++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/AppSettings/Data Usage/ProxySettingsViewController.swift b/Signal/src/ViewControllers/AppSettings/Data Usage/ProxySettingsViewController.swift index a1c0586485..eb492f124f 100644 --- a/Signal/src/ViewControllers/AppSettings/Data Usage/ProxySettingsViewController.swift +++ b/Signal/src/ViewControllers/AppSettings/Data Usage/ProxySettingsViewController.swift @@ -21,6 +21,14 @@ class ProxySettingsViewController: OWSTableViewController2, OWSNavigationView { } private func updateNavigationBar() { + if navigationController?.viewControllers.count == 1 { + navigationItem.leftBarButtonItem = .init( + barButtonSystemItem: .cancel, + target: self, + action: #selector(didTapCancel) + ) + } + navigationItem.rightBarButtonItem = UIBarButtonItem( barButtonSystemItem: .save, target: self, @@ -113,7 +121,22 @@ class ProxySettingsViewController: OWSTableViewController2, OWSNavigationView { databaseStorage.write { transaction in SignalProxy.setProxyHost(host: self.hostTextField.text, useProxy: self.useProxy, transaction: transaction) } - navigationController?.popViewController(animated: true) + if navigationController?.viewControllers.count == 1 { + dismiss(animated: true) + } else { + navigationController?.popViewController(animated: true) + } + } + + @objc + private func didTapCancel() { + if hasPendingChanges { + OWSActionSheets.showPendingChangesActionSheet { [weak self] in + self?.dismiss(animated: true) + } + } else { + dismiss(animated: true) + } } func shouldCancelNavigationBack() -> Bool { diff --git a/Signal/src/ViewControllers/Registration/Onboarding/OnboardingPhoneNumberViewController.swift b/Signal/src/ViewControllers/Registration/Onboarding/OnboardingPhoneNumberViewController.swift index 79dfbb19b9..d0b9e4caf6 100644 --- a/Signal/src/ViewControllers/Registration/Onboarding/OnboardingPhoneNumberViewController.swift +++ b/Signal/src/ViewControllers/Registration/Onboarding/OnboardingPhoneNumberViewController.swift @@ -147,6 +147,28 @@ public class RegistrationPhoneNumberViewController: OnboardingBaseViewController view.addSubview(primaryView) primaryView.autoPinEdgesToSuperviewEdges() + let proxyButton = ContextMenuButton(contextMenu: .init([ + .init( + title: NSLocalizedString( + "USE_PROXY_BUTTON", + comment: "Button to activate the signal proxy" + ), + handler: { [weak self] _ in + guard let self = self else { return } + let vc = ProxySettingsViewController() + self.presentFormSheet(OWSNavigationController(rootViewController: vc), animated: true) + } + ) + ])) + proxyButton.showsContextMenuAsPrimaryAction = true + proxyButton.setImage(Theme.iconImage(.more24), for: .normal) + proxyButton.tintColor = Theme.primaryIconColor + proxyButton.autoSetDimensions(to: .square(40)) + + view.addSubview(proxyButton) + proxyButton.autoPinEdge(toSuperviewMargin: .trailing) + proxyButton.autoPinEdge(toSuperviewMargin: .top) + // Setup subviews and stack views let titleString = (Self.tsAccountManager.isReregistering ? NSLocalizedString(