Skip to content

Commit 8199aeb

Browse files
committed
Extracted AuthClient and HUD in separate modules. Also some fixes for HomeView
1 parent 87d0ee9 commit 8199aeb

File tree

23 files changed

+283
-143
lines changed

23 files changed

+283
-143
lines changed

AuthClient/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

AuthClient/Package.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "AuthClient",
8+
platforms: [.iOS(.v15)],
9+
products: [
10+
// Products define the executables and libraries a package produces, making them visible to other packages.
11+
.library(
12+
name: "AuthClient",
13+
targets: ["AuthClient"]
14+
)
15+
],
16+
dependencies: [
17+
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.6.0"),
18+
.package(path: "../Utils")
19+
],
20+
targets: [
21+
// Targets are the basic building blocks of a package, defining a module or a test suite.
22+
// Targets can depend on other targets in this package and products from dependencies.
23+
.target(
24+
name: "AuthClient",
25+
dependencies: [
26+
.product(name: "Dependencies", package: "swift-dependencies"),
27+
.product(name: "Utils", package: "Utils")
28+
]
29+
),
30+
.testTarget(
31+
name: "AuthClientTests",
32+
dependencies: ["AuthClient"]
33+
),
34+
]
35+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// AuthClient.swift
3+
// Hanami
4+
//
5+
// Created by Oleg on 13/10/2022.
6+
//
7+
8+
import Dependencies
9+
import Combine
10+
import LocalAuthentication
11+
import Foundation
12+
import Utils
13+
14+
public extension DependencyValues {
15+
var authClient: AuthClient {
16+
get { self[AuthClient.self] }
17+
set { self[AuthClient.self] = newValue }
18+
}
19+
}
20+
21+
public struct AuthClient {
22+
public func makeAuth() async throws -> Bool {
23+
let context = LAContext()
24+
25+
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
26+
do {
27+
let success = try await context.evaluatePolicy(
28+
.deviceOwnerAuthenticationWithBiometrics,
29+
localizedReason: "To unlock the app"
30+
)
31+
return success
32+
} catch let authError as LAError {
33+
throw AppError.biometryError(authError)
34+
} catch {
35+
throw AppError.unknownError(error)
36+
}
37+
} else {
38+
return true
39+
}
40+
}
41+
}
42+
43+
extension AuthClient: DependencyKey {
44+
public static let liveValue = AuthClient()
45+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import XCTest
2+
@testable import AuthClient
3+
4+
final class AuthClientTests: XCTestCase {
5+
func testExample() throws {
6+
// XCTest Documentation
7+
// https://developer.apple.com/documentation/xctest
8+
9+
// Defining Test Cases and Test Methods
10+
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
11+
}
12+
}

HUD/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

HUD/Package.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "HUD",
8+
platforms: [.iOS(.v15)],
9+
products: [
10+
// Products define the executables and libraries a package produces, making them visible to other packages.
11+
.library(
12+
name: "HUD",
13+
targets: ["HUD"]),
14+
],
15+
dependencies: [
16+
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.6.0"),
17+
.package(path: "../UITheme")
18+
],
19+
targets: [
20+
// Targets are the basic building blocks of a package, defining a module or a test suite.
21+
// Targets can depend on other targets in this package and products from dependencies.
22+
.target(
23+
name: "HUD",
24+
dependencies: [
25+
.product(name: "Dependencies", package: "swift-dependencies"),
26+
.product(name: "UITheme", package: "UITheme"),
27+
]
28+
),
29+
.testTarget(
30+
name: "HUDTests",
31+
dependencies: ["HUD"]
32+
),
33+
]
34+
)
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66
//
77

88
import SwiftUI
9-
import ComposableArchitecture
9+
import Dependencies
10+
import UITheme
1011

