Skip to content

Commit

Permalink
Add MainActor attribution to avoid crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
chihchy committed Jul 10, 2024
1 parent 0de6620 commit 856c492
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion EhPanda/App/Tools/Clients/AppDelegateClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import ComposableArchitecture

struct AppDelegateClient {
let setOrientation: (UIInterfaceOrientationMask) -> Void
let setOrientation: @MainActor (UIInterfaceOrientationMask) -> Void
let setOrientationMask: (UIInterfaceOrientationMask) -> Void
}

Expand All @@ -23,6 +23,7 @@ extension AppDelegateClient {
}
)

@MainActor
func setPortraitOrientation() {
setOrientation(.portrait)
}
Expand Down
4 changes: 3 additions & 1 deletion EhPanda/App/Tools/Clients/UIApplicationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Combine
import ComposableArchitecture

struct UIApplicationClient {
let openURL: (URL) -> Void
let openURL: @MainActor (URL) -> Void
let hideKeyboard: () -> Void
let alternateIconName: () -> String?
let setAlternateIconName: @MainActor (String?) async -> Bool
Expand Down Expand Up @@ -43,11 +43,13 @@ extension UIApplicationClient {
(DeviceUtil.keyWindow ?? DeviceUtil.anyWindow)?.overrideUserInterfaceStyle = userInterfaceStyle
}
)
@MainActor
func openSettings() {
if let url = URL(string: UIApplication.openSettingsURLString) {
return openURL(url)
}
}
@MainActor
func openFileApp() {
if let dirPath = FileUtil.logsDirectoryURL?.path,
let dirURL = URL(string: "shareddocuments://" + dirPath)
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/View/Detail/Comments/CommentsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct CommentsReducer: Reducer {
case .handleCommentLink(let url):
guard urlClient.checkIfHandleable(url) else {
return .run { _ in
uiApplicationClient.openURL(url)
await uiApplicationClient.openURL(url)
}
}
let (isGalleryImageURL, _, _) = urlClient.analyzeURL(url)
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/View/Reading/ReadingReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ struct ReadingReducer: Reducer {
appDelegateClient.setPortraitOrientationMask()
})
effects.append(.run { _ in
appDelegateClient.setPortraitOrientation()
await appDelegateClient.setPortraitOrientation()
})
} else {
effects.append(.run { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct GeneralSettingReducer: Reducer {

case .navigateToSystemSetting:
return .run { _ in
uiApplicationClient.openSettings()
await uiApplicationClient.openSettings()
}

case .calculateWebImageDiskCache:
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/View/Setting/Logs/LogsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct LogsReducer: Reducer {

case .navigateToFileApp:
return .run { _ in
uiApplicationClient.openFileApp()
await uiApplicationClient.openFileApp()
}

case .teardown:
Expand Down

0 comments on commit 856c492

Please sign in to comment.