From 78e9ab0e443c887e27d06b5f2c4392014d4d13e1 Mon Sep 17 00:00:00 2001 From: Anton Kharchevskyi Date: Wed, 22 Dec 2021 12:08:57 +0200 Subject: [PATCH 1/2] Fix for imap session --- .../SetupImap/SetupImapViewController.swift | 3 +- .../Mail Provider/Imap/Imap+retry.swift | 4 +-- .../Mail Provider/Imap/Imap+session.swift | 28 ++++++++----------- .../Mail Provider/Imap/Imap.swift | 10 +++++-- FlowCryptUI/Nodes/TextFieldNode.swift | 8 ++++++ 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/FlowCrypt/Controllers/SetupImap/SetupImapViewController.swift b/FlowCrypt/Controllers/SetupImap/SetupImapViewController.swift index 7ec1de89c..68c2dbaed 100644 --- a/FlowCrypt/Controllers/SetupImap/SetupImapViewController.swift +++ b/FlowCrypt/Controllers/SetupImap/SetupImapViewController.swift @@ -184,7 +184,7 @@ extension SetupImapViewController { state = newState node.reloadSections( - IndexSet(arrayLiteral: 3), + IndexSet(integer: 3), with: .fade ) @@ -253,6 +253,7 @@ extension SetupImapViewController { } .then { $0.textField.attributedText = self.decorator.stringFor(user: self.user, for: section) + $0.textField.autocapitalizationType = .none self.setPicker(for: section, and: $0) } } diff --git a/FlowCrypt/Functionality/Mail Provider/Imap/Imap+retry.swift b/FlowCrypt/Functionality/Mail Provider/Imap/Imap+retry.swift index 75f5c8274..ab609c446 100644 --- a/FlowCrypt/Functionality/Mail Provider/Imap/Imap+retry.swift +++ b/FlowCrypt/Functionality/Mail Provider/Imap/Imap+retry.swift @@ -111,8 +111,8 @@ extension Imap { case .connection: // the connection has dropped, so it's probably ok to not officially "close" it. // but maybe there could be a cleaner way to dispose of the connection? - imapSess = nil - smtpSess = nil + // imapSess = nil + // smtpSess = nil // this is a mess, neads a real refactor. use DI // todo - for now renewing of session disabled, will probably break retries // setupSession() diff --git a/FlowCrypt/Functionality/Mail Provider/Imap/Imap+session.swift b/FlowCrypt/Functionality/Mail Provider/Imap/Imap+session.swift index aaaa726d6..b2f75598c 100644 --- a/FlowCrypt/Functionality/Mail Provider/Imap/Imap+session.swift +++ b/FlowCrypt/Functionality/Mail Provider/Imap/Imap+session.swift @@ -13,22 +13,18 @@ import MailCore extension Imap { func setupSession() { - guard - let imapSession = imapSessionProvider.imapSession(), - let smtpSession = imapSessionProvider.smtpSession() - else { return } - logger.logInfo("Creating a new IMAP session") - let newImapSession = MCOIMAPSession(session: imapSession) - imapSess = newImapSession.log() - logger.logInfo("Creating a new SMTP session") - let newSmtpSession = MCOSMTPSession(session: smtpSession) - smtpSess = newSmtpSession.log() + guard let imapSession = imapSess, let smtpSession = smtpSess else { + logger.logError("No IMAP session") + return + } + imapSession.startLogging() + smtpSession.startLogging() } func connectSmtp(session: SMTPSession) async throws { return try await withCheckedThrowingContinuation { continuation in MCOSMTPSession(session: session) - .log() + .startLogging() .loginOperation()? .start { error in if let error = error { @@ -43,7 +39,7 @@ extension Imap { func connectImap(session: IMAPSession) async throws { return try await withCheckedThrowingContinuation { continuation in MCOIMAPSession(session: session) - .log() + .startLogging() .connectOperation()? .start { error in if let error = error { @@ -64,13 +60,12 @@ extension Imap { self?.logger.logInfo("disconnect with duration \(start.finish())") } } - imapSess = nil - smtpSess = nil // smtp session has no disconnect method } } extension MCOIMAPSession { - func log() -> Self { + @discardableResult + func startLogging() -> Self { connectionLogger = { _, type, data in guard let data = data, let string = String(data: data, encoding: .utf8) else { return } Logger.nested("IMAP").logInfo("\(type):\(string)") @@ -80,7 +75,8 @@ extension MCOIMAPSession { } extension MCOSMTPSession { - func log() -> Self { + @discardableResult + func startLogging() -> Self { connectionLogger = { _, type, data in guard let data = data, let string = String(data: data, encoding: .utf8) else { return } Logger.nested("SMTP").logInfo("\(type):\(string)") diff --git a/FlowCrypt/Functionality/Mail Provider/Imap/Imap.swift b/FlowCrypt/Functionality/Mail Provider/Imap/Imap.swift index a1164250d..7a9e6bc6b 100644 --- a/FlowCrypt/Functionality/Mail Provider/Imap/Imap.swift +++ b/FlowCrypt/Functionality/Mail Provider/Imap/Imap.swift @@ -12,8 +12,14 @@ final class Imap: MailServiceProvider { let user: User let helper: ImapHelperType let messageKindProvider: MessageKindProviderType - var imapSess: MCOIMAPSession? - var smtpSess: MCOSMTPSession? + var imapSess: MCOIMAPSession? { + imapSessionProvider.imapSession() + .map(MCOIMAPSession.init) + } + var smtpSess: MCOSMTPSession? { + imapSessionProvider.smtpSession() + .map(MCOSMTPSession.init) + } typealias ImapIndexSet = MCOIndexSet typealias ReqKind = MCOIMAPMessagesRequestKind diff --git a/FlowCryptUI/Nodes/TextFieldNode.swift b/FlowCryptUI/Nodes/TextFieldNode.swift index 5c56d6e33..121f36635 100644 --- a/FlowCryptUI/Nodes/TextFieldNode.swift +++ b/FlowCryptUI/Nodes/TextFieldNode.swift @@ -111,6 +111,14 @@ public final class TextFieldNode: ASDisplayNode { } } } + + public var autocapitalizationType: UITextAutocapitalizationType = .sentences { + didSet { + DispatchQueue.main.async { + self.textField.autocapitalizationType = self.autocapitalizationType + } + } + } var shouldReturn: ShouldReturnAction? From bc0fc759038dddc1891563626cb8c59222a9c63c Mon Sep 17 00:00:00 2001 From: Anton Kharchevskyi Date: Thu, 23 Dec 2021 13:23:48 +0200 Subject: [PATCH 2/2] Clarify appium docs --- appium/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/appium/README.md b/appium/README.md index c9a5f5f06..504409259 100644 --- a/appium/README.md +++ b/appium/README.md @@ -12,11 +12,13 @@ 8. use Visual Studio Code IDE for editting appium tests - be sure to open it using `File` -> `Open Workspace from File` -> `Core/flowcrypt-mobile-core.code-workspace` (don't simply open the project as a folder, because advanced IDE functionality will be missing) ## Building app for testing -1. Manually compile build from the current code: +#### Option 1 - run `bundle exec fastlane build` in `flowcrypt-ios` folder -- it will produce `appium/FlowCrypt.app` for testing -2. Use the latest simulator build: -- copy `FlowCrypt.app` from `/DerivedData/FlowCrypt-.../Build/Products/Debug-iphonesimulator` (In Xcode open Products folder -> FlowCrypt -> Show in Finder). +- this will build `FlowCrypt.app` app and move it to `appium` folder. + +#### Option 2 +- build app with Xcode +- copy `FlowCrypt.app` from `/DerivedData/FlowCrypt-.../Build/Products/Debug-iphonesimulator` *(In Xcode open Products folder -> FlowCrypt -> Show in Finder)*. ## Run tests