11-
extension DependencyValues {
12-
var hudClient: HUDClient {
13-
get { self[HUDClient.self] }
14-
set { self[HUDClient.self] = newValue }
12+
public extension DependencyValues {
13+
var hud: HUD {
14+
get { self[HUD.self] }
15+
set { self[HUD.self] = newValue }
1516
}
1617
}
1718

18-
final class HUDClient: ObservableObject, DependencyKey {
19-
@Published var isPresented = false
20-
private(set) var message = ""
21-
private(set) var iconName: String?
22-
private(set) var backgroundColor: Color = .theme.red
19+
public final class HUD: ObservableObject, DependencyKey {
20+
@Published public var isPresented = false
21+
public private(set) var message = ""
22+
public private(set) var iconName: String?
23+
public private(set) var backgroundColor: Color = .theme.red
2324
private var workItem: DispatchWorkItem?
2425

25-
static let liveValue = HUDClient()
26+
public static let liveValue = HUD()
2627

2728
private init () { }
2829

29-
func show(message: String, iconName: String? = nil, hideAfter: Double = 2.5, backgroundColor: Color = .theme.red) {
30+
public func show(message: String, iconName: String? = nil, hideAfter: Double = 2.5, backgroundColor: Color = .theme.red) {
3031
self.message = message
3132
self.iconName = iconName
3233
self.backgroundColor = backgroundColor

HUD/Tests/HUDTests/HUDTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import XCTest
2+
@testable import HUD
3+
4+
final class HUDTests: XCTestCase {
5+
func testExample() throws {
6+
// XCTest Documentation
7+
// https://developer.apple.com/documentation/xctest
8+
9+
// Defining Test Cases and Test Methods
10+
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
11+
}
12+
}

Hanami.xcodeproj/project.pbxproj

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
081FF3032A79CF0800C444E4 /* Utils in Frameworks */ = {isa = PBXBuildFile; productRef = 081FF3022A79CF0800C444E4 /* Utils */; };
2020
081FF3052A79CF4A00C444E4 /* ModelKit in Frameworks */ = {isa = PBXBuildFile; productRef = 081FF3042A79CF4A00C444E4 /* ModelKit */; };
2121
081FF3072A79CF4F00C444E4 /* DataTypeExtensions in Frameworks */ = {isa = PBXBuildFile; productRef = 081FF3062A79CF4F00C444E4 /* DataTypeExtensions */; };
22-
0829E20828F896C30009A907 /* AuthClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0829E20728F896C30009A907 /* AuthClient.swift */; };
2322
0837E3512AEA90D9000963BA /* SearchClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0837E3502AEA90D9000963BA /* SearchClient.swift */; };
2423
0859979528F4C4170095422C /* SettingsFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0859979428F4C4170095422C /* SettingsFeature.swift */; };
2524
0859979728F4C4230095422C /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0859979628F4C4230095422C /* SettingsView.swift */; };
@@ -33,6 +32,8 @@
3332
08A8F45C290169FB001EECD9 /* AuthorFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A8F45B290169FB001EECD9 /* AuthorFeature.swift */; };
3433
08A8F45E2902A9F5001EECD9 /* AuthorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A8F45D2902A9F5001EECD9 /* AuthorView.swift */; };
3534
08B5C58E2AA5074E00ECE4B8 /* ImageClient in Frameworks */ = {isa = PBXBuildFile; productRef = 08B5C58D2AA5074E00ECE4B8 /* ImageClient */; };
35+
08B657E02B0509B100F0FF2A /* AuthClient in Frameworks */ = {isa = PBXBuildFile; productRef = 08B657DF2B0509B100F0FF2A /* AuthClient */; };
36+
08B657E32B050F0500F0FF2A /* HUD in Frameworks */ = {isa = PBXBuildFile; productRef = 08B657E22B050F0500F0FF2A /* HUD */; };
3637
08C69A8A2A7B109D006D6369 /* UIComponents in Frameworks */ = {isa = PBXBuildFile; productRef = 08C69A892A7B109D006D6369 /* UIComponents */; };
3738
08CF177A29B9F1F500A91E94 /* OnlineMangaViewLoaderFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08CF177929B9F1F500A91E94 /* OnlineMangaViewLoaderFeature.swift */; };
3839
08D7306C2AA2766900038543 /* Logger in Frameworks */ = {isa = PBXBuildFile; productRef = 08D7306B2AA2766900038543 /* Logger */; };
@@ -70,7 +71,6 @@
7071
2274193F2886EC6900ACAA24 /* DownloadsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2274193E2886EC6900ACAA24 /* DownloadsView.swift */; };
7172
228D8D55287B2DD000F988CC /* ChapterDetailsMO+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228D8D51287B2DD000F988CC /* ChapterDetailsMO+CoreDataProperties.swift */; };
7273
228D8D57287B2DD000F988CC /* MangaMO+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228D8D53287B2DD000F988CC /* MangaMO+CoreDataProperties.swift */; };
73-
228DD05028A5278300F70162 /* HUDClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228DD04F28A5278300F70162 /* HUDClient.swift */; };
7474
228FA49D288DBB5500369529 /* CacheClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228FA49C288DBB5500369529 /* CacheClient.swift */; };
7575
229F8D8B282DB34C00761054 /* RootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229F8D8A282DB34C00761054 /* RootView.swift */; };
7676
229F8D90282DB5E400761054 /* RootFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229F8D8F282DB5E400761054 /* RootFeature.swift */; };
@@ -131,7 +131,6 @@
131131
080D1DC6294FF685008B813C /* SearchRequestMO+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchRequestMO+CoreDataClass.swift"; sourceTree = "<group>"; };
132132
080D1DC7294FF685008B813C /* SearchRequestMO+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchRequestMO+CoreDataProperties.swift"; sourceTree = "<group>"; };
133133
080D1DCD294FFAE6008B813C /* SearchRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRequest.swift; sourceTree = "<group>"; };
134-
0829E20728F896C30009A907 /* AuthClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthClient.swift; sourceTree = "<group>"; };
135134
0837E3502AEA90D9000963BA /* SearchClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchClient.swift; sourceTree = "<group>"; };
136135
0859979428F4C4170095422C /* SettingsFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsFeature.swift; sourceTree = "<group>"; };
137136
0859979628F4C4230095422C /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
@@ -145,6 +144,8 @@
145144
08A8F45B290169FB001EECD9 /* AuthorFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorFeature.swift; sourceTree = "<group>"; };
146145
08A8F45D2902A9F5001EECD9 /* AuthorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorView.swift; sourceTree = "<group>"; };
147146
08B5C58C2AA5071500ECE4B8 /* ImageClient */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = ImageClient; sourceTree = "<group>"; };
147+
08B657DE2B05092900F0FF2A /* AuthClient */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = AuthClient; sourceTree = "<group>"; };
148+
08B657E12B050E3E00F0FF2A /* HUD */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = HUD; sourceTree = "<group>"; };
148149
08C237CB2A322646003E122D /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
149150
08CF177929B9F1F500A91E94 /* OnlineMangaViewLoaderFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnlineMangaViewLoaderFeature.swift; sourceTree = "<group>"; };
150151
08D358E02A79BB7F001406D1 /* ModelKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = ModelKit; sourceTree = "<group>"; };
@@ -186,7 +187,6 @@
186187
2274193E2886EC6900ACAA24 /* DownloadsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadsView.swift; sourceTree = "<group>"; };
187188
228D8D51287B2DD000F988CC /* ChapterDetailsMO+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ChapterDetailsMO+CoreDataProperties.swift"; sourceTree = "<group>"; };
188189
228D8D53287B2DD000F988CC /* MangaMO+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MangaMO+CoreDataProperties.swift"; sourceTree = "<group>"; };
189-
228DD04F28A5278300F70162 /* HUDClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HUDClient.swift; sourceTree = "<group>"; };
190190
228FA49C288DBB5500369529 /* CacheClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheClient.swift; sourceTree = "<group>"; };
191191
229DA9EE28725F5E00C6EF91 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
192192
229F8D8A282DB34C00761054 /* RootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootView.swift; sourceTree = "<group>"; };
@@ -216,12 +216,14 @@
216216
08C69A8A2A7B109D006D6369 /* UIComponents in Frameworks */,
217217
08E206FD2AE6BCE3005CF305 /* Kingfisher in Frameworks */,
218218
087DB9E92A79C766002D0277 /* PopupView in Frameworks */,
219+
08B657E32B050F0500F0FF2A /* HUD in Frameworks */,
219220
081FF3052A79CF4A00C444E4 /* ModelKit in Frameworks */,
220221
081FF3072A79CF4F00C444E4 /* DataTypeExtensions in Frameworks */,
221222
087DB9E02A79C738002D0277 /* Cache in Frameworks */,
222223
08E621902A7B0E6A001B0318 /* UITheme in Frameworks */,
223224
087DB9EF2A79CA00002D0277 /* ComposableArchitecture in Frameworks */,
224225
087DB9EC2A79C774002D0277 /* WrappingHStack in Frameworks */,
226+
08B657E02B0509B100F0FF2A /* AuthClient in Frameworks */,
225227
08E6218C2A79D138001B0318 /* UIExtensions in Frameworks */,
226228
081FF3032A79CF0800C444E4 /* Utils in Frameworks */,
227229
080B17BE2AE87CA2002F780C /* SettingsClient in Frameworks */,
@@ -440,6 +442,8 @@
440442
224C656F2827204000AAEF2E = {
441443
isa = PBXGroup;
442444
children = (
445+
08B657E12B050E3E00F0FF2A /* HUD */,
446+
08B657DE2B05092900F0FF2A /* AuthClient */,
443447
080B17BC2AE87B95002F780C /* SettingsClient */,
444448
08B5C58C2AA5071500ECE4B8 /* ImageClient */,
445449
086E3A872AA274E300FE65C8 /* Logger */,
@@ -500,8 +504,6 @@
500504
228FA49C288DBB5500369529 /* CacheClient.swift */,
501505
2225265E28B1627E009F6FA3 /* HapticClient.swift */,
502506
22D0CA6F287DE15F005D06ED /* HomeClient.swift */,
503-
0829E20728F896C30009A907 /* AuthClient.swift */,
504-
228DD04F28A5278300F70162 /* HUDClient.swift */,
505507
);
506508
path = Clients;
507509
sourceTree = "<group>";
@@ -640,6 +642,8 @@
640642
08B5C58D2AA5074E00ECE4B8 /* ImageClient */,
641643
08E206FC2AE6BCE3005CF305 /* Kingfisher */,
642644
080B17BD2AE87CA2002F780C /* SettingsClient */,
645+
08B657DF2B0509B100F0FF2A /* AuthClient */,
646+
08B657E22B050F0500F0FF2A /* HUD */,
643647
);
644648
productName = Smuggler;
645649
productReference = 224C65782827204100AAEF2E /* Hanami - Manga Reader.app */;
@@ -821,7 +825,6 @@
821825
0837E3512AEA90D9000963BA /* SearchClient.swift in Sources */,
822826
22F4A85628AB29C9008C11A7 /* ChapterFeature.swift in Sources */,
823827
22D0CA70287DE15F005D06ED /* HomeClient.swift in Sources */,
824-
228DD05028A5278300F70162 /* HUDClient.swift in Sources */,
825828
08A8F45E2902A9F5001EECD9 /* AuthorView.swift in Sources */,
826829
229F8D90282DB5E400761054 /* RootFeature.swift in Sources */,
827830
08E0B078293EC0C60021D5EC /* ChapterLoaderFeature.swift in Sources */,
@@ -846,7 +849,6 @@
846849
0859979528F4C4170095422C /* SettingsFeature.swift in Sources */,
847850
080D1DCE294FFAE6008B813C /* SearchRequest.swift in Sources */,
848851
088934AF29C7365500AA81D4 /* MangaChapterLoaderFeature.swift in Sources */,
849-
0829E20828F896C30009A907 /* AuthClient.swift in Sources */,
850852
22F4A85428AB29C9008C11A7 /* VolumeTabView.swift in Sources */,
851853
);
852854
runOnlyForDeploymentPostprocessing = 0;
@@ -1281,6 +1283,14 @@
12811283
isa = XCSwiftPackageProductDependency;
12821284
productName = ImageClient;
12831285
};
1286+
08B657DF2B0509B100F0FF2A /* AuthClient */ = {
1287+
isa = XCSwiftPackageProductDependency;
1288+
productName = AuthClient;
1289+
};
1290+
08B657E22B050F0500F0FF2A /* HUD */ = {
1291+
isa = XCSwiftPackageProductDependency;
1292+
productName = HUD;
1293+
};
12841294
08C69A892A7B109D006D6369 /* UIComponents */ = {
12851295
isa = XCSwiftPackageProductDependency;
12861296
productName = UIComponents;
Binary file not shown.

0 commit comments

Comments
 (0)