Skip to content

Commit

Permalink
Merge pull request #372 from Jimmy-Prime/jimmy/fix-most-warnings
Browse files Browse the repository at this point in the history
Fix most warnings
  • Loading branch information
chihchy authored May 27, 2024
2 parents 6842553 + 4c4163b commit 69f316b
Show file tree
Hide file tree
Showing 44 changed files with 998 additions and 913 deletions.
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) -> Effect<Never>
let setOrientationMask: (UIInterfaceOrientationMask) -> Effect<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() -> Effect<Never> {
func setPortraitOrientation() {
setOrientation(.portrait)
}
func setAllOrientationMask() -> Effect<Never> {
func setAllOrientationMask() {
setOrientationMask([.all])
}
func setPortraitOrientationMask() -> Effect<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: 10 additions & 13 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) -> Effect<Bool>
let localAuthroize: (String) async -> Bool
}

extension AuthorizationClient {
Expand All @@ -21,20 +21,17 @@ extension AuthorizationClient {
return !LAContext().canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)
},
localAuthroize: { reason in
.publisher {
Future { promise in
let context = LAContext()
var error: NSError?
await withCheckedContinuation { continuation in
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) {
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { isSuccess, _ in
continuation.resume(returning: isSuccess)
}
} else {
continuation.resume(returning: false)
}
.receive(on: DispatchQueue.main)
}
}
)
Expand All @@ -58,7 +55,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
28 changes: 12 additions & 16 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) -> Effect<Never>
let saveImage: (UIImage, Bool) -> Effect<Never>
let saveText: (String) -> Void
let saveImage: (UIImage, Bool) -> Void
}

