Skip to content

Commit

Permalink
Migrate to TCA 1.0 [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
chihchy committed Jan 28, 2024
1 parent 99906b7 commit e6a51c4
Show file tree
Hide file tree
Showing 87 changed files with 1,709 additions and 1,591 deletions.
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ identifier_name:
- y
- id
- no
- mo

excluded:
- EhPandaTests
- EhPanda/App/Generated
40 changes: 24 additions & 16 deletions EhPanda.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
AB6DE897268822390087C579 /* LogsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB6DE896268822390087C579 /* LogsView.swift */; };
AB706F7927890A6C0025A48A /* AppRouteReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB706F7827890A6C0025A48A /* AppRouteReducer.swift */; };
AB706F7B278937500025A48A /* FrontpageReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB706F7A278937500025A48A /* FrontpageReducer.swift */; };
AB706F80278981370025A48A /* AlertKit_Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB706F7F278981370025A48A /* AlertKit_Extension.swift */; };
AB706F80278981370025A48A /* AlertKit+.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB706F7F278981370025A48A /* AlertKit+.swift */; };
AB706F82278986120025A48A /* ToolbarItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB706F81278986120025A48A /* ToolbarItems.swift */; };
AB706F842789AD2D0025A48A /* ToplistsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB706F832789AD2D0025A48A /* ToplistsView.swift */; };
AB706F862789AD490025A48A /* ToplistsReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB706F852789AD490025A48A /* ToplistsReducer.swift */; };
Expand Down Expand Up @@ -155,7 +155,7 @@
AB7BF2D427AA3F12001865A3 /* CookieUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7BF2D327AA3F12001865A3 /* CookieUtil.swift */; };
AB7BF2D627AA3F4C001865A3 /* FileUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7BF2D527AA3F4C001865A3 /* FileUtil.swift */; };
AB7BF2D827AA3F61001865A3 /* UserDefaultsUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7BF2D727AA3F61001865A3 /* UserDefaultsUtil.swift */; };
AB7BF2DA27AA78CF001865A3 /* Reducer_Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7BF2D927AA78CF001865A3 /* Reducer_Extension.swift */; };
AB7BF2DA27AA78CF001865A3 /* Reducer+.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7BF2D927AA78CF001865A3 /* Reducer+.swift */; };
AB7BF2FB27ABCA3A001865A3 /* MigrationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7BF2FA27ABCA3A001865A3 /* MigrationView.swift */; };
AB7BF2FD27ABCAD4001865A3 /* MigrationReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7BF2FC27ABCAD4001865A3 /* MigrationReducer.swift */; };
AB7BF30727ABDFF1001865A3 /* CoreDataMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB7BF2FE27ABDFF1001865A3 /* CoreDataMigrator.swift */; };
Expand Down Expand Up @@ -187,8 +187,8 @@
ABAC82FE26BC4A96009F5026 /* OpenCC in Frameworks */ = {isa = PBXBuildFile; productRef = ABAC82FD26BC4A96009F5026 /* OpenCC */; };
ABBB2631278E6EF3007B6149 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBB2630278E6EF3007B6149 /* SearchView.swift */; };
ABBB2636278FB888007B6149 /* SwiftUINavigation in Frameworks */ = {isa = PBXBuildFile; productRef = ABBB2635278FB888007B6149 /* SwiftUINavigation */; };
ABBB2638278FBD2F007B6149 /* SwiftUINavigation_Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBB2637278FBD2F007B6149 /* SwiftUINavigation_Extension.swift */; };
ABBB263A2792588F007B6149 /* TTProgressHUD_Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBB26392792588F007B6149 /* TTProgressHUD_Extension.swift */; };
ABBB2638278FBD2F007B6149 /* SwiftUINavigation+.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBB2637278FBD2F007B6149 /* SwiftUINavigation+.swift */; };
ABBB263A2792588F007B6149 /* TTProgressHUD+.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBB26392792588F007B6149 /* TTProgressHUD+.swift */; };
ABBB263E2793C648007B6149 /* PreviewsReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBB263D2793C648007B6149 /* PreviewsReducer.swift */; };
ABBB2640279417EC007B6149 /* CommentsReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBB263F279417EC007B6149 /* CommentsReducer.swift */; };
ABBB264227942B74007B6149 /* URLClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABBB264127942B74007B6149 /* URLClient.swift */; };
Expand Down Expand Up @@ -271,6 +271,8 @@
ABF9720A26DE6E1300118887 /* GalleryDetailWithGreeting.html in Resources */ = {isa = PBXBuildFile; fileRef = ABF9720926DE6E1300118887 /* GalleryDetailWithGreeting.html */; };
EA2E2E7F2A1F7E500038A261 /* SettingReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA2E2E7E2A1F7E500038A261 /* SettingReducer.swift */; };
EA2E2E822A1FA1060038A261 /* SearchReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA2E2E812A1FA1050038A261 /* SearchReducer.swift */; };
EAC831E02B66298900B518D5 /* CoreData+.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC831DF2B66298900B518D5 /* CoreData+.swift */; };
EAC831E22B662BB300B518D5 /* NSPredicate+.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC831E12B662BB300B518D5 /* NSPredicate+.swift */; };
EAE63E2129E2A6330048C601 /* SwiftyBeaver in Frameworks */ = {isa = PBXBuildFile; productRef = EAE63E2029E2A6330048C601 /* SwiftyBeaver */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -412,7 +414,7 @@
AB6DE896268822390087C579 /* LogsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogsView.swift; sourceTree = "<group>"; };
AB706F7827890A6C0025A48A /* AppRouteReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppRouteReducer.swift; sourceTree = "<group>"; };
AB706F7A278937500025A48A /* FrontpageReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrontpageReducer.swift; sourceTree = "<group>"; };
AB706F7F278981370025A48A /* AlertKit_Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertKit_Extension.swift; sourceTree = "<group>"; };
AB706F7F278981370025A48A /* AlertKit+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AlertKit+.swift"; sourceTree = "<group>"; };
AB706F81278986120025A48A /* ToolbarItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolbarItems.swift; sourceTree = "<group>"; };
AB706F832789AD2D0025A48A /* ToplistsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToplistsView.swift; sourceTree = "<group>"; };
AB706F852789AD490025A48A /* ToplistsReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToplistsReducer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -452,7 +454,7 @@
AB7BF2D327AA3F12001865A3 /* CookieUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CookieUtil.swift; sourceTree = "<group>"; };
AB7BF2D527AA3F4C001865A3 /* FileUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUtil.swift; sourceTree = "<group>"; };
AB7BF2D727AA3F61001865A3 /* UserDefaultsUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsUtil.swift; sourceTree = "<group>"; };
AB7BF2D927AA78CF001865A3 /* Reducer_Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reducer_Extension.swift; sourceTree = "<group>"; };
AB7BF2D927AA78CF001865A3 /* Reducer+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Reducer+.swift"; sourceTree = "<group>"; };
AB7BF2FA27ABCA3A001865A3 /* MigrationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationView.swift; sourceTree = "<group>"; };
AB7BF2FC27ABCAD4001865A3 /* MigrationReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationReducer.swift; sourceTree = "<group>"; };
AB7BF2FE27ABDFF1001865A3 /* CoreDataMigrator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataMigrator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -487,8 +489,8 @@
ABB5013026A41EBA00B542D9 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
ABB5013126A41EBA00B542D9 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/InfoPlist.strings; sourceTree = "<group>"; };
ABBB2630278E6EF3007B6149 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; };
ABBB2637278FBD2F007B6149 /* SwiftUINavigation_Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUINavigation_Extension.swift; sourceTree = "<group>"; };
ABBB26392792588F007B6149 /* TTProgressHUD_Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TTProgressHUD_Extension.swift; sourceTree = "<group>"; };
ABBB2637278FBD2F007B6149 /* SwiftUINavigation+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftUINavigation+.swift"; sourceTree = "<group>"; };
ABBB26392792588F007B6149 /* TTProgressHUD+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TTProgressHUD+.swift"; sourceTree = "<group>"; };
ABBB263D2793C648007B6149 /* PreviewsReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewsReducer.swift; sourceTree = "<group>"; };
ABBB263F279417EC007B6149 /* CommentsReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsReducer.swift; sourceTree = "<group>"; };
ABBB264127942B74007B6149 /* URLClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLClient.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -581,6 +583,8 @@
ABF9720926DE6E1300118887 /* GalleryDetailWithGreeting.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = GalleryDetailWithGreeting.html; sourceTree = "<group>"; };
EA2E2E7E2A1F7E500038A261 /* SettingReducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingReducer.swift; sourceTree = "<group>"; };
EA2E2E812A1FA1050038A261 /* SearchReducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchReducer.swift; sourceTree = "<group>"; };
EAC831DF2B66298900B518D5 /* CoreData+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreData+.swift"; sourceTree = "<group>"; };
EAC831E12B662BB300B518D5 /* NSPredicate+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSPredicate+.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -900,10 +904,12 @@
children = (
ABA732D825A8018A00B3D9AB /* Extensions.swift */,
ABC3C7762593699A00E0C11B /* ViewModifiers.swift */,
AB706F7F278981370025A48A /* AlertKit_Extension.swift */,
AB7BF2D927AA78CF001865A3 /* Reducer_Extension.swift */,
ABBB26392792588F007B6149 /* TTProgressHUD_Extension.swift */,
ABBB2637278FBD2F007B6149 /* SwiftUINavigation_Extension.swift */,
AB706F7F278981370025A48A /* AlertKit+.swift */,
AB7BF2D927AA78CF001865A3 /* Reducer+.swift */,
ABBB26392792588F007B6149 /* TTProgressHUD+.swift */,
ABBB2637278FBD2F007B6149 /* SwiftUINavigation+.swift */,
EAC831DF2B66298900B518D5 /* CoreData+.swift */,
EAC831E12B662BB300B518D5 /* NSPredicate+.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1790,6 +1796,7 @@
AB1FA94D27CA1F140063EF55 /* TagTranslation.swift in Sources */,
ABC8355D27B118330091DCDB /* DetailSearchView.swift in Sources */,
ABBB264227942B74007B6149 /* URLClient.swift in Sources */,
EAC831E02B66298900B518D5 /* CoreData+.swift in Sources */,
AB0CFBD527C24B3B004BD372 /* MarkdownUtil.swift in Sources */,
ABF45AF625F3313D00ECB568 /* AppearanceSettingView.swift in Sources */,
AB7BF2CE27AA3E58001865A3 /* AppUtil.swift in Sources */,
Expand Down Expand Up @@ -1840,7 +1847,7 @@
AB0929C027805A8200F107CA /* LoginReducer.swift in Sources */,
ABBB2631278E6EF3007B6149 /* SearchView.swift in Sources */,
AB706F92278A6E8C0025A48A /* WatchedReducer.swift in Sources */,
AB706F80278981370025A48A /* AlertKit_Extension.swift in Sources */,
AB706F80278981370025A48A /* AlertKit+.swift in Sources */,
ABA9A6C228EC7BD000EE28DE /* Strings.swift in Sources */,
AB58A5B22776B99000C0D285 /* AppReducer.swift in Sources */,
AB24C566276758E30085C33A /* GalleryCardCell.swift in Sources */,
Expand All @@ -1865,9 +1872,9 @@
ABF45AF025F3313D00ECB568 /* CommentsView.swift in Sources */,
ABC8356527B36E550091DCDB /* AutoPlayHandler.swift in Sources */,
ABBB2671279AFA61007B6149 /* EnvironmentKeys.swift in Sources */,
AB7BF2DA27AA78CF001865A3 /* Reducer_Extension.swift in Sources */,
AB7BF2DA27AA78CF001865A3 /* Reducer+.swift in Sources */,
ABBD2B602768D7AD0072AED2 /* GalleryRankingCell.swift in Sources */,
ABBB263A2792588F007B6149 /* TTProgressHUD_Extension.swift in Sources */,
ABBB263A2792588F007B6149 /* TTProgressHUD+.swift in Sources */,
AB7BF2D627AA3F4C001865A3 /* FileUtil.swift in Sources */,
AB0ABCB726C541A400AD970F /* WaveForm.swift in Sources */,
AB0929D62782A65F00F107CA /* GeneralSettingReducer.swift in Sources */,
Expand Down Expand Up @@ -1914,12 +1921,13 @@
ABA732DF25A852D800B3D9AB /* Filter.swift in Sources */,
AB7BF31E27ABE028001865A3 /* NSPersistentStoreCoordinator+SQLite.swift in Sources */,
ABC1FAB82642C37D00A9F352 /* NewDawnView.swift in Sources */,
EAC831E22B662BB300B518D5 /* NSPredicate+.swift in Sources */,
ABC732C527B9024500D47DA9 /* LiveText.swift in Sources */,
ABF45AE825F3313D00ECB568 /* LinkedText.swift in Sources */,
ABC732C727B90F0900D47DA9 /* LiveTextView.swift in Sources */,
AB0929B6277F043D00F107CA /* AccountSettingReducer.swift in Sources */,
ABD49D67277EAC90003D1A07 /* URLUtil.swift in Sources */,
ABBB2638278FBD2F007B6149 /* SwiftUINavigation_Extension.swift in Sources */,
ABBB2638278FBD2F007B6149 /* SwiftUINavigation+.swift in Sources */,
AB10117E26986B7D00C2C1A9 /* GalleryStateMO+CoreDataProperties.swift in Sources */,
AB26F59627ACCA1800AB3468 /* AppEnv.swift in Sources */,
ABF45AE525F3313D00ECB568 /* PostCommentView.swift in Sources */,
Expand Down
22 changes: 9 additions & 13 deletions EhPanda/App/Tools/Clients/AppDelegateClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,27 @@ import SwiftUI
import ComposableArchitecture

struct AppDelegateClient {
let setOrientation: (UIInterfaceOrientationMask) -> EffectTask<Never>
let setOrientationMask: (UIInterfaceOrientationMask) -> EffectTask<Never>
let setOrientation: (UIInterfaceOrientationMask) -> Void
let setOrientationMask: (UIInterfaceOrientationMask) -> Void
}

extension AppDelegateClient {
static let live: Self = .init(
setOrientation: { mask in
.fireAndForget {
DeviceUtil.keyWindow?.windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: mask))
}
DeviceUtil.keyWindow?.windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: mask))
},
setOrientationMask: { mask in
.fireAndForget {
AppDelegate.orientationMask = mask
}
AppDelegate.orientationMask = mask
}
)

