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 some concurrency warnings, update missed licence headers. #3741

Merged
merged 4 commits into from
Feb 6, 2025
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
2 changes: 1 addition & 1 deletion .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; }
git lfs pre-push "$@"
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 @@ -5,10 +5,11 @@
// Please see LICENSE files in the repository root for full details.
//

import Combine
import SwiftUI

class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol {
private var dismissalTimer: Timer?
private var timerCancellable: AnyCancellable?
private var displayTimes = [String: Date]()
private var delayedIndicators = Set<String>()

Expand All @@ -21,10 +22,11 @@ class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol
activeIndicator = indicatorQueue.last

if let activeIndicator, !activeIndicator.persistent {
dismissalTimer?.invalidate()
dismissalTimer = Timer.scheduledTimer(withTimeInterval: nonPersistentDisplayDuration, repeats: false) { [weak self] _ in
timerCancellable?.cancel()
timerCancellable = Task { [weak self, nonPersistentDisplayDuration] in
try await Task.sleep(for: .seconds(nonPersistentDisplayDuration))
self?.retractIndicatorWithId(activeIndicator.id)
}
}.asCancellable()
}
}
}
Expand All @@ -46,9 +48,9 @@ class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol
} else {
if let delay {
delayedIndicators.insert(indicator.id)

Timer.scheduledTimer(withTimeInterval: delay.seconds, repeats: false) { [weak self] _ in
guard let self else { return }
Task {
try await Task.sleep(for: .seconds(delay.seconds))

guard delayedIndicators.contains(indicator.id) else {
return
Expand All @@ -75,10 +77,11 @@ class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol
indicatorQueue.removeAll { $0.id == id }
return
}

Timer.scheduledTimer(withTimeInterval: minimumDisplayDuration, repeats: false) { [weak self] _ in
self?.indicatorQueue.removeAll { $0.id == id }
self?.displayTimes[id] = nil

Task {
try? await Task.sleep(for: .seconds(minimumDisplayDuration))
indicatorQueue.removeAll { $0.id == id }
displayTimes[id] = nil
}
}

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 @@ -46,7 +46,7 @@ final class ComposerDraftService: ComposerDraftServiceProtocol {
func getReply(eventID: String) async -> Result<TimelineItemReply, ComposerDraftServiceError> {
switch await roomProxy.timeline.getLoadedReplyDetails(eventID: eventID) {
case .success(let replyDetails):
return await .success(timelineItemfactory.buildReply(details: replyDetails))
return .success(timelineItemfactory.buildReply(details: replyDetails))
case .failure(let error):
MXLog.error("Could not load reply: \(error)")
return .failure(.failedToLoadReply)
Expand Down
Loading
Loading