Files
Morgan Pretty 5863beb352 Updated code to use libSession for storing app settings
• Moved settings into libSession
• Added new observation mechanism for libSession changes (driven via async/await)
• Updated settings screen to update based on observing changes to libSession data
• Updated home screen "State" to update based on observing libSession changes
• Removed a number of database functions for data which is entirely retrievable via libSession
2025-06-11 09:43:44 +10:00

138 lines
4.3 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import UIKit
import SessionUIKit
import SessionUtilitiesKit
final class SeedModal: Modal {
private let dependencies: Dependencies
private let mnemonic: String
// MARK: - Initialization
init(using dependencies: Dependencies) throws {
self.dependencies = dependencies
self.mnemonic = try Identity.mnemonic(using: dependencies)
super.init(targetView: nil, dismissType: .recursive, afterClosed: nil)
self.modalPresentationStyle = .overFullScreen
self.modalTransitionStyle = .crossDissolve
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Components
private let titleLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .boldSystemFont(ofSize: Values.mediumFontSize)
result.text = "sessionRecoveryPassword".localized()
result.themeTextColor = .textPrimary
result.textAlignment = .center
result.lineBreakMode = .byWordWrapping
result.numberOfLines = 0
return result
}()
private let explanationLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize)
result.text = "recoveryPasswordDescription".localized()
result.themeTextColor = .textPrimary
result.textAlignment = .center
result.lineBreakMode = .byWordWrapping
result.numberOfLines = 0
return result
}()
private lazy var mnemonicLabelContainer: UIView = {
let result: UIView = UIView()
result.themeBorderColor = .textPrimary
result.layer.cornerRadius = SNTextField.cornerRadius
result.layer.borderWidth = 1
return result
}()
private lazy var mnemonicLabel: UILabel = {
let result: UILabel = UILabel()
result.font = Fonts.spaceMono(ofSize: Values.smallFontSize)
result.text = mnemonic
result.themeTextColor = .textPrimary
result.textAlignment = .center
result.lineBreakMode = .byWordWrapping
result.numberOfLines = 0
return result
}()
private lazy var copyButton: UIButton = {
let result: UIButton = Modal.createButton(
title: "copy".localized(),
titleColor: .textPrimary
)
result.addTarget(self, action: #selector(copySeed), for: .touchUpInside)
return result
}()
private lazy var buttonStackView: UIStackView = {
let result = UIStackView(arrangedSubviews: [ copyButton, cancelButton ])
result.axis = .horizontal
result.spacing = Values.mediumSpacing
result.distribution = .fillEqually
return result
}()
private lazy var contentStackView: UIStackView = {
let result = UIStackView(arrangedSubviews: [ titleLabel, explanationLabel, mnemonicLabelContainer ])
result.axis = .vertical
result.spacing = Values.smallSpacing
result.isLayoutMarginsRelativeArrangement = true
result.layoutMargins = UIEdgeInsets(
top: Values.largeSpacing,
leading: Values.largeSpacing,
bottom: Values.verySmallSpacing,
trailing: Values.largeSpacing
)
return result
}()
private lazy var mainStackView: UIStackView = {
let result = UIStackView(arrangedSubviews: [ contentStackView, buttonStackView ])
result.axis = .vertical
result.spacing = Values.largeSpacing - Values.smallFontSize / 2
return result
}()
// MARK: - Lifecycle
override func populateContentView() {
contentView.addSubview(mainStackView)
mainStackView.pin(to: contentView)
mnemonicLabelContainer.addSubview(mnemonicLabel)
mnemonicLabel.pin(to: mnemonicLabelContainer, withInset: isIPhone6OrSmaller ? 4 : Values.smallSpacing)
// Mark seed as viewed
dependencies.setAsync(.hasViewedSeed, true)
}
// MARK: - Interaction
@objc private func copySeed() {
UIPasteboard.general.string = mnemonic
dismiss(animated: true, completion: nil)
}
}