func setPortraitOrientation() -> EffectTask<Never> {
func setPortraitOrientation() {
setOrientation(.portrait)
}
func setAllOrientationMask() -> EffectTask<Never> {
func setAllOrientationMask() {
setOrientationMask([.all])
}
func setPortraitOrientationMask() -> EffectTask<Never> {
func setPortraitOrientationMask() {
setOrientationMask([.portrait, .portraitUpsideDown])
}
}
Expand All @@ -55,8 +51,8 @@ extension DependencyValues {
// MARK: Test
extension AppDelegateClient {
static let noop: Self = .init(
setOrientation: { _ in .none },
setOrientationMask: { _ in .none }
setOrientation: { _ in },
setOrientationMask: { _ in }
)

static let unimplemented: Self = .init(
Expand Down
23 changes: 8 additions & 15 deletions EhPanda/App/Tools/Clients/AuthorizationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ComposableArchitecture

struct AuthorizationClient {
let passcodeNotSet: () -> Bool
let localAuthroize: (String) -> EffectTask<Bool>
let localAuthroize: (String) async -> Bool
}

extension AuthorizationClient {
Expand All @@ -21,21 +21,14 @@ extension AuthorizationClient {
return !LAContext().canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)
},
localAuthroize: { reason in
Future { promise in
let context = LAContext()
var error: NSError?
let context = LAContext()
var error: NSError?

if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { isSuccess, _ in
promise(.success(isSuccess))
}
} else {
promise(.success(false))
}
if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
return (try? await context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason)) ?? false
} else {
return false
}
.eraseToAnyPublisher()
.receive(on: DispatchQueue.main)
.eraseToEffect()
}
)
}
Expand All @@ -58,7 +51,7 @@ extension DependencyValues {
extension AuthorizationClient {
static let noop: Self = .init(
passcodeNotSet: { false },
localAuthroize: { _ in .none }
localAuthroize: { _ in false }
)

static let unimplemented: Self = .init(
Expand Down
26 changes: 11 additions & 15 deletions EhPanda/App/Tools/Clients/ClipboardClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import UniformTypeIdentifiers
struct ClipboardClient {
let url: () -> URL?
let changeCount: () -> Int
let saveText: (String) -> EffectTask<Never>
let saveImage: (UIImage, Bool) -> EffectTask<Never>
let saveText: (String) -> Void
let saveImage: (UIImage, Bool) -> Void
}

extension ClipboardClient {
Expand All @@ -29,21 +29,17 @@ extension ClipboardClient {
UIPasteboard.general.changeCount
},
saveText: { text in
.fireAndForget {
UIPasteboard.general.string = text
}
UIPasteboard.general.string = text
},
saveImage: { (image, isAnimated) in
.fireAndForget {
if isAnimated {
DispatchQueue.global(qos: .utility).async {
if let data = image.kf.data(format: .GIF) {
UIPasteboard.general.setData(data, forPasteboardType: UTType.gif.identifier)
}
if isAnimated {
DispatchQueue.global(qos: .utility).async {
if let data = image.kf.data(format: .GIF) {
UIPasteboard.general.setData(data, forPasteboardType: UTType.gif.identifier)
}
} else {
UIPasteboard.general.image = image
}
} else {
UIPasteboard.general.image = image
}
}
)
Expand All @@ -68,8 +64,8 @@ extension ClipboardClient {
static let noop: Self = .init(
url: { nil },
changeCount: { 0 },
saveText: { _ in .none },
saveImage: { _, _ in .none }
saveText: { _ in },
saveImage: { _, _ in }
)

static let unimplemented: Self = .init(
Expand Down
Loading

0 comments on commit e6a51c4

Please sign in to comment.