Skip to content

Commit

Permalink
Merge pull request #376 from Jimmy-Prime/jimmy/fix-publisher-deprecated
Browse files Browse the repository at this point in the history
Jimmy/fix publisher deprecated
  • Loading branch information
chihchy authored May 30, 2024
2 parents 69f316b + 093504c commit 0f475cc
Show file tree
Hide file tree
Showing 24 changed files with 458 additions and 256 deletions.
8 changes: 4 additions & 4 deletions EhPanda.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2408,8 +2408,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swift-composable-architecture.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.0.0;
kind = exactVersion;
version = 1.0.0;
};
};
ABAC82FC26BC4866009F5026 /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */ = {
Expand All @@ -2424,8 +2424,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swiftui-navigation.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.0.0;
kind = exactVersion;
version = 1.0.0;
};
};
ABC4A0772751B40E00968A4F /* XCRemoteSwiftPackageReference "Kingfisher" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "ec62f32d21584214a4b27c8cee2b2ad70ab2c38a",
"version" : "0.11.0"
"revision" : "9dc9cbe4bc45c65164fa653a563d8d8db61b09bb",
"version" : "1.0.0"
}
},
{
Expand All @@ -50,17 +50,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tid-kijyun/Kanna.git",
"state" : {
"revision" : "f9e4922223dd0d3dfbf02ca70812cf5531fc0593",
"version" : "5.2.7"
"revision" : "41c3d28ea0eac07e4551b28def9de1ede702e739",
"version" : "5.3.0"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher.git",
"state" : {
"revision" : "3ec0ab0bca4feb56e8b33e289c9496e89059dd08",
"version" : "7.10.2"
"revision" : "5b92f029fab2cce44386d28588098b5be0824ef5",
"version" : "7.11.0"
}
},
{
Expand All @@ -77,71 +77,80 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "fc45e7b2cfece9dd80b5a45e6469ffe67fe67984",
"version" : "0.14.1"
"revision" : "e593aba2c6222daad7c4f2732a431eed2c09bb07",
"version" : "1.3.0"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "0fbaebfc013715dab44d715a4d350ba37f297e4d",
"version" : "0.4.0"
"revision" : "a8421d68068d8f45fbceb418fbf22c5dad4afd33",
"version" : "1.0.2"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
}
},
{
"identity" : "swift-composable-architecture",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture.git",
"state" : {
"revision" : "9f4202ab5b8422aa90f0ed983bf7652c3af7abf0",
"version" : "0.59.0"
"revision" : "195284b94b799b326729640453f547f08892293a",
"version" : "1.0.0"
}
},
{
"identity" : "swift-concurrency-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
"state" : {
"revision" : "479750bd98fac2e813fffcf2af0728b5b0085795",
"version" : "0.1.1"
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71",
"version" : "1.1.0"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "4a87bb75be70c983a9548597e8783236feb3401e",
"version" : "0.11.1"
"revision" : "f01efb26f3a192a0e88dcdb7c3c391ec2fc25d9c",
"version" : "1.3.0"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "16fd42ae04c6e7f74a6a86395d04722c641cccee",
"version" : "0.6.0"
"revision" : "d3a5af3038a09add4d7682f66555d6212058a3c0",
"version" : "1.2.2"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections",
"state" : {
"revision" : "d01446a78fb768adc9a78cbb6df07767c8ccfc29",
"version" : "0.8.0"
"revision" : "d1e45f3e1eee2c9193f5369fa9d70a6ddad635e8",
"version" : "1.0.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "fa8f95c2d536d6620cc2f504ebe8a6167c9fc2dd",
"version" : "510.0.1"
}
},
{
Expand All @@ -158,8 +167,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation.git",
"state" : {
"revision" : "2aa885e719087ee19df251c08a5980ad3e787f12",
"version" : "0.8.0"
"revision" : "f5bcdac5b6bb3f826916b14705f37a3937c2fd34",
"version" : "1.0.0"
}
},
{
Expand Down Expand Up @@ -221,8 +230,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "50843cbb8551db836adec2290bb4bc6bac5c1865",
"version" : "0.9.0"
"revision" : "b13b1d1a8e787a5ffc71ac19dcaf52183ab27ba2",
"version" : "1.1.1"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions EhPanda/App/Tools/Extensions/Reducer_Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ComposableArchitecture
extension Reducer {
func haptics<Enum, Case>(
unwrapping enum: @escaping (State) -> Enum?,
case casePath: CasePath<Enum, Case>,
case casePath: AnyCasePath<Enum, Case>,
hapticsClient: HapticsClient,
style: UIImpactFeedbackGenerator.FeedbackStyle = .light
) -> some Reducer<State, Action> {
Expand All @@ -24,7 +24,7 @@ extension Reducer {

private func onBecomeNonNil<Enum, Case>(
unwrapping enum: @escaping (State) -> Enum?,
case casePath: CasePath<Enum, Case>,
case casePath: AnyCasePath<Enum, Case>,
perform additionalEffects: @escaping (inout State, Action) -> Effect<Action>
) -> some Reducer<State, Action> {
Reduce { state, action in
Expand Down
10 changes: 5 additions & 5 deletions EhPanda/App/Tools/Extensions/SwiftUINavigation_Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension NavigationLink {
}
init<Enum, Case, WrappedDestination>(
unwrapping enum: Binding<Enum?>,
case casePath: CasePath<Enum, Case>,
case casePath: AnyCasePath<Enum, Case>,
@ViewBuilder destination: @escaping (Binding<Case>) -> WrappedDestination
) where Destination == WrappedDestination?, Label == Text {
self.init(
Expand All @@ -38,7 +38,7 @@ extension View {
@ViewBuilder
func sheet<Enum, Case, Content>(
unwrapping enum: Binding<Enum?>,
case casePath: CasePath<Enum, Case>,
case casePath: AnyCasePath<Enum, Case>,
onDismiss: (() -> Void)? = nil,
isEnabled: Bool,
@ViewBuilder content: @escaping (Binding<Case>) -> Content
Expand All @@ -53,7 +53,7 @@ extension View {
func confirmationDialog<Enum, Case, A: View>(
message: String,
unwrapping enum: Binding<Enum?>,
case casePath: CasePath<Enum, Case>,
case casePath: AnyCasePath<Enum, Case>,
@ViewBuilder actions: @escaping (Case) -> A
) -> some View {
self.confirmationDialog(
Expand All @@ -67,7 +67,7 @@ extension View {
func confirmationDialog<Enum, Case: Equatable, A: View>(
message: String,
unwrapping enum: Binding<Enum?>,
case casePath: CasePath<Enum, Case>,
case casePath: AnyCasePath<Enum, Case>,
matching case: Case,
@ViewBuilder actions: @escaping (Case) -> A
) -> some View {
Expand All @@ -87,7 +87,7 @@ extension View {
func progressHUD<Enum: Equatable, Case>(
config: TTProgressHUDConfig,
unwrapping enum: Binding<Enum?>,
case casePath: CasePath<Enum, Case>
case casePath: AnyCasePath<Enum, Case>
) -> some View {
ZStack {
self
Expand Down
16 changes: 10 additions & 6 deletions EhPanda/DataFlow/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ struct AppReducer: Reducer {
var body: some Reducer<State, Action> {
LoggingReducer {
BindingReducer()
.onChange(of: \.appRouteState.route) { _, newValue in
Reduce { _, _ in
return newValue == nil ? .send(.appRoute(.clearSubStates)) : .none
}
}
.onChange(of: \.settingState.setting) { _, _ in
Reduce { _, _ in
return .send(.setting(.syncSetting))
}
}

Reduce { state, action in
switch action {
case .binding(\.appRouteState.$route):
return state.appRouteState.route == nil ? .send(.appRoute(.clearSubStates)) : .none

case .binding(\.settingState.$setting):
return .send(.setting(.syncSetting))

case .binding:
return .none

Expand Down
6 changes: 4 additions & 2 deletions EhPanda/DataFlow/AppRouteReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ struct AppRouteReducer: Reducer {

case .fetchGallery(let url, let isGalleryImageURL):
state.route = .hud
return GalleryReverseRequest(url: url, isGalleryImageURL: isGalleryImageURL)
.effect.map({ Action.fetchGalleryDone(url, $0) })
return .run { send in
let response = await GalleryReverseRequest(url: url, isGalleryImageURL: isGalleryImageURL).response()
await send(Action.fetchGalleryDone(url, response))
}

case .fetchGalleryDone(let url, let result):
state.route = nil
Expand Down
26 changes: 24 additions & 2 deletions EhPanda/Network/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ protocol Request {
var publisher: AnyPublisher<Response, AppError> { get }
}
extension Request {
var effect: Effect<Result<Response, AppError>> {
publisher.receive(on: DispatchQueue.main).catchToEffect()
func response() async -> Result<Response, AppError> {
await publisher.receive(on: DispatchQueue.main).async()
}

func mapAppError(error: Error) -> AppError {
Expand All @@ -41,6 +41,28 @@ private extension Publisher {
func genericRetry() -> Publishers.Retry<Self> {
retry(3)
}

func async() async -> Result<Output, Failure> where Failure == AppError {
await withCheckedContinuation { continuation in
var cancellable: AnyCancellable?
var finishedWithoutValue = true
cancellable = first()
.sink { result in
switch result {
case .finished:
if finishedWithoutValue {
continuation.resume(returning: .failure(.unknown))
}
case let .failure(error):
continuation.resume(returning: .failure(error))
}
cancellable?.cancel()
} receiveValue: { value in
finishedWithoutValue = false
continuation.resume(returning: .success(value))
}
}
}
}
private extension URLRequest {
mutating func setURLEncodedContentType() {
Expand Down
27 changes: 18 additions & 9 deletions EhPanda/View/Detail/Archives/ArchivesReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ struct ArchivesReducer: Reducer {
case .fetchArchive(let gid, let galleryURL, let archiveURL):
guard state.loadingState != .loading else { return .none }
state.loadingState = .loading
return GalleryArchiveRequest(archiveURL: archiveURL)
.effect.map({ Action.fetchArchiveDone(gid, galleryURL, $0) })
.cancellable(id: CancelID.fetchArchive)
return .run { send in
let response = await GalleryArchiveRequest(archiveURL: archiveURL).response()
await send(Action.fetchArchiveDone(gid, galleryURL, response))
}
.cancellable(id: CancelID.fetchArchive)

case .fetchArchiveDone(let gid, let galleryURL, let result):
state.loadingState = .idle
Expand All @@ -99,8 +101,11 @@ struct ArchivesReducer: Reducer {

case .fetchArchiveFunds(let gid, let galleryURL):
guard let galleryURL = galleryURL.replaceHost(to: Defaults.URL.ehentai.host) else { return .none }
return GalleryArchiveFundsRequest(gid: gid, galleryURL: galleryURL)
.effect.map(Action.fetchArchiveFundsDone).cancellable(id: CancelID.fetchArchiveFunds)
return .run { send in
let response = await GalleryArchiveFundsRequest(gid: gid, galleryURL: galleryURL).response()
await send(Action.fetchArchiveFundsDone(response))
}
.cancellable(id: CancelID.fetchArchiveFunds)

case .fetchArchiveFundsDone(let result):
if case .success(let (galleryPoints, credits)) = result {
Expand All @@ -113,10 +118,14 @@ struct ArchivesReducer: Reducer {
state.route != .communicatingHUD
else { return .none }
state.route = .communicatingHUD
return SendDownloadCommandRequest(
archiveURL: archiveURL, resolution: selectedArchive.resolution.parameter
)
.effect.map(Action.fetchDownloadResponseDone).cancellable(id: CancelID.fetchDownloadResponse)
return .run {send in
let response = await SendDownloadCommandRequest(
archiveURL: archiveURL,
resolution: selectedArchive.resolution.parameter
).response()
await send(Action.fetchDownloadResponseDone(response))
}
.cancellable(id: CancelID.fetchDownloadResponse)

case .fetchDownloadResponseDone(let result):
state.route = .messageHUD
Expand Down
Loading

0 comments on commit 0f475cc

Please sign in to comment.