Skip to content

Commit

Permalink
Fix some concurrency warnings, update missed licence headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Feb 5, 2025
1 parent 6c190cf commit 3e655c2
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 112 deletions.
1 change: 1 addition & 0 deletions ElementX/Sources/Application/AppCoordinatorProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation

@MainActor
protocol AppCoordinatorProtocol: CoordinatorProtocol {
var windowManager: SecureWindowManagerProtocol { get }

Expand Down
15 changes: 3 additions & 12 deletions ElementX/Sources/Other/Extensions/Snapshotting.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//
// Copyright 2024 New Vector Ltd
// Copyright 2022-2024 New Vector Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//

import Combine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

/// Represents a specific portion of the ViewState that can be bound to with SwiftUI's [2-way binding](https://developer.apple.com/documentation/swiftui/binding).
@MainActor
protocol BindableState {
/// The associated type of the Bindable State. Defaults to Void.
associatedtype BindStateType = Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Combine

@MainActor
protocol SoftLogoutScreenViewModelProtocol {
var actions: AnyPublisher<SoftLogoutScreenViewModelAction, Never> { get }
var context: SoftLogoutScreenViewModelType.Context { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ struct WebRegistrationWebView: UIViewRepresentable {
webView.load(URLRequest(url: url))
}

nonisolated func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
guard let jsonString = message.body as? String, let jsonData = jsonString.data(using: .utf8) else {
MXLog.error("Unexpected response.")
return
Expand All @@ -94,7 +94,7 @@ struct WebRegistrationWebView: UIViewRepresentable {
}

MXLog.info("Received login credentials.")
Task { await viewModelContext.send(viewAction: .signedIn(credentials)) }
viewModelContext.send(viewAction: .signedIn(credentials))
}

// MARK: WKUIDelegate
Expand All @@ -120,8 +120,8 @@ struct WebRegistrationWebView: UIViewRepresentable {

// MARK: WKScriptMessageHandler

nonisolated func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
coordinator?.userContentController(userContentController, didReceive: message)
}
}
Expand Down
16 changes: 5 additions & 11 deletions ElementX/Sources/Screens/CallScreen/View/CallScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,8 @@ private struct CallView: UIViewRepresentable {
}
}

nonisolated func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
Task { @MainActor [weak self] in
self?.viewModelContext?.javaScriptMessageHandler?(message.body)
}
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
viewModelContext?.javaScriptMessageHandler?(message.body)
}

// MARK: - WKUIDelegate
Expand Down Expand Up @@ -191,10 +188,8 @@ private struct CallView: UIViewRepresentable {
return .cancel
}

nonisolated func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
Task { @MainActor in
viewModelContext?.send(viewAction: .urlChanged(webView.url))
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
viewModelContext?.send(viewAction: .urlChanged(webView.url))
}

// MARK: - Picture in Picture
Expand Down Expand Up @@ -271,8 +266,7 @@ private struct CallView: UIViewRepresentable {

// MARK: - WKScriptMessageHandler

nonisolated func userContentController(_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage) {
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
coordinator?.userContentController(userContentController, didReceive: message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Combine
import Foundation

@MainActor
protocol ReportContentScreenViewModelProtocol {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//
// Copyright 2022 New Vector Ltd
// Copyright 2022-2024 New Vector Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//

import Combine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//
// Copyright 2022 New Vector Ltd
// Copyright 2022-2024 New Vector Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//

import Foundation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//
// Copyright 2022 New Vector Ltd
// Copyright 2022-2024 New Vector Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//

import Combine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//
// Copyright 2022 New Vector Ltd
// Copyright 2022-2024 New Vector Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//

import Combine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//
// Copyright 2022 New Vector Ltd
// Copyright 2022-2024 New Vector Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//

import Compound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Combine
import WysiwygComposer

// periphery: ignore - markdown protocol
@MainActor
protocol ComposerToolbarViewModelProtocol {
var actions: AnyPublisher<ComposerToolbarViewModelAction, Never> { get }
var context: ComposerToolbarViewModelType.Context { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import Combine
import Foundation

@MainActor
protocol RoomScreenViewModelProtocol {
var actions: AnyPublisher<RoomScreenViewModelAction, Never> { get }
var context: RoomScreenViewModel.Context { get }
Expand Down
14 changes: 5 additions & 9 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,12 @@ class ClientProxy: ClientProxyProtocol {
// Note: This isn't strictly necessary now given the unwrap above, but leaving the code as
// documentation. SE-0371 will allow us to fix this by using an async deinit.
Task { [syncService] in
do {
defer {
completion?()
}

try await syncService.stop()
MXLog.info("Sync stopped")
} catch {
MXLog.error("Failed stopping the sync service with error: \(error)")
defer {
completion?()
}

await syncService.stop()
MXLog.info("Sync stopped")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ class TimelineController: TimelineControllerProtocol {
@objc private func contentSizeCategoryDidChange() {
// Recompute all attributed strings on content size changes -> DynamicType support
serialDispatchQueue.async { [activeTimelineProvider] in
self.updateTimelineItems(itemProxies: activeTimelineProvider.itemProxies, paginationState: activeTimelineProvider.paginationState)
MainActor.assumeIsolated {
self.updateTimelineItems(itemProxies: activeTimelineProvider.itemProxies, paginationState: activeTimelineProvider.paginationState)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
//
// Copyright 2022 New Vector Ltd
// Copyright 2022-2024 New Vector Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//

import XCTest
Expand Down

0 comments on commit 3e655c2

Please sign in to comment.