Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed Jul 16, 2021
2 parents 0f492be + 26ddd4d commit c54a661
Show file tree
Hide file tree
Showing 27 changed files with 943 additions and 150 deletions.
85 changes: 48 additions & 37 deletions EhPanda.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,19 @@
},
{
"package": "Kingfisher",
"repositoryURL": "https://github.com/tatsuz0u/Kingfisher",
"repositoryURL": "https://github.com/onevcat/Kingfisher.git",
"state": {
"branch": "Xcode-13-fix",
"revision": "ff901f1bbde87c923fb79bb084bb28a75d63b8dc",
"branch": "fix/xcode-13",
"revision": "f012224344f09421588a28e9f6259968e3574f8b",
"version": null
}
},
{
"package": "SDWebImage",
"repositoryURL": "https://github.com/SDWebImage/SDWebImage.git",
"state": {
"branch": null,
"revision": "76dd4b49110b8624317fc128e7fa0d8a252018bc",
"version": "5.11.1"
}
},
{
"package": "SDWebImageSwiftUI",
"repositoryURL": "https://github.com/SDWebImage/SDWebImageSwiftUI.git",
"state": {
"branch": null,
"revision": "cd8625b7cf11a97698e180d28bb7d5d357196678",
"version": "2.0.2"
}
},
{
"package": "SwiftyBeaver",
"repositoryURL": "https://github.com/tatsuz0u/SwiftyBeaver",
"repositoryURL": "https://github.com/SwiftyBeaver/SwiftyBeaver.git",
"state": {
"branch": "expose-calendar",
"revision": "e5d55d02b571aa9b8a833db519ca9d794380c7fc",
"branch": "master",
"revision": "607fc8d64388652135f4dcf6a1a340e3a0641088",
"version": null
}
},
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/App/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct Defaults {
struct URL {
// Domains
static var host: String {
galleryType == .ehentai ? ehentai : exhentai
galleryHost == .exhentai ? exhentai : ehentai
}
static let ehentai = "https://e-hentai.org/"
static let exhentai = "https://exhentai.org/"
Expand Down
31 changes: 19 additions & 12 deletions EhPanda/App/EhPandaApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
import SwiftUI
import Kingfisher
import SwiftyBeaver
import SDWebImageSwiftUI

@main
struct EhPandaApp: App {
@StateObject private var store = Store()

init() {
configureLogging()
configureWebImage()
clearImageCachesIfNeeded()
}

var body: some Scene {
WindowGroup {
Home()
Expand All @@ -44,9 +37,15 @@ private extension EhPandaApp {
}

func onStartTasks() {
syncGalleryHost()
configureLogging()
configureWebImage()
configureDomainFronting()
clearImageCachesIfNeeded()

DispatchQueue.main.async {
store.dispatch(.fetchFavoriteNames)
store.dispatch(.fetchUserInfo)
store.dispatch(.fetchFavoriteNames)
}
}
func onOpenURL(url: URL) {
Expand All @@ -58,6 +57,9 @@ private extension EhPandaApp {
}
}

func syncGalleryHost() {
setGalleryHost(with: setting.galleryHost)
}
func configureLogging() {
var file = FileDestination()
var console = ConsoleDestination()
Expand Down Expand Up @@ -97,16 +99,21 @@ private extension EhPandaApp {
}

func configureWebImage() {
let config = KingfisherManager.shared.downloader.sessionConfiguration
let config = KingfisherManager.shared
.downloader.sessionConfiguration
if setting.bypassSNIFiltering {
config.protocolClasses = [DFURLProtocol.self]
}
config.httpCookieStorage = HTTPCookieStorage.shared
KingfisherManager.shared.downloader.sessionConfiguration = config
}
func configureDomainFronting() {
DFManager.shared.dfState = setting.bypassSNIFiltering
? .activated : .notActivated
}
func clearImageCachesIfNeeded() {
let threshold = 200 * 1024 * 1024

if SDImageCache.shared.totalDiskSize() > threshold {
SDImageCache.shared.clearDisk()
}
KingfisherManager.shared.cache.calculateDiskStorageSize { result in
if case .success(let size) = result {
if size > threshold {
Expand Down
9 changes: 9 additions & 0 deletions EhPanda/App/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,12 @@ extension CGSize {
CGSize(width: left.width * right, height: left.height * right)
}
}

extension URLRequest {
mutating func setURLEncodedContentType() {
setValue(
"application/x-www-form-urlencoded",
forHTTPHeaderField: "Content-Type"
)
}
}
10 changes: 5 additions & 5 deletions EhPanda/App/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ var appBuild: String {
) as? String ?? "(null)"
}

var galleryType: GalleryType {
var galleryHost: GalleryHost {
let rawValue = UserDefaults
.standard
.string(forKey: "GalleryType") ?? ""
return GalleryType(rawValue: rawValue) ?? .ehentai
.string(forKey: "GalleryHost") ?? ""
return GalleryHost(rawValue: rawValue) ?? .ehentai
}

var appIconType: IconType {
Expand Down Expand Up @@ -282,8 +282,8 @@ func setDebugMode(with debugModeOn: Bool) {
UserDefaults.standard.set(debugModeOn, forKey: "debugModeOn")
}

func setGalleryType(with type: GalleryType) {
UserDefaults.standard.set(type.rawValue, forKey: "GalleryType")
func setGalleryHost(with host: GalleryHost) {
UserDefaults.standard.set(host.rawValue, forKey: "GalleryHost")
}

func clearGalleryType() {
Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
"Maximum scale factor" = "最大スケール係数";
"Double tap scale factor" = "ダブルタップスケール係数";

"Laboratory" = "ラボ";
"Bypass SNI Filtering" = "SNIフィルタリングを回避";

"About EhPanda" = "EhPandaについて";
"Version" = "バージョン";
"Contacts" = "連絡";
Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
"Maximum scale factor" = "最大缩放系数";
"Double tap scale factor" = "双击缩放系数";

"Laboratory" = "实验室";
"Bypass SNI Filtering" = "域前置绕过SNI阻断";

"About EhPanda" = "关于EhPanda";
"Version" = "版本";
"Contacts" = "联系";
Expand Down
3 changes: 3 additions & 0 deletions EhPanda/App/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
"Maximum scale factor" = "縮放上限";
"Double tap scale factor" = "雙擊縮放值";

"Laboratory" = "實驗室";
"Bypass SNI Filtering" = "域前置繞過SNI阻斷";

"About EhPanda" = "關於EhPanda";
"Version" = "版本";
"Contacts" = "聯絡";
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/Models/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ extension MangaTorrent: DateFormattable, CustomStringConvertible {

extension Category {
var color: Color {
Color(galleryType.rawValue + "/" + rawValue)
Color(galleryHost.rawValue + "/" + rawValue)
}
var value: Int {
switch self {
Expand Down
9 changes: 6 additions & 3 deletions EhPanda/Models/Setting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import Foundation

struct Setting: Codable {
// Account
var galleryType = GalleryType.ehentai {
var galleryHost = GalleryHost.ehentai {
didSet {
setGalleryType(with: galleryType)
setGalleryHost(with: galleryHost)
}
}
var showNewDawnGreeting = false
Expand Down Expand Up @@ -63,9 +63,12 @@ struct Setting: Codable {
}
}
}

// Laboratory
var bypassSNIFiltering = false
}

enum GalleryType: String, Codable {
enum GalleryHost: String, Codable {
case ehentai = "E-Hentai"
case exhentai = "ExHentai"

Expand Down
Loading

0 comments on commit c54a661

Please sign in to comment.