From 16a3549c0e674e0ac30d74d73db0cb4dc330fbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=9F=E3=81=A4=E3=81=9D=E3=82=99=E3=81=86?= Date: Mon, 12 Jul 2021 15:30:39 +0800 Subject: [PATCH] feat: Links host redirection feature --- EhPanda/App/Extensions.swift | 16 +++++++----- EhPanda/App/ja.lproj/Localizable.strings | 16 +++++++----- EhPanda/App/zh-Hans.lproj/Localizable.strings | 16 +++++++----- EhPanda/App/zh-Hant.lproj/Localizable.strings | 16 +++++++----- EhPanda/DataFlow/Store.swift | 12 ++++++++- EhPanda/DataFlow/StoreAccessor.swift | 4 +-- EhPanda/Models/Setting.swift | 11 ++++---- EhPanda/View/Detail/DetailView.swift | 12 ++++----- EhPanda/View/Home/HomeView.swift | 4 +-- EhPanda/View/Home/SlideMenu.swift | 4 +-- .../View/Setting/AppearanceSettingView.swift | 14 +++++----- EhPanda/View/Setting/GeneralSettingView.swift | 26 +++++++++++-------- EhPanda/View/Tools/MangaSummaryRow.swift | 6 ++--- 13 files changed, 91 insertions(+), 66 deletions(-) diff --git a/EhPanda/App/Extensions.swift b/EhPanda/App/Extensions.swift index 5252e14b..47ed0a11 100644 --- a/EhPanda/App/Extensions.swift +++ b/EhPanda/App/Extensions.swift @@ -5,10 +5,8 @@ // Created by 荒木辰造 on R 3/01/08. // -import UIKit import SwiftUI import Combine -import Foundation import SwiftyBeaver extension Dictionary where Key == String, Value == String { @@ -135,9 +133,12 @@ extension String { } func safeURL() -> URL { - isValidURL - ? URL(string: self)! - : URL(string: Defaults.URL.ehentai)! + if isValidURL { + return URL(string: self).forceUnwrapped + } else { + SwiftyBeaver.error("Invalid URL, redirect to default host...") + return URL(string: Defaults.URL.ehentai).forceUnwrapped + } } var isValidURL: Bool { @@ -234,7 +235,10 @@ extension Optional { } SwiftyBeaver.error( "Failed in force unwrapping..." - + "Shutting down now..." + + "Shutting down now...", + context: [ + "type": Wrapped.self + ] ) fatalError() } diff --git a/EhPanda/App/ja.lproj/Localizable.strings b/EhPanda/App/ja.lproj/Localizable.strings index 849e4c32..bfcebb13 100644 --- a/EhPanda/App/ja.lproj/Localizable.strings +++ b/EhPanda/App/ja.lproj/Localizable.strings @@ -77,27 +77,29 @@ "Are you sure to logout?" = "本当にログアウトしますか?"; "Are you sure to clear?" = "本当に削除しますか?"; "Clear" = "削除"; +"Copy cookies" = "クッキーをコピー"; "General" = "一般"; -"Close slide menu after selection" = "選択後スライドメニューを閉じる"; -"Detect link from the clipboard" = "クリップボードからリンクを探知"; -"Allows detection even when no change" = "変化なしの場合でも探知を有効化"; +"Closes slide menu after selection" = "選択後スライドメニューを閉じる"; +"Navigation" = "ナビゲーション"; +"Redirects links to the selected host" = "リンクを選択されたホストへリダイレクト"; +"Detects links from the clipboard" = "クリップボードからリンクを探知"; +"Allows detection even when no changes" = "変化なしの場合でも探知を有効化"; "Security" = "セキュリティ"; "Auto-Lock" = "自動ロック"; "App switcher blur" = "アプリスイッチャーぼかし"; "Cache" = "キャッシュ"; "Clear image caches" = "画像キャッシュを削除"; -"Copy cookies" = "クッキーをコピー"; "Appearance" = "外観"; "Global" = "全般"; "Theme" = "テーマ"; "Tint Color" = "テーマの色"; "App Icon" = "アプリアイコン"; -"Translate category" = "カテゴリーを訳す"; +"Translates category" = "カテゴリーを訳す"; "List" = "リスト"; -"Show tags in list" = "リストでタグを表示"; -"Set maximum number of tags" = "リストでのタグ数を制限"; +"Shows tags in list" = "リストでタグを表示"; +"Sets maximum number of tags" = "リストでのタグ数を制限"; "Maximum number of tags" = "タグ数上限"; "Reading" = "閲覧"; diff --git a/EhPanda/App/zh-Hans.lproj/Localizable.strings b/EhPanda/App/zh-Hans.lproj/Localizable.strings index cee1b1c1..1757e0bb 100644 --- a/EhPanda/App/zh-Hans.lproj/Localizable.strings +++ b/EhPanda/App/zh-Hans.lproj/Localizable.strings @@ -77,27 +77,29 @@ "Are you sure to logout?" = "确定要退出登录吗?"; "Are you sure to clear?" = "确定要清空吗?"; "Clear" = "清空"; +"Copy cookies" = "复制Cookies"; "General" = "一般"; -"Close slide menu after selection" = "选择后关闭侧边栏"; -"Detect link from the clipboard" = "从剪切板检测链接"; -"Allows detection even when no change" = "无变化时依旧检测"; +"Closes slide menu after selection" = "选择后关闭侧边栏"; +"Navigation" = "导航"; +"Redirects links to the selected host" = "重定向链接到选定的站点"; +"Detects links from the clipboard" = "从剪切板检测链接"; +"Allows detection even when no changes" = "无变化时依旧检测"; "Security" = "安全"; "Auto-Lock" = "自动锁定"; "App switcher blur" = "在应用切换器中模糊处理"; "Cache" = "缓存"; "Clear image caches" = "清空图片缓存"; -"Copy cookies" = "复制Cookies"; "Appearance" = "外观"; "Global" = "全局"; "Theme" = "主题"; "Tint Color" = "主题色"; "App Icon" = "应用图标"; -"Translate category" = "显示分类的翻译版本"; +"Translates category" = "显示分类的翻译版本"; "List" = "列表"; -"Show tags in list" = "在列表中显示标签"; -"Set maximum number of tags" = "设置标签数量上限"; +"Shows tags in list" = "在列表中显示标签"; +"Sets maximum number of tags" = "设置标签数量上限"; "Maximum number of tags" = "标签数量上限"; "Reading" = "阅读"; diff --git a/EhPanda/App/zh-Hant.lproj/Localizable.strings b/EhPanda/App/zh-Hant.lproj/Localizable.strings index ddbd64a7..bc24beea 100644 --- a/EhPanda/App/zh-Hant.lproj/Localizable.strings +++ b/EhPanda/App/zh-Hant.lproj/Localizable.strings @@ -77,27 +77,29 @@ "Are you sure to logout?" = "確定要登出嗎?"; "Are you sure to clear?" = "確定要清空嗎?"; "Clear" = "清空"; +"Copy cookies" = "複製Cookies"; "General" = "一般"; -"Close slide menu after selection" = "選擇後關閉側邊選單"; -"Detect link from the clipboard" = "偵測剪貼簿中的連結"; -"Allows detection even when no change" = "沒有變化時仍然偵測"; +"Closes slide menu after selection" = "選擇後關閉側邊選單"; +"Navigation" = "導航"; +"Redirects links to the selected host" = "重定向連結到選定的站點"; +"Detects links from the clipboard" = "偵測剪貼簿中的連結"; +"Allows detection even when no changes" = "沒有變化時仍然偵測"; "Security" = "安全"; "Auto-Lock" = "自動鎖定"; "App switcher blur" = "模糊多工處理中的預覽"; "Cache" = "快取"; "Clear image caches" = "清空圖片快取"; -"Copy cookies" = "複製Cookies"; "Appearance" = "外觀"; "Global" = "全局"; "Theme" = "主題"; "Tint Color" = "主題色"; "App Icon" = "應用圖標"; -"Translate category" = "翻譯分類"; +"Translates category" = "翻譯分類"; "List" = "列表"; -"Show tags in list" = "在列表中顯示標籤"; -"Set maximum number of tags" = "設定標籤數量上限"; +"Shows tags in list" = "在列表中顯示標籤"; +"Sets maximum number of tags" = "設定標籤數量上限"; "Maximum number of tags" = "標籤數量上限"; "Reading" = "閱讀"; diff --git a/EhPanda/DataFlow/Store.swift b/EhPanda/DataFlow/Store.swift index 7f56dc50..95632861 100644 --- a/EhPanda/DataFlow/Store.swift +++ b/EhPanda/DataFlow/Store.swift @@ -146,12 +146,22 @@ final class Store: ObservableObject { appState.settings.user.favoriteNames = names } - case .fetchMangaItemReverse(let detailURL): + case .fetchMangaItemReverse(var detailURL): appState.environment.mangaItemReverseLoadFailed = false if appState.environment.mangaItemReverseLoading { break } appState.environment.mangaItemReverseLoading = true + if appState.settings.setting.redirectsLinksToSelectedHost { + detailURL = detailURL.replacingOccurrences( + of: Defaults.URL.ehentai, + with: Defaults.URL.host + ) + .replacingOccurrences( + of: Defaults.URL.exhentai, + with: Defaults.URL.host + ) + } appCommand = FetchMangaItemReverseCommand(detailURL: detailURL) case .fetchMangaItemReverseDone(let result): appState.environment.mangaItemReverseLoading = false diff --git a/EhPanda/DataFlow/StoreAccessor.swift b/EhPanda/DataFlow/StoreAccessor.swift index 0921e2a0..3fe7e255 100644 --- a/EhPanda/DataFlow/StoreAccessor.swift +++ b/EhPanda/DataFlow/StoreAccessor.swift @@ -82,8 +82,8 @@ extension StoreAccessor { var autoLockPolicy: AutoLockPolicy { setting.autoLockPolicy } - var detectGalleryFromPasteboard: Bool { - setting.detectGalleryFromPasteboard + var detectsLinksFromPasteboard: Bool { + setting.detectsLinksFromPasteboard } } diff --git a/EhPanda/Models/Setting.swift b/EhPanda/Models/Setting.swift index a9c3ff17..1d469795 100644 --- a/EhPanda/Models/Setting.swift +++ b/EhPanda/Models/Setting.swift @@ -19,9 +19,10 @@ struct Setting: Codable { var showNewDawnGreeting = false // General - var detectGalleryFromPasteboard = false - var allowsDetectionWhenNoChange = false - var closeSlideMenuAfterSelection = true + var closesSlideMenuAfterSelection = true + var redirectsLinksToSelectedHost = false + var detectsLinksFromPasteboard = false + var allowsDetectionWhenNoChanges = false var diskImageCacheSize = "0 KB" var allowsResignActiveBlur = true var autoLockPolicy: AutoLockPolicy = .never @@ -40,8 +41,8 @@ struct Setting: Codable { var preferredColorScheme: PreferredColorScheme = .automatic var accentColor: Color = .blue var appIconType: IconType = .default - var translateCategory = true - var showSummaryRowTags = false + var translatesCategory = true + var showsSummaryRowTags = false var summaryRowTagsMaximumActivated = false var summaryRowTagsMaximum: Int = 5 diff --git a/EhPanda/View/Detail/DetailView.swift b/EhPanda/View/Detail/DetailView.swift index 6a43bbf2..9d01efae 100644 --- a/EhPanda/View/Detail/DetailView.swift +++ b/EhPanda/View/Detail/DetailView.swift @@ -39,8 +39,8 @@ struct DetailView: View, StoreAccessor, PersistenceAccessor { VStack(spacing: 30) { HeaderView( manga: manga, detail: detail, - translateCategory: setting - .translateCategory, + translatesCategory: setting + .translatesCategory, favoriteNames: user.favoriteNames, addFavAction: addFavorite, deleteFavAction: deleteFavorite @@ -229,7 +229,7 @@ private extension DetailView { private struct HeaderView: View { private let manga: Manga private let detail: MangaDetail - private let translateCategory: Bool + private let translatesCategory: Bool private let favoriteNames: [Int: String]? private let addFavAction: (Int) -> Void private let deleteFavAction: () -> Void @@ -237,14 +237,14 @@ private struct HeaderView: View { init( manga: Manga, detail: MangaDetail, - translateCategory: Bool, + translatesCategory: Bool, favoriteNames: [Int: String]?, addFavAction: @escaping (Int) -> Void, deleteFavAction: @escaping () -> Void ) { self.manga = manga self.detail = detail - self.translateCategory = translateCategory + self.translatesCategory = translatesCategory self.favoriteNames = favoriteNames self.addFavAction = addFavAction self.deleteFavAction = deleteFavAction @@ -339,7 +339,7 @@ private extension HeaderView { } } var category: String { - if translateCategory { + if translatesCategory { return manga.category.rawValue.localized() } else { return manga.category.rawValue diff --git a/EhPanda/View/Home/HomeView.swift b/EhPanda/View/Home/HomeView.swift index b2532d2d..272788f7 100644 --- a/EhPanda/View/Home/HomeView.swift +++ b/EhPanda/View/Home/HomeView.swift @@ -142,7 +142,7 @@ private extension HomeView { } var hasJumpPermission: Bool { - detectGalleryFromPasteboard + detectsLinksFromPasteboard && viewControllersCount == 1 } var suggestions: [String] { @@ -365,7 +365,7 @@ private extension HomeView { store.dispatch(.replaceMangaCommentJumpID(gid: gid)) } func getPasteboardLinkIfAllowed() -> URL? { - if setting.allowsDetectionWhenNoChange { + if setting.allowsDetectionWhenNoChanges { return getPasteboardLink() } else { let currentChangeCount = UIPasteboard.general.changeCount diff --git a/EhPanda/View/Home/SlideMenu.swift b/EhPanda/View/Home/SlideMenu.swift index a3bf9bfe..d498590f 100644 --- a/EhPanda/View/Home/SlideMenu.swift +++ b/EhPanda/View/Home/SlideMenu.swift @@ -81,7 +81,7 @@ private extension SlideMenu { store.dispatch(.toggleHomeList(type: item)) impactFeedback(style: .soft) - if setting.closeSlideMenuAfterSelection { + if setting.closesSlideMenuAfterSelection { performTransition(offset: -width) } } @@ -90,7 +90,7 @@ private extension SlideMenu { store.dispatch(.toggleHomeViewSheet(state: .setting)) } func onFavoritesIndexChange(_ : Int) { - if setting.closeSlideMenuAfterSelection { + if setting.closesSlideMenuAfterSelection { performTransition(offset: -width) } } diff --git a/EhPanda/View/Setting/AppearanceSettingView.swift b/EhPanda/View/Setting/AppearanceSettingView.swift index b50e72c1..ff860cf9 100644 --- a/EhPanda/View/Setting/AppearanceSettingView.swift +++ b/EhPanda/View/Setting/AppearanceSettingView.swift @@ -47,22 +47,22 @@ struct AppearanceSettingView: View, StoreAccessor { ColorPicker("Tint Color", selection: settingBinding.accentColor) Button("App Icon", action: onAppIconButtonTap) .foregroundStyle(.primary).withArrow() - Toggle("Translate category", isOn: settingBinding.translateCategory) + Toggle("Translates category", isOn: settingBinding.translatesCategory) .disabled(Locale.current.languageCode == "en") } Section(header: Text("List")) { - Toggle(isOn: settingBinding.showSummaryRowTags) { + Toggle(isOn: settingBinding.showsSummaryRowTags) { HStack { - Text("Show tags in list") + Text("Shows tags in list") Image(systemName: "exclamationmark.triangle.fill") - .opacity(setting.showSummaryRowTags ? 1 : 0) + .opacity(setting.showsSummaryRowTags ? 1 : 0) .foregroundStyle(.yellow) } } Toggle(isOn: settingBinding.summaryRowTagsMaximumActivated) { - Text("Set maximum number of tags") + Text("Sets maximum number of tags") } - .disabled(!setting.showSummaryRowTags) + .disabled(!setting.showsSummaryRowTags) HStack { Text("Maximum number of tags") Spacer() @@ -80,7 +80,7 @@ struct AppearanceSettingView: View, StoreAccessor { } .disabled( !setting.summaryRowTagsMaximumActivated - || !setting.showSummaryRowTags + || !setting.showsSummaryRowTags ) } } diff --git a/EhPanda/View/Setting/GeneralSettingView.swift b/EhPanda/View/Setting/GeneralSettingView.swift index 7abcb92e..4218ded8 100644 --- a/EhPanda/View/Setting/GeneralSettingView.swift +++ b/EhPanda/View/Setting/GeneralSettingView.swift @@ -21,19 +21,27 @@ struct GeneralSettingView: View, StoreAccessor { Spacer() Button(language, action: toSettingLanguage) } + NavigationLink("Logs", destination: LogsView()) + NavigationLink("Filters", destination: FilterView()) + Toggle( + "Closes slide menu after selection", + isOn: settingBinding.closesSlideMenuAfterSelection + ) + } + Section(header: Text("Navigation")) { Toggle( - "Close slide menu after selection", - isOn: settingBinding.closeSlideMenuAfterSelection + "Redirects links to the selected host", + isOn: settingBinding.redirectsLinksToSelectedHost ) Toggle( - "Detect link from the clipboard", - isOn: settingBinding.detectGalleryFromPasteboard + "Detects links from the clipboard", + isOn: settingBinding.detectsLinksFromPasteboard ) Toggle( - "Allows detection even when no change", - isOn: settingBinding.allowsDetectionWhenNoChange + "Allows detection even when no changes", + isOn: settingBinding.allowsDetectionWhenNoChanges ) - .disabled(!setting.detectGalleryFromPasteboard) + .disabled(!setting.detectsLinksFromPasteboard) } Section(header: Text("Security")) { HStack { @@ -67,10 +75,6 @@ struct GeneralSettingView: View, StoreAccessor { .foregroundColor(.primary) } } - Section(header: Text("Advanced")) { - NavigationLink("Logs", destination: LogsView()) - NavigationLink("Filters", destination: FilterView()) - } } .navigationBarTitle("General") .task(checkPasscodeExistence) diff --git a/EhPanda/View/Tools/MangaSummaryRow.swift b/EhPanda/View/Tools/MangaSummaryRow.swift index aa091e5d..98f0c567 100644 --- a/EhPanda/View/Tools/MangaSummaryRow.swift +++ b/EhPanda/View/Tools/MangaSummaryRow.swift @@ -39,7 +39,7 @@ struct MangaSummaryRow: View { .lineLimit(1) .font(.subheadline) .foregroundStyle(.secondary) - if setting.showSummaryRowTags, !tags.isEmpty { + if setting.showsSummaryRowTags, !tags.isEmpty { TagCloudView( tag: MangaTag( category: .artist, @@ -83,7 +83,7 @@ struct MangaSummaryRow: View { } .drawingGroup() } - .padding(.vertical, setting.showSummaryRowTags ? 5 : 0) + .padding(.vertical, setting.showsSummaryRowTags ? 5 : 0) .padding(.leading, -10) .padding(.trailing, -5) } @@ -98,7 +98,7 @@ private extension MangaSummaryRow { } var category: String { - if setting.translateCategory { + if setting.translatesCategory { return manga.category.rawValue.localized() } else { return manga.category.rawValue