|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import SessionUIKit
|
|
|
|
|
import SessionUtilitiesKit
|
|
|
|
|
|
|
|
|
|
public class HostWrapper: ObservableObject {
|
|
|
|
|
public weak var controller: UIViewController?
|
|
|
|
@ -120,6 +121,107 @@ public class SessionHostingViewController<Content>: UIHostingController<Modified
|
|
|
|
|
navigationItem.titleView = logoImageView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal func setUpClearDataBackButton(flow: Onboarding.Flow) {
|
|
|
|
|
if #available(iOS 16.0, *) {
|
|
|
|
|
navigationItem.backAction = UIAction() { [weak self] action in
|
|
|
|
|
switch flow {
|
|
|
|
|
case .register:
|
|
|
|
|
self?.clearDataForAccountCreation()
|
|
|
|
|
case .recover:
|
|
|
|
|
self?.clearDataForLoadAccount()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let action: Selector = {
|
|
|
|
|
switch flow {
|
|
|
|
|
case .register:
|
|
|
|
|
return #selector(clearDataForAccountCreation)
|
|
|
|
|
case .recover:
|
|
|
|
|
return #selector(clearDataForLoadAccount)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
let clearDataBackButton = UIBarButtonItem(
|
|
|
|
|
image: UIImage(
|
|
|
|
|
systemName: "chevron.backward",
|
|
|
|
|
withConfiguration: UIImage.SymbolConfiguration(textStyle: .headline, scale: .large)
|
|
|
|
|
),
|
|
|
|
|
style: .plain,
|
|
|
|
|
target: self,
|
|
|
|
|
action: action
|
|
|
|
|
)
|
|
|
|
|
clearDataBackButton.imageInsets = .init(top: 0, leading: -8, bottom: 0, trailing: 8)
|
|
|
|
|
clearDataBackButton.themeTintColor = .textPrimary
|
|
|
|
|
navigationItem.leftBarButtonItem = clearDataBackButton
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc private func clearDataForAccountCreation() {
|
|
|
|
|
let modal: ConfirmationModal = ConfirmationModal(
|
|
|
|
|
targetView: self.view,
|
|
|
|
|
info: ConfirmationModal.Info(
|
|
|
|
|
title: "warning".localized(),
|
|
|
|
|
body: .text("onboardingBackAccountCreation".localized()),
|
|
|
|
|
confirmTitle: "quitButton".localized(),
|
|
|
|
|
confirmStyle: .danger,
|
|
|
|
|
cancelStyle: .textPrimary,
|
|
|
|
|
onConfirm: { [weak self] confirmationModal in
|
|
|
|
|
self?.deleteAllLocalData()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
self.present(modal, animated: true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc private func clearDataForLoadAccount() {
|
|
|
|
|
let modal: ConfirmationModal = ConfirmationModal(
|
|
|
|
|
targetView: self.view,
|
|
|
|
|
info: ConfirmationModal.Info(
|
|
|
|
|
title: "warning".localized(),
|
|
|
|
|
body: .text("onboardingBackLoadAccount".localized()),
|
|
|
|
|
confirmTitle: "quitButton".localized(),
|
|
|
|
|
confirmStyle: .danger,
|
|
|
|
|
cancelStyle: .textPrimary,
|
|
|
|
|
onConfirm: { [weak self] confirmationModal in
|
|
|
|
|
self?.deleteAllLocalData()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
self.present(modal, animated: true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func deleteAllLocalData(using dependencies: Dependencies = Dependencies()) {
|
|
|
|
|
/// Stop and cancel all current jobs (don't want to inadvertantly have a job store data after it's table has already been cleared)
|
|
|
|
|
///
|
|
|
|
|
/// **Note:** This is file as long as this process kills the app, if it doesn't then we need an alternate mechanism to flag that
|
|
|
|
|
/// the `JobRunner` is allowed to start it's queues again
|
|
|
|
|
JobRunner.stopAndClearPendingJobs(using: dependencies)
|
|
|
|
|
|
|
|
|
|
// Clear the app badge and notifications
|
|
|
|
|
AppEnvironment.shared.notificationPresenter.clearAllNotifications()
|
|
|
|
|
UIApplication.shared.applicationIconBadgeNumber = 0
|
|
|
|
|
|
|
|
|
|
// Clear out the user defaults
|
|
|
|
|
UserDefaults.removeAll()
|
|
|
|
|
|
|
|
|
|
// Remove the cached key so it gets re-cached on next access
|
|
|
|
|
dependencies.caches.mutate(cache: .general) {
|
|
|
|
|
$0.encodedPublicKey = nil
|
|
|
|
|
$0.recentReactionTimestamps = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stop any pollers
|
|
|
|
|
(UIApplication.shared.delegate as? AppDelegate)?.stopPollers()
|
|
|
|
|
|
|
|
|
|
// Call through to the SessionApp's "resetAppData" which will wipe out logs, database and
|
|
|
|
|
// profile storage
|
|
|
|
|
let wasUnlinked: Bool = UserDefaults.standard[.wasUnlinked]
|
|
|
|
|
|
|
|
|
|
SessionApp.resetAppData {
|
|
|
|
|
// Resetting the data clears the old user defaults. We need to restore the unlink default.
|
|
|
|
|
UserDefaults.standard[.wasUnlinked] = wasUnlinked
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal func setUpDismissingButton(on postion: NavigationItemPosition) {
|
|
|
|
|
let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close))
|
|
|
|
|
closeButton.themeTintColor = .textPrimary
|
|
|
|
|