Skip to content
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

fix: resolve strict concurrency errors #3731

Merged
merged 19 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Amplify/Core/Support/DeviceInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import AppKit
/// ```
///
/// - Tag: DeviceInfo
@MainActor
public struct DeviceInfo {

private init() {}
Expand Down
1 change: 1 addition & 0 deletions Amplify/DevMenu/Data/DeviceInfoHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import UIKit

/// Helper class to fetch information for Device Information Screen
@MainActor
struct DeviceInfoHelper {

static func getDeviceInformation() -> [DeviceInfoItem] {
Expand Down
1 change: 1 addition & 0 deletions Amplify/DevMenu/Data/IssueInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

/// Struct consisting of information required to report an issue
@MainActor
struct IssueInfo {

private var includeEnvironmentInfo: Bool
Expand Down
1 change: 1 addition & 0 deletions Amplify/DevMenu/Data/IssueInfoHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

/// Helper class to generate markdown text for issue reporting
@MainActor
struct IssueInfoHelper {

private static let issueDescTitle = "Issue Description"
Expand Down
8 changes: 0 additions & 8 deletions Amplify/DevMenu/Trigger/LongPressGestureRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,5 @@ class LongPressGestureRecognizer: NSObject, TriggerRecognizer, UIGestureRecogniz
uiWindow?.addGestureRecognizer(recognizer)
recognizer.delegate = self
}

deinit {
thisisabhash marked this conversation as resolved.
Show resolved Hide resolved
if let window = uiWindow {
window.removeGestureRecognizer(recognizer)
}
uiWindow = nil
triggerDelegate = nil
}
}
#endif
55 changes: 31 additions & 24 deletions Amplify/DevMenu/View/IssueReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,36 +95,42 @@ struct IssueReporter: View {

/// Open Amplify iOS issue logging screen on Github
private func reportToGithub() {
let issueDescriptionMarkdown =
IssueInfoHelper.generateMarkdownForIssue(
issue: IssueInfo(issueDescription: issueDescription,
includeEnvInfo: includeEnvInfo,
includeDeviceInfo: includeDeviceInfo))

let urlString = amplifyIosNewIssueUrl + issueDescriptionMarkdown
guard let url = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
showAlertIfInvalidURL = true
return
}
guard let urlToOpen = URL(string: url) else {
showAlertIfInvalidURL = true
return
Task {
let issue = await IssueInfo(issueDescription: issueDescription,
includeEnvInfo: includeEnvInfo,
includeDeviceInfo: includeDeviceInfo)
let issueDescriptionMarkdown =
await IssueInfoHelper.generateMarkdownForIssue(
issue: issue)

let urlString = amplifyIosNewIssueUrl + issueDescriptionMarkdown
guard let url = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
showAlertIfInvalidURL = true
return
}
guard let urlToOpen = URL(string: url) else {
showAlertIfInvalidURL = true
return
}

await UIApplication.shared.open(urlToOpen)
}

UIApplication.shared.open(urlToOpen)
}

/// Copy issue as a markdown string to clipboard
private func copyToClipboard() {
let issue = IssueInfo(issueDescription: issueDescription,
includeEnvInfo: includeEnvInfo,
includeDeviceInfo: includeDeviceInfo)
let value = IssueInfoHelper.generateMarkdownForIssue(issue: issue)
#if os(iOS)
UIPasteboard.general.string = value
#elseif canImport(AppKit)
NSPasteboard.general.setString(value, forType: .string)
#endif
Task {
let issue = await IssueInfo(issueDescription: issueDescription,
includeEnvInfo: includeEnvInfo,
includeDeviceInfo: includeDeviceInfo)
let value = await IssueInfoHelper.generateMarkdownForIssue(issue: issue)
#if os(iOS)
UIPasteboard.general.string = value
#elseif canImport(AppKit)
NSPasteboard.general.setString(value, forType: .string)
#endif
}
}
}

Expand Down Expand Up @@ -166,6 +172,7 @@ final class MultilineTextField: UIViewRepresentable {
return view
}

@MainActor
@objc func dismissKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder),
to: nil, from: nil, for: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import Amplify

@MainActor
struct ASFDeviceInfo: ASFDeviceBehavior {

let id: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protocol AdvancedSecurityBehavior {
configuration: UserPoolConfigurationData) throws -> String
}

protocol ASFDeviceBehavior {
protocol ASFDeviceBehavior: Sendable {

var id: String { get }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extension CognitoUserPoolASF {
static func encodedContext(username: String,
asfDeviceId: String,
asfClient: AdvancedSecurityBehavior,
userPoolConfiguration: UserPoolConfigurationData) -> String? {
let deviceInfo: ASFDeviceBehavior = ASFDeviceInfo(id: asfDeviceId)
userPoolConfiguration: UserPoolConfigurationData) async -> String? {
let deviceInfo: ASFDeviceBehavior = await ASFDeviceInfo(id: asfDeviceId)
let appInfo: ASFAppInfoBehavior = ASFAppInfo()

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct RefreshUserPoolTokens: Action {
for: existingSignedIndata.username,
credentialStoreClient: authEnv.credentialsClient)

let input = InitiateAuthInput.refreshAuthInput(
let input = await InitiateAuthInput.refreshAuthInput(
thisisabhash marked this conversation as resolved.
Show resolved Hide resolved
username: existingSignedIndata.username,
refreshToken: existingTokens.refreshToken,
clientMetadata: [:],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct ConfirmDevice: Action {
deviceKey: deviceMetadata.deviceKey,
password: deviceMetadata.deviceSecret)

let deviceName = DeviceInfo.current.name
let deviceName = await DeviceInfo.current.name

let base64EncodedVerifier = passwordVerifier.passwordVerifier.base64EncodedString()
let base64EncodedSalt = passwordVerifier.salt.base64EncodedString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct InitiateCustomAuth: Action {
let asfDeviceId = try await CognitoUserPoolASF.asfDeviceID(
for: username,
credentialStoreClient: authEnv.credentialsClient)
let request = InitiateAuthInput.customAuth(
let request = await InitiateAuthInput.customAuth(
username: username,
clientMetadata: clientMetadata,
asfDeviceId: asfDeviceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct InitiateAuthDeviceSRP: Action {
srpKeyPair: srpKeyPair,
clientTimestamp: Date())

let request = RespondToAuthChallengeInput.deviceSRP(
let request = await RespondToAuthChallengeInput.deviceSRP(
username: username,
environment: userPoolEnv,
deviceMetadata: deviceMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct VerifyDevicePasswordSRP: Action {
serverPublicBHexString: serverPublicB,
srpClient: srpClient)

let request = RespondToAuthChallengeInput.devicePasswordVerifier(
let request = await RespondToAuthChallengeInput.devicePasswordVerifier(
username: username,
stateData: stateData,
session: authResponse.session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct InitializeHostedUISignIn: Action {
let asfDeviceId = try await CognitoUserPoolASF.asfDeviceID(
for: username,
credentialStoreClient: environment.credentialsClient)
let encodedData = CognitoUserPoolASF.encodedContext(
let encodedData = await CognitoUserPoolASF.encodedContext(
username: username,
asfDeviceId: asfDeviceId,
asfClient: environment.cognitoUserPoolASFFactory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct InitiateMigrateAuth: Action {
let asfDeviceId = try await CognitoUserPoolASF.asfDeviceID(
for: username,
credentialStoreClient: authEnv.credentialsClient)
let request = InitiateAuthInput.migrateAuth(
let request = await InitiateAuthInput.migrateAuth(
username: username,
password: password,
clientMetadata: clientMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct InitiateAuthSRP: Action {
for: username,
credentialStoreClient: authEnv.credentialsClient)

let request = InitiateAuthInput.srpInput(
let request = await InitiateAuthInput.srpInput(
username: username,
publicSRPAHexValue: srpKeyPair.publicKeyHexValue,
authFlowType: authFlowType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct VerifyPasswordSRP: Action {
serverPublicBHexString: serverPublicB,
srpClient: srpClient,
poolId: userPoolEnv.userPoolConfiguration.poolId)
let request = RespondToAuthChallengeInput.passwordVerifier(
let request = await RespondToAuthChallengeInput.passwordVerifier(
username: username,
stateData: stateData,
session: authResponse.session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct CompleteTOTPSetup: Action {
credentialStoreClient: authEnv.credentialsClient)

var userContextData: CognitoIdentityProviderClientTypes.UserContextDataType?
if let encodedData = CognitoUserPoolASF.encodedContext(
if let encodedData = await CognitoUserPoolASF.encodedContext(
username: username,
asfDeviceId: asfDeviceId,
asfClient: userpoolEnv.cognitoUserPoolASFFactory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct VerifySignInChallenge: Action {
for: username,
with: environment)

let input = RespondToAuthChallengeInput.verifyChallenge(
let input = await RespondToAuthChallengeInput.verifyChallenge(
username: username,
challengeType: challengeType,
session: session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
#if os(iOS) || os(macOS)
extension HostedUIASWebAuthenticationSession: ASWebAuthenticationPresentationContextProviding {

@MainActor
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return webPresentation ?? ASPresentationAnchor()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ extension ConfirmSignUpInput {
asfDeviceId: String?,
forceAliasCreation: Bool?,
environment: UserPoolEnvironment
) {
) async {

let configuration = environment.userPoolConfiguration
let secretHash = ClientSecretHelper.calculateSecretHash(
username: username,
userPoolConfiguration: configuration)
var userContextData: CognitoIdentityProviderClientTypes.UserContextDataType?
if let asfDeviceId = asfDeviceId,
let encodedData = CognitoUserPoolASF.encodedContext(
let encodedData = await CognitoUserPoolASF.encodedContext(
username: username,
asfDeviceId: asfDeviceId,
asfClient: environment.cognitoUserPoolASFFactory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension InitiateAuthInput {
clientMetadata: [String: String],
asfDeviceId: String,
deviceMetadata: DeviceMetadata,
environment: UserPoolEnvironment) -> InitiateAuthInput {
environment: UserPoolEnvironment) async -> InitiateAuthInput {
var authParameters = [
"USERNAME": username,
"SRP_A": publicSRPAHexValue
Expand All @@ -28,7 +28,7 @@ extension InitiateAuthInput {
authParameters["CHALLENGE_NAME"] = "SRP_A"
}

return buildInput(username: username,
return await buildInput(username: username,
authFlowType: authFlowType.getClientFlowType(),
authParameters: authParameters,
clientMetadata: clientMetadata,
Expand All @@ -41,12 +41,12 @@ extension InitiateAuthInput {
clientMetadata: [String: String],
asfDeviceId: String,
deviceMetadata: DeviceMetadata,
environment: UserPoolEnvironment) -> InitiateAuthInput {
environment: UserPoolEnvironment) async -> InitiateAuthInput {
let authParameters = [
"USERNAME": username
]

return buildInput(username: username,
return await buildInput(username: username,
authFlowType: .customAuth,
authParameters: authParameters,
clientMetadata: clientMetadata,
Expand All @@ -60,13 +60,13 @@ extension InitiateAuthInput {
clientMetadata: [String: String],
asfDeviceId: String,
deviceMetadata: DeviceMetadata,
environment: UserPoolEnvironment) -> InitiateAuthInput {
environment: UserPoolEnvironment) async -> InitiateAuthInput {
let authParameters = [
"USERNAME": username,
"PASSWORD": password
]

return buildInput(username: username,
return await buildInput(username: username,
authFlowType: .userPasswordAuth,
authParameters: authParameters,
clientMetadata: clientMetadata,
Expand All @@ -80,13 +80,13 @@ extension InitiateAuthInput {
clientMetadata: [String: String],
asfDeviceId: String,
deviceMetadata: DeviceMetadata,
environment: UserPoolEnvironment) -> InitiateAuthInput {
environment: UserPoolEnvironment) async -> InitiateAuthInput {

let authParameters = [
"REFRESH_TOKEN": refreshToken
]

return buildInput(username: username,
return await buildInput(username: username,
authFlowType: .refreshTokenAuth,
authParameters: authParameters,
clientMetadata: clientMetadata,
Expand All @@ -102,7 +102,7 @@ extension InitiateAuthInput {
clientMetadata: [String: String],
asfDeviceId: String?,
deviceMetadata: DeviceMetadata,
environment: UserPoolEnvironment) -> InitiateAuthInput {
environment: UserPoolEnvironment) async -> InitiateAuthInput {

var authParameters = authParameters
let configuration = environment.userPoolConfiguration
Expand All @@ -123,7 +123,7 @@ extension InitiateAuthInput {

var userContextData: CognitoIdentityProviderClientTypes.UserContextDataType?
if let asfDeviceId = asfDeviceId,
let encodedData = CognitoUserPoolASF.encodedContext(
let encodedData = await CognitoUserPoolASF.encodedContext(
username: username,
asfDeviceId: asfDeviceId,
asfClient: environment.cognitoUserPoolASFFactory(),
Expand Down
Loading
Loading