-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue 1111 only initialize Realm and KeyChainService once #1117
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
cf00351
issue 1111 only initialize Realm and KeyChainService once
tomholub 35f2086
wip
tomholub 0e2a495
wip
tomholub aca0f96
wip
tomholub f2d01f8
[skip ci] fixed controllers
tomholub 353ff23
[skip ci] more fixes
tomholub 7302dbd
[skip ci] a few more
tomholub bd91385
[skip ci] fix services
tomholub f62f156
mail provider fixes [skip ci]
tomholub 70509db
a few more fixes [skip ci]
tomholub 7e5accd
a few more fixes [skip ci]
tomholub bbf37a9
it builds
tomholub 08941db
add to test scope
tomholub 143f9b7
Merge branch 'master' into issue-1111-realm-keychain-init
tomholub 40738e5
[skip ci] remove AppReset, fix some test usages
tomholub 2f8df6d
Project file fixed
ivan-ushakov 418572d
removed unwanted files from test target
tomholub a87d35a
Merge branch 'issue-1111-realm-keychain-init' of github.com:FlowCrypt…
tomholub bd556c0
intermediate
tomholub dc66c8c
fix
tomholub 120af70
PR fixes
tomholub aae17fb
PR fixes II
tomholub e786059
less verbose backup service init
tomholub 5767e3a
cleanup
tomholub 90bfac3
controller cleanup
tomholub 2458d9b
fix
tomholub 8eda81f
cleanup
tomholub 5947f39
issue #1111 fix unit tests running
sosnovsky 050d226
issue #1131 use in-memory Realm for tests
sosnovsky 359030b
issue #1111 fix tests
sosnovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we could skip
autoreleasepool
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure either - the IDE was telling me that it's no longer needed. @sosnovsky may know
This comment was marked as resolved.
Sorry, something went wrong.