-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* issue 1111 only initialize Realm and KeyChainService once * wip * wip * wip * [skip ci] fixed controllers * [skip ci] more fixes * [skip ci] a few more * [skip ci] fix services * mail provider fixes [skip ci] * a few more fixes [skip ci] * a few more fixes [skip ci] * it builds * add to test scope * [skip ci] remove AppReset, fix some test usages * Project file fixed * removed unwanted files from test target * intermediate * fix * PR fixes * PR fixes II * less verbose backup service init * cleanup * controller cleanup * fix * cleanup * issue #1111 fix unit tests running * issue #1131 use in-memory Realm for tests * issue #1111 fix tests Co-authored-by: Ivan <[email protected]> Co-authored-by: Roma Sosnovsky <[email protected]>
- Loading branch information
1 parent
5580caf
commit 4162138
Showing
88 changed files
with
967 additions
and
815 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// | ||
// AppContext.swift | ||
// FlowCrypt | ||
// | ||
// Created by Tom on 30.11.2021 | ||
// Copyright © 2017-present FlowCrypt a. s. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
class AppContext { | ||
|
||
let globalRouter: GlobalRouterType | ||
let encryptedStorage: EncryptedStorageType | ||
let session: SessionType? | ||
// todo - session service should have maybe `.currentSession` on it, then we don't have to have `session` above? | ||
let userAccountService: SessionServiceType | ||
let dataService: DataServiceType | ||
let keyStorage: KeyStorageType | ||
let keyService: KeyServiceType | ||
let passPhraseService: PassPhraseServiceType | ||
let clientConfigurationService: ClientConfigurationServiceType | ||
|
||
private init( | ||
encryptedStorage: EncryptedStorageType, | ||
session: SessionType?, | ||
userAccountService: SessionServiceType, | ||
dataService: DataServiceType, | ||
keyStorage: KeyStorageType, | ||
keyService: KeyServiceType, | ||
passPhraseService: PassPhraseServiceType, | ||
clientConfigurationService: ClientConfigurationServiceType, | ||
globalRouter: GlobalRouterType | ||
) { | ||
self.encryptedStorage = encryptedStorage | ||
self.session = session | ||
self.userAccountService = userAccountService | ||
self.dataService = dataService | ||
self.keyStorage = keyStorage // todo - keyStorage and keyService should be the same | ||
self.keyService = keyService | ||
self.passPhraseService = passPhraseService | ||
self.clientConfigurationService = clientConfigurationService | ||
self.globalRouter = globalRouter | ||
} | ||
|
||
@MainActor | ||
static func setUpAppContext(globalRouter: GlobalRouterType) throws -> AppContext { | ||
let keyChainService = KeyChainService() | ||
let encryptedStorage = EncryptedStorage( | ||
storageEncryptionKey: try keyChainService.getStorageEncryptionKey() | ||
) | ||
let dataService = DataService(encryptedStorage: encryptedStorage) | ||
let passPhraseService = PassPhraseService(encryptedStorage: encryptedStorage) | ||
let keyStorage = KeyDataStorage(encryptedStorage: encryptedStorage) | ||
let keyService = KeyService( | ||
storage: keyStorage, | ||
passPhraseService: passPhraseService, | ||
currentUserEmail: { dataService.email } | ||
) | ||
let clientConfigurationService = ClientConfigurationService( | ||
local: LocalClientConfiguration( | ||
encryptedStorage: encryptedStorage | ||
) | ||
) | ||
return AppContext( | ||
encryptedStorage: encryptedStorage, | ||
session: nil, // will be set later. But would be nice to already set here, if available | ||
userAccountService: SessionService( | ||
encryptedStorage: encryptedStorage, | ||
dataService: dataService, | ||
googleService: GoogleUserService( | ||
currentUserEmail: dataService.currentUser?.email, | ||
appDelegateGoogleSessionContainer: UIApplication.shared.delegate as? AppDelegate | ||
) | ||
), | ||
dataService: dataService, | ||
keyStorage: keyStorage, | ||
keyService: keyService, | ||
passPhraseService: passPhraseService, | ||
clientConfigurationService: clientConfigurationService, | ||
globalRouter: globalRouter | ||
) | ||
} | ||
|
||
func withSession(_ session: SessionType?) -> AppContext { | ||
return AppContext( | ||
encryptedStorage: self.encryptedStorage, | ||
session: session, | ||
userAccountService: self.userAccountService, | ||
dataService: self.dataService, | ||
keyStorage: self.keyStorage, | ||
keyService: self.keyService, | ||
passPhraseService: self.passPhraseService, | ||
clientConfigurationService: self.clientConfigurationService, | ||
globalRouter: globalRouter | ||
) | ||
} | ||
|
||
func getRequiredMailProvider() -> MailProvider { | ||
guard let mailProvider = getOptionalMailProvider() else { | ||
// todo - should throw instead | ||
fatalError("wrongly using mail provider when not logged in") | ||
} | ||
return mailProvider | ||
} | ||
|
||
func getOptionalMailProvider() -> MailProvider? { | ||
guard let currentUser = self.dataService.currentUser, let currentAuthType = self.dataService.currentAuthType else { | ||
return nil | ||
} | ||
return MailProvider( | ||
currentAuthType: currentAuthType, | ||
currentUser: currentUser | ||
) | ||
} | ||
|
||
func getBackupService() -> BackupService { | ||
let mailProvider = self.getRequiredMailProvider() | ||
return BackupService( | ||
backupProvider: mailProvider.backupProvider, | ||
messageSender: mailProvider.messageSender | ||
) | ||
} | ||
|
||
func getFoldersService() -> FoldersService { | ||
return FoldersService( | ||
encryptedStorage: self.encryptedStorage, | ||
remoteFoldersProvider: self.getRequiredMailProvider().remoteFoldersProvider | ||
) | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.