Skip to content

Commit

Permalink
Fix 'fireAndForget' is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy-Prime committed Mar 15, 2024
1 parent 52fd6c8 commit 0026c04
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 64 deletions.
8 changes: 4 additions & 4 deletions EhPanda/App/Tools/Clients/ClipboardClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ extension ClipboardClient {
UIPasteboard.general.changeCount
},
saveText: { text in
.fireAndForget {
.run(operation: { _ in
UIPasteboard.general.string = text
}
})
},
saveImage: { (image, isAnimated) in
.fireAndForget {
.run(operation: { _ in
if isAnimated {
DispatchQueue.global(qos: .utility).async {
if let data = image.kf.data(format: .GIF) {
Expand All @@ -44,7 +44,7 @@ extension ClipboardClient {
} else {
UIPasteboard.general.image = image
}
}
})
}
)
}
Expand Down
20 changes: 10 additions & 10 deletions EhPanda/App/Tools/Clients/CookieClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ struct CookieClient {
extension CookieClient {
static let live: Self = .init(
clearAll: {
.fireAndForget {
.run(operation: { _ in
if let historyCookies = HTTPCookieStorage.shared.cookies {
historyCookies.forEach {
HTTPCookieStorage.shared.deleteCookie($0)
}
}
}
})
},
getCookie: { url, key in
var value = CookieValue(
Expand Down Expand Up @@ -109,13 +109,13 @@ extension CookieClient {
HTTPCookieStorage.shared.setCookie(cookie)
}
func setOrEditCookie(for url: URL, key: String, value: String) -> Effect<Never> {
.fireAndForget {
.run(operation: { _ in
if checkExistence(url, key) {
editCookie(for: url, key: key, value: value)
} else {
setCookie(for: url, key: key, value: value)
}
}
})
}
}

Expand All @@ -139,10 +139,10 @@ extension CookieClient {
&& getCookie(url, Defaults.Cookie.igneous).rawValue.isEmpty
}
func removeYay() -> Effect<Never> {
.fireAndForget {
.run(operation: { _ in
removeCookie(Defaults.URL.exhentai, Defaults.Cookie.yay)
removeCookie(Defaults.URL.sexhentai, Defaults.Cookie.yay)
}
})
}
func syncExCookies() -> Effect<Never> {
.merge(
Expand Down Expand Up @@ -234,7 +234,7 @@ extension CookieClient {
return effects.isEmpty ? .none : .merge(effects)
}
func setCredentials(response: HTTPURLResponse) -> Effect<Never> {
.fireAndForget {
.run(operation: { _ in
guard let setString = response.allHeaderFields["Set-Cookie"] as? String else { return }
setString.components(separatedBy: ", ")
.flatMap { $0.components(separatedBy: "; ") }.forEach { value in
Expand All @@ -250,10 +250,10 @@ extension CookieClient {
}
}
}
}
})
}
func setSkipServer(response: HTTPURLResponse) -> Effect<Never> {
.fireAndForget {
.run(operation: { _ in
guard let setString = response.allHeaderFields["Set-Cookie"] as? String else { return }
setString.components(separatedBy: ", ")
.flatMap { $0.components(separatedBy: "; ") }
Expand All @@ -266,7 +266,7 @@ extension CookieClient {
)
}
}
}
})
}
}

Expand Down
4 changes: 2 additions & 2 deletions EhPanda/App/Tools/Clients/DFClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct DFClient {
extension DFClient {
static let live: Self = .init(
setActive: { newValue in
.fireAndForget {
.run(operation: { _ in
if newValue {
URLProtocol.registerClass(DFURLProtocol.self)
} else {
Expand All @@ -26,7 +26,7 @@ extension DFClient {
let config = KingfisherManager.shared.downloader.sessionConfiguration
config.protocolClasses = newValue ? [DFURLProtocol.self] : nil
KingfisherManager.shared.downloader.sessionConfiguration = config
}
})
}
)
}
Expand Down
28 changes: 14 additions & 14 deletions EhPanda/App/Tools/Clients/DatabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,21 @@ extension DatabaseClient {
extension DatabaseClient {
func updateGallery(gid: String, key: String, value: Any?) -> Effect<Never> {
guard gid.isValidGID else { return .none }
return .fireAndForget {
return .run(operation: { _ in
DispatchQueue.main.async {
update(
entityType: GalleryMO.self, gid: gid, createIfNil: true,
commitChanges: { $0.setValue(value, forKeyPath: key) }
)
}
}
})
}
func updateLastOpenDate(gid: String, date: Date = .now) -> Effect<Never> {
guard gid.isValidGID else { return .none }
return updateGallery(gid: gid, key: "lastOpenDate", value: date)
}
func clearHistoryGalleries() -> Effect<Never> {
.fireAndForget {
.run(operation: { _ in
DispatchQueue.main.async {
let predicate = NSPredicate(format: "lastOpenDate != nil")
batchUpdate(entityType: GalleryMO.self, predicate: predicate) { galleryMOs in
Expand All @@ -313,10 +313,10 @@ extension DatabaseClient {
}
}
}
}
})
}
func cacheGalleries(_ galleries: [Gallery]) -> Effect<Never> {
.fireAndForget {
.run(operation: { _ in
DispatchQueue.main.async {
for gallery in galleries.filter({ $0.id.isValidGID }) {
let storedMO = fetch(
Expand All @@ -342,15 +342,15 @@ extension DatabaseClient {
}
saveContext()
}
}
})
}
}

// MARK: UpdateGalleryDetail
extension DatabaseClient {
func cacheGalleryDetail(_ detail: GalleryDetail) -> Effect<Never> {
guard detail.gid.isValidGID else { return .none }
return .fireAndForget {
return .run(operation: { _ in
DispatchQueue.main.async {
let storedMO = fetch(
entityType: GalleryDetailMO.self, gid: detail.gid
Expand Down Expand Up @@ -380,22 +380,22 @@ extension DatabaseClient {
}
saveContext()
}
}
})
}
}

// MARK: UpdateGalleryState
extension DatabaseClient {
func updateGalleryState(gid: String, commitChanges: @escaping (GalleryStateMO) -> Void) -> Effect<Never> {
guard gid.isValidGID else { return .none }
return .fireAndForget {
return .run(operation: { _ in
DispatchQueue.main.async {
update(
entityType: GalleryStateMO.self, gid: gid, createIfNil: true,
commitChanges: commitChanges
)
}
}
})
}
func updateGalleryState(gid: String, key: String, value: Any?) -> Effect<Never> {
guard gid.isValidGID else { return .none }
Expand Down Expand Up @@ -430,7 +430,7 @@ extension DatabaseClient {
}
}
func removeImageURLs() -> Effect<Never> {
.fireAndForget {
.run(operation: { _ in
DispatchQueue.main.async {
batchUpdate(entityType: GalleryStateMO.self) { galleryStateMOs in
galleryStateMOs.forEach { galleryStateMO in
Expand All @@ -441,7 +441,7 @@ extension DatabaseClient {
}
}
}
}
})
}
func removeExpiredImageURLs() -> Effect<Never> {
fetchHistoryGalleries()
Expand Down Expand Up @@ -490,14 +490,14 @@ extension DatabaseClient {
// MARK: UpdateAppEnv
extension DatabaseClient {
func updateAppEnv(key: String, value: Any?) -> Effect<Never> {
.fireAndForget {
.run(operation: { _ in
DispatchQueue.main.async {
update(
entityType: AppEnvMO.self, createIfNil: true,
commitChanges: { $0.setValue(value, forKeyPath: key) }
)
}
}
})
}
func updateSetting(_ setting: Setting) -> Effect<Never> {
updateAppEnv(key: "setting", value: setting.toData())
Expand Down
4 changes: 2 additions & 2 deletions EhPanda/App/Tools/Clients/ImageClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ struct ImageClient {
extension ImageClient {
static let live: Self = .init(
prefetchImages: { urls in
.fireAndForget {
.run(operation: { _ in
ImagePrefetcher(urls: urls).start()
}
})
},
saveImageToPhotoLibrary: { (image, isAnimated) in
Future { promise in
Expand Down
12 changes: 6 additions & 6 deletions EhPanda/App/Tools/Clients/LibraryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct LibraryClient {
extension LibraryClient {
static let live: Self = .init(
initializeLogger: {
.fireAndForget {
.run(operation: { _ in
// MARK: SwiftyBeaver
let file = FileDestination()
let console = ConsoleDestination()
Expand Down Expand Up @@ -52,19 +52,19 @@ extension LibraryClient {
#if DEBUG
SwiftyBeaver.addDestination(console)
#endif
}
})
},
initializeWebImage: {
.fireAndForget {
.run(operation: { _ in
let config = KingfisherManager.shared.downloader.sessionConfiguration
config.httpCookieStorage = HTTPCookieStorage.shared
KingfisherManager.shared.downloader.sessionConfiguration = config
}
})
},
clearWebImageDiskCache: {
.fireAndForget {
.run(operation: { _ in
KingfisherManager.shared.cache.clearDiskCache()
}
})
},
analyzeImageColors: { image in
Future { promise in
Expand Down
8 changes: 4 additions & 4 deletions EhPanda/App/Tools/Clients/LoggerClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ struct LoggerClient {
extension LoggerClient {
static let live: Self = .init(
info: { message, context in
.fireAndForget {
.run(operation: { _ in
Logger.info(message, context: context)
}
})
},
error: { message, context in
.fireAndForget {
.run(operation: { _ in
Logger.error(message, context: context)
}
})
}
)
}
Expand Down
4 changes: 2 additions & 2 deletions EhPanda/App/Tools/Clients/UserDefaultsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ struct UserDefaultsClient {
extension UserDefaultsClient {
static let live: Self = .init(
setValue: { value, key in
.fireAndForget {
.run(operation: { _ in
UserDefaults.standard.set(value, forKey: key.rawValue)
}
})
}
)

Expand Down
2 changes: 1 addition & 1 deletion EhPanda/App/Tools/Extensions/Reducer_Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension Reducer {
style: UIImpactFeedbackGenerator.FeedbackStyle = .light
) -> some Reducer<State, Action> {
onBecomeNonNil(unwrapping: `enum`, case: casePath) { _, _ in
.fireAndForget({ hapticsClient.generateFeedback(style) })
.run(operation: { _ in hapticsClient.generateFeedback(style) })
}
}

Expand Down
4 changes: 2 additions & 2 deletions EhPanda/DataFlow/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct AppReducer: Reducer {

case .tabBar(.setTabBarItemType(let type)):
var effects = [Effect<Action>]()
let hapticEffect: Effect<Action> = .fireAndForget({ hapticsClient.generateFeedback(.soft) })
let hapticEffect: Effect<Action> = .run(operation: { _ in hapticsClient.generateFeedback(.soft) })
if type == state.tabBarState.tabBarItemType {
switch type {
case .home:
Expand Down Expand Up @@ -149,7 +149,7 @@ struct AppReducer: Reducer {

case .home(.watched(.onNotLoginViewButtonTapped)), .favorites(.onNotLoginViewButtonTapped):
var effects: [Effect<Action>] = [
.fireAndForget({ hapticsClient.generateFeedback(.soft) }),
.run(operation: { _ in hapticsClient.generateFeedback(.soft) }),
Effect.send(.tabBar(.setTabBarItemType(.setting)))
]
effects.append(Effect.send(.setting(.setNavigation(.account))))
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/View/Detail/Archives/ArchivesReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct ArchivesReducer: Reducer {
state.messageHUDConfig = .error
isSuccess = false
}
return .fireAndForget({ hapticsClient.generateNotificationFeedback(isSuccess ? .success : .error) })
return .run(operation: { _ in hapticsClient.generateNotificationFeedback(isSuccess ? .success : .error) })
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions EhPanda/View/Detail/DetailReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ struct DetailReducer: Reducer {

case .toggleShowFullTitle:
state.showsFullTitle.toggle()
return .fireAndForget({ hapticsClient.generateFeedback(.soft) })
return .run(operation: { _ in hapticsClient.generateFeedback(.soft) })

case .toggleShowUserRating:
state.showsUserRating.toggle()
return .fireAndForget({ hapticsClient.generateFeedback(.soft) })
return .run(operation: { _ in hapticsClient.generateFeedback(.soft) })

case .setCommentContent(let content):
state.commentContent = content
Expand All @@ -188,7 +188,7 @@ struct DetailReducer: Reducer {
state.updateRating(value: value)
return .merge(
Effect.send(.rateGallery),
.fireAndForget({ hapticsClient.generateFeedback(.soft) }),
.run(operation: { _ in hapticsClient.generateFeedback(.soft) }),
Effect.send(.confirmRatingDone).delay(for: 1, scheduler: DispatchQueue.main).eraseToEffect()
)

Expand Down Expand Up @@ -320,10 +320,10 @@ struct DetailReducer: Reducer {
if case .success = result {
return .merge(
Effect.send(.fetchGalleryDetail),
.fireAndForget({ hapticsClient.generateNotificationFeedback(.success) })
.run(operation: { _ in hapticsClient.generateNotificationFeedback(.success) })
)
}
return .fireAndForget({ hapticsClient.generateNotificationFeedback(.error) })
return .run(operation: { _ in hapticsClient.generateNotificationFeedback(.error) })

case .reading(.onPerformDismiss):
return Effect.send(.setNavigation(nil))
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/View/Detail/GalleryInfos/GalleryInfosReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct GalleryInfosReducer: Reducer {
state.route = .hud
return .merge(
clipboardClient.saveText(text).fireAndForget(),
.fireAndForget({ hapticsClient.generateNotificationFeedback(.success) })
.run(operation: { _ in hapticsClient.generateNotificationFeedback(.success) })
)
}
}
Expand Down
Loading

0 comments on commit 0026c04

Please sign in to comment.