Signal-iOS/Signal/src/ViewControllers/AppSettings/Account/AdvancedPinSettingsTableViewController.swift
Evan Hahn 370ff654e7
Change license to AGPL
Change license to AGPL

This commit:

- Updates the `LICENSE` file

- Start every file with something like:

      // Copyright YEAR_FIRST_PUBLISHED Signal Messenger, LLC
      // SPDX-License-Identifier: AGPL-3.0-only

---

First, I removed existing license headers with this Ruby 3.1.2 script:

    require 'set'

    EXTENSIONS_TO_CHECK = Set['.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift']

    same = 0
    different = 0

    all_files = `git ls-files`.lines.map { |line| line.strip }
    all_files.each do |relative_path|
      if relative_path == 'Pods'
        next
      end

      unless EXTENSIONS_TO_CHECK.include? File.extname(relative_path)
        next
      end

      path = File.expand_path(relative_path)

      contents = File.read(path)
      new_contents = contents.sub(/\/\/\n\/\/  Copyright .*\n\/\/\n\n/, '')

      if contents == new_contents
        same += 1
      else
        different += 1
      end

      File.write(path, new_contents)
    end

    puts "updated #{different} file(s), left #{same} untouched"

I'm sure this script could be improved, but it worked well enough.

Then, I created `Scripts/lint/lint-license-headers` and ran it to auto-
fix a lot of files. This changed the mode of some files, but I think
that's actually desirable. For example,
`SignalServiceKit/src/Util/AppContext.m` previously had a mode of
`0755/-rwxr-xr-x`, and it's now `0644/-rw-r--r--`.

Then I fixed some stragglers and updated the precommit script.

See [a similar change in the Desktop app][0].

[0]: 8bfaf598af
2022-10-13 08:25:37 -05:00

114 lines
4.8 KiB
Swift

//
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
@objc
class AdvancedPinSettingsTableViewController: OWSTableViewController2 {
override func viewDidLoad() {
super.viewDidLoad()
title = NSLocalizedString("SETTINGS_ADVANCED_PIN_TITLE", comment: "The title for the advanced pin settings.")
updateTableContents()
}
func updateTableContents() {
let contents = OWSTableContents()
let pinsSection = OWSTableSection()
pinsSection.add(OWSTableItem.actionItem(
withText: (KeyBackupService.hasMasterKey && !KeyBackupService.hasBackedUpMasterKey)
? NSLocalizedString("SETTINGS_ADVANCED_PINS_ENABLE_PIN_ACTION",
comment: "")
: NSLocalizedString("SETTINGS_ADVANCED_PINS_DISABLE_PIN_ACTION",
comment: ""),
textColor: Theme.accentBlueColor,
accessibilityIdentifier: "advancedPinSettings.disable",
actionBlock: { [weak self] in
self?.enableOrDisablePin()
}))
contents.addSection(pinsSection)
self.contents = contents
}
private func enableOrDisablePin() {
if KeyBackupService.hasMasterKey && !KeyBackupService.hasBackedUpMasterKey {
enablePin()
} else {
if self.paymentsHelper.arePaymentsEnabled,
!PaymentsSettingsViewController.hasReviewedPassphraseWithSneakyTransaction() {
showReviewPassphraseAlertUI()
} else {
disablePin()
}
}
}
private func enablePin() {
let vc = PinSetupViewController.creating { [weak self] _, _ in
guard let self = self else { return }
self.navigationController?.setNavigationBarHidden(false, animated: false)
self.navigationController?.popToViewController(self, animated: true)
self.updateTableContents()
}
navigationController?.pushViewController(vc, animated: true)
}
private func disablePin() {
firstly(on: .main) {
PinSetupViewController.disablePinWithConfirmation(fromViewController: self)
}.done { [weak self] _ in
self?.updateTableContents()
}.catch { error in
owsFailDebug("Error: \(error)")
}
}
private func showReviewPassphraseAlertUI() {
AssertIsOnMainThread()
let actionSheet = ActionSheetController(title: NSLocalizedString("SETTINGS_PAYMENTS_RECORD_PASSPHRASE_DISABLE_PIN_TITLE",
comment: "Title for the 'record payments passphrase to disable pin' UI in the app settings."),
message: NSLocalizedString("SETTINGS_PAYMENTS_RECORD_PASSPHRASE_DISABLE_PIN_DESCRIPTION",
comment: "Description for the 'record payments passphrase to disable pin' UI in the app settings."))
actionSheet.addAction(ActionSheetAction(title: NSLocalizedString("SETTINGS_PAYMENTS_RECORD_PASSPHRASE_DISABLE_PIN_RECORD_PASSPHRASE",
comment: "Label for the 'record recovery passphrase' button in the 'record payments passphrase to disable pin' UI in the app settings."),
accessibilityIdentifier: "payments.settings.disable-pin.record-passphrase",
style: .default) { [weak self] _ in
self?.showRecordPaymentsPassphraseUI()
})
actionSheet.addAction(OWSActionSheets.cancelAction)
presentActionSheet(actionSheet)
}
private func showRecordPaymentsPassphraseUI() {
guard let passphrase = paymentsSwift.passphrase else {
owsFailDebug("Missing passphrase.")
return
}
let view = PaymentsViewPassphraseSplashViewController(passphrase: passphrase,
shouldShowConfirm: true,
viewPassphraseDelegate: self)
let navigationVC = OWSNavigationController(rootViewController: view)
present(navigationVC, animated: true)
}
}
// MARK: -
extension AdvancedPinSettingsTableViewController: PaymentsViewPassphraseDelegate {
public func viewPassphraseDidComplete() {
PaymentsSettingsViewController.setHasReviewedPassphraseWithSneakyTransaction()
presentToast(text: NSLocalizedString("SETTINGS_PAYMENTS_VIEW_PASSPHRASE_COMPLETE_TOAST",
comment: "Message indicating that 'payments passphrase review' is complete."))
}
}