Skip to content

Commit

Permalink
feat: Links host redirection feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuz0u committed Jul 12, 2021
1 parent f724aa3 commit 16a3549
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 66 deletions.
16 changes: 10 additions & 6 deletions EhPanda/App/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -234,7 +235,10 @@ extension Optional {
}
SwiftyBeaver.error(
"Failed in force unwrapping..."
+ "Shutting down now..."
+ "Shutting down now...",
context: [
"type": Wrapped.self
]
)
fatalError()
}
Expand Down
16 changes: 9 additions & 7 deletions EhPanda/App/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "閲覧";
Expand Down
16 changes: 9 additions & 7 deletions EhPanda/App/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "阅读";
Expand Down
16 changes: 9 additions & 7 deletions EhPanda/App/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "閱讀";
Expand Down
12 changes: 11 additions & 1 deletion EhPanda/DataFlow/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions EhPanda/DataFlow/StoreAccessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ extension StoreAccessor {
var autoLockPolicy: AutoLockPolicy {
setting.autoLockPolicy
}
var detectGalleryFromPasteboard: Bool {
setting.detectGalleryFromPasteboard
var detectsLinksFromPasteboard: Bool {
setting.detectsLinksFromPasteboard
}
}

Expand Down
11 changes: 6 additions & 5 deletions EhPanda/Models/Setting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
12 changes: 6 additions & 6 deletions EhPanda/View/Detail/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -229,22 +229,22 @@ 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

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
Expand Down Expand Up @@ -339,7 +339,7 @@ private extension HeaderView {
}
}
var category: String {
if translateCategory {
if translatesCategory {
return manga.category.rawValue.localized()
} else {
return manga.category.rawValue
Expand Down
4 changes: 2 additions & 2 deletions EhPanda/View/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private extension HomeView {
}

var hasJumpPermission: Bool {
detectGalleryFromPasteboard
detectsLinksFromPasteboard
&& viewControllersCount == 1
}
var suggestions: [String] {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions EhPanda/View/Home/SlideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private extension SlideMenu {
store.dispatch(.toggleHomeList(type: item))
impactFeedback(style: .soft)

if setting.closeSlideMenuAfterSelection {
if setting.closesSlideMenuAfterSelection {
performTransition(offset: -width)
}
}
Expand All @@ -90,7 +90,7 @@ private extension SlideMenu {
store.dispatch(.toggleHomeViewSheet(state: .setting))
}
func onFavoritesIndexChange(_ : Int) {
if setting.closeSlideMenuAfterSelection {
if setting.closesSlideMenuAfterSelection {
performTransition(offset: -width)
}
}
Expand Down
14 changes: 7 additions & 7 deletions EhPanda/View/Setting/AppearanceSettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -80,7 +80,7 @@ struct AppearanceSettingView: View, StoreAccessor {
}
.disabled(
!setting.summaryRowTagsMaximumActivated
|| !setting.showSummaryRowTags
|| !setting.showsSummaryRowTags
)
}
}
Expand Down
26 changes: 15 additions & 11 deletions EhPanda/View/Setting/GeneralSettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 16a3549

Please sign in to comment.