extension ClipboardClient {
Expand All @@ -29,22 +29,18 @@ extension ClipboardClient {
UIPasteboard.general.changeCount
},
saveText: { text in
.run(operation: { _ in
UIPasteboard.general.string = text
})
UIPasteboard.general.string = text
},
saveImage: { (image, isAnimated) in
.run(operation: { _ in
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
168 changes: 73 additions & 95 deletions EhPanda/App/Tools/Clients/CookieClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import ComposableArchitecture

struct CookieClient {
let clearAll: () -> Effect<Never>
let clearAll: () -> Void
let getCookie: (URL, String) -> CookieValue
private let removeCookie: (URL, String) -> Void
private let checkExistence: (URL, String) -> Bool
Expand All @@ -19,13 +19,11 @@ struct CookieClient {
extension CookieClient {
static let live: Self = .init(
clearAll: {
.run(operation: { _ in
if let historyCookies = HTTPCookieStorage.shared.cookies {
historyCookies.forEach {
HTTPCookieStorage.shared.deleteCookie($0)
}
if let historyCookies = HTTPCookieStorage.shared.cookies {
historyCookies.forEach {
HTTPCookieStorage.shared.deleteCookie($0)
}
})
}
},
getCookie: { url, key in
var value = CookieValue(
Expand Down Expand Up @@ -108,14 +106,12 @@ extension CookieClient {
guard let cookie = newCookie else { return }
HTTPCookieStorage.shared.setCookie(cookie)
}
func setOrEditCookie(for url: URL, key: String, value: String) -> Effect<Never> {
.run(operation: { _ in
if checkExistence(url, key) {
editCookie(for: url, key: key, value: value)
} else {
setCookie(for: url, key: key, value: value)
}
})
func setOrEditCookie(for url: URL, key: String, value: String) {
if checkExistence(url, key) {
editCookie(for: url, key: key, value: value)
} else {
setCookie(for: url, key: key, value: value)
}
}
}

Expand All @@ -138,35 +134,29 @@ extension CookieClient {
&& !getCookie(url, Defaults.Cookie.ipbPassHash).rawValue.isEmpty
&& getCookie(url, Defaults.Cookie.igneous).rawValue.isEmpty
}
func removeYay() -> Effect<Never> {
.run(operation: { _ in
removeCookie(Defaults.URL.exhentai, Defaults.Cookie.yay)
removeCookie(Defaults.URL.sexhentai, Defaults.Cookie.yay)
})
func removeYay() {
removeCookie(Defaults.URL.exhentai, Defaults.Cookie.yay)
removeCookie(Defaults.URL.sexhentai, Defaults.Cookie.yay)
}
func syncExCookies() -> Effect<Never> {
.merge(
[
Defaults.Cookie.ipbMemberId,
Defaults.Cookie.ipbPassHash,
Defaults.Cookie.igneous
]
.map {
setOrEditCookie(
for: Defaults.URL.sexhentai,
key: $0,
value: getCookie(Defaults.URL.exhentai, $0).rawValue
)
}
)
func syncExCookies() {
let cookies = [
Defaults.Cookie.ipbMemberId,
Defaults.Cookie.ipbPassHash,
Defaults.Cookie.igneous
]
for cookie in cookies {
setOrEditCookie(
for: Defaults.URL.sexhentai,
key: cookie,
value: getCookie(Defaults.URL.exhentai, cookie).rawValue
)
}
}
func ignoreOffensive() -> Effect<Never> {
.merge(
setOrEditCookie(for: Defaults.URL.ehentai, key: Defaults.Cookie.ignoreOffensive, value: "1"),
setOrEditCookie(for: Defaults.URL.exhentai, key: Defaults.Cookie.ignoreOffensive, value: "1")
)
func ignoreOffensive() {
setOrEditCookie(for: Defaults.URL.ehentai, key: Defaults.Cookie.ignoreOffensive, value: "1")
setOrEditCookie(for: Defaults.URL.exhentai, key: Defaults.Cookie.ignoreOffensive, value: "1")
}
func fulfillAnotherHostField() -> Effect<Never> {
func fulfillAnotherHostField() {
let ehURL = Defaults.URL.ehentai
let exURL = Defaults.URL.exhentai
let memberIdKey = Defaults.Cookie.ipbMemberId
Expand All @@ -177,17 +167,11 @@ extension CookieClient {
let exPassHash = getCookie(exURL, passHashKey).rawValue

if !ehMemberId.isEmpty && !ehPassHash.isEmpty && (exMemberId.isEmpty || exPassHash.isEmpty) {
return .merge(
setOrEditCookie(for: exURL, key: memberIdKey, value: ehMemberId),
setOrEditCookie(for: exURL, key: passHashKey, value: ehPassHash)
)
setOrEditCookie(for: exURL, key: memberIdKey, value: ehMemberId)
setOrEditCookie(for: exURL, key: passHashKey, value: ehPassHash)
} else if !exMemberId.isEmpty && !exPassHash.isEmpty && (ehMemberId.isEmpty || ehPassHash.isEmpty) {
return .merge(
setOrEditCookie(for: ehURL, key: memberIdKey, value: exMemberId),
setOrEditCookie(for: ehURL, key: passHashKey, value: exPassHash)
)
} else {
return .none
setOrEditCookie(for: ehURL, key: memberIdKey, value: exMemberId)
setOrEditCookie(for: ehURL, key: passHashKey, value: exPassHash)
}
}
func loadCookiesState(host: GalleryHost) -> CookiesState {
Expand Down Expand Up @@ -218,55 +202,49 @@ extension CookieClient {

// MARK: SetCookies
extension CookieClient {
func setCookies(state: CookiesState, trimsSpaces: Bool = true) -> Effect<Never> {
let effects: [Effect<Never>] = state.allCases
.flatMap { subState in
state.host.cookieURLs
.map {
setOrEditCookie(
for: $0,
key: subState.key,
value: trimsSpaces
? subState.editingText .trimmingCharacters(in: .whitespaces) : subState.editingText
)
}
func setCookies(state: CookiesState, trimsSpaces: Bool = true) {
for subState in state.allCases {
for cookie in state.host.cookieURLs {
setOrEditCookie(
for: cookie,
key: subState.key,
value: trimsSpaces
? subState.editingText .trimmingCharacters(in: .whitespaces) : subState.editingText
)
}
return effects.isEmpty ? .none : .merge(effects)
}

}
func setCredentials(response: HTTPURLResponse) -> Effect<Never> {
.run(operation: { _ in
guard let setString = response.allHeaderFields["Set-Cookie"] as? String else { return }
setString.components(separatedBy: ", ")
.flatMap { $0.components(separatedBy: "; ") }.forEach { value in
[Defaults.URL.ehentai, Defaults.URL.exhentai].forEach { url in
[
Defaults.Cookie.ipbMemberId,
Defaults.Cookie.ipbPassHash,
Defaults.Cookie.igneous
].forEach { key in
guard !(url == Defaults.URL.ehentai && key == Defaults.Cookie.igneous),
let range = value.range(of: "\(key)=") else { return }
setCookie(for: url, key: key, value: String(value[range.upperBound...]))
}
func setCredentials(response: HTTPURLResponse) {
guard let setString = response.allHeaderFields["Set-Cookie"] as? String else { return }
setString.components(separatedBy: ", ")
.flatMap { $0.components(separatedBy: "; ") }.forEach { value in
[Defaults.URL.ehentai, Defaults.URL.exhentai].forEach { url in
[
Defaults.Cookie.ipbMemberId,
Defaults.Cookie.ipbPassHash,
Defaults.Cookie.igneous
].forEach { key in
guard !(url == Defaults.URL.ehentai && key == Defaults.Cookie.igneous),
let range = value.range(of: "\(key)=") else { return }
setCookie(for: url, key: key, value: String(value[range.upperBound...]))
}
}
})
}
}
func setSkipServer(response: HTTPURLResponse) -> Effect<Never> {
.run(operation: { _ in
guard let setString = response.allHeaderFields["Set-Cookie"] as? String else { return }
setString.components(separatedBy: ", ")
.flatMap { $0.components(separatedBy: "; ") }
.forEach { value in
let key = Defaults.Cookie.skipServer
if let range = value.range(of: "\(key)=") {
setCookie(
for: Defaults.URL.host, key: key,
value: String(value[range.upperBound...]), path: "/s/"
)
}
func setSkipServer(response: HTTPURLResponse) {
guard let setString = response.allHeaderFields["Set-Cookie"] as? String else { return }
setString.components(separatedBy: ", ")
.flatMap { $0.components(separatedBy: "; ") }
.forEach { value in
let key = Defaults.Cookie.skipServer
if let range = value.range(of: "\(key)=") {
setCookie(
for: Defaults.URL.host, key: key,
value: String(value[range.upperBound...]), path: "/s/"
)
}
})
}
}
}

Expand All @@ -287,7 +265,7 @@ extension DependencyValues {
// MARK: Test
extension CookieClient {
static let noop: Self = .init(
clearAll: { .none },
clearAll: {},
getCookie: { _, _ in .empty },
removeCookie: { _, _ in },
checkExistence: { _, _ in false },
Expand Down
Loading

0 comments on commit 69f316b

Please sign in to comment.