mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-29 06:56:46 -04:00
Merge branch 'feature/24-localization' of https://github.com/tvision251/apple into feature/24-localization
This commit is contained in:
commit
d6affef6d6
@ -62,7 +62,6 @@ extension Color {
|
|||||||
|
|
||||||
extension Notification.Name {
|
extension Notification.Name {
|
||||||
static let alert = Notification.Name("alert")
|
static let alert = Notification.Name("alert")
|
||||||
static let externalLink = Notification.Name("externalLink")
|
|
||||||
static let openFiles = Notification.Name("openFiles")
|
static let openFiles = Notification.Name("openFiles")
|
||||||
static let openURL = Notification.Name("openURL")
|
static let openURL = Notification.Name("openURL")
|
||||||
static let toggleSidebar = Notification.Name("toggleSidebar")
|
static let toggleSidebar = Notification.Name("toggleSidebar")
|
||||||
|
@ -45,6 +45,7 @@ class BrowserViewModel: NSObject, ObservableObject,
|
|||||||
@Published private(set) var outlineItems = [OutlineItem]()
|
@Published private(set) var outlineItems = [OutlineItem]()
|
||||||
@Published private(set) var outlineItemTree = [OutlineItem]()
|
@Published private(set) var outlineItemTree = [OutlineItem]()
|
||||||
@Published private(set) var url: URL?
|
@Published private(set) var url: URL?
|
||||||
|
@Published var externalLink: URL?
|
||||||
|
|
||||||
let tabID: NSManagedObjectID?
|
let tabID: NSManagedObjectID?
|
||||||
let webView: WKWebView
|
let webView: WKWebView
|
||||||
@ -179,7 +180,7 @@ class BrowserViewModel: NSObject, ObservableObject,
|
|||||||
} else if url.isKiwixURL {
|
} else if url.isKiwixURL {
|
||||||
decisionHandler(.allow)
|
decisionHandler(.allow)
|
||||||
} else if url.scheme == "http" || url.scheme == "https" {
|
} else if url.scheme == "http" || url.scheme == "https" {
|
||||||
NotificationCenter.default.post(name: .externalLink, object: nil, userInfo: ["url": url])
|
externalLink = url
|
||||||
decisionHandler(.cancel)
|
decisionHandler(.cancel)
|
||||||
} else if url.scheme == "geo" {
|
} else if url.scheme == "geo" {
|
||||||
if FeatureFlags.map {
|
if FeatureFlags.map {
|
||||||
|
@ -11,12 +11,11 @@ import SwiftUI
|
|||||||
import Defaults
|
import Defaults
|
||||||
|
|
||||||
struct ExternalLinkHandler: ViewModifier {
|
struct ExternalLinkHandler: ViewModifier {
|
||||||
|
@EnvironmentObject private var browserViewModel: BrowserViewModel
|
||||||
@State private var isAlertPresented = false
|
@State private var isAlertPresented = false
|
||||||
@State private var activeAlert: ActiveAlert?
|
@State private var activeAlert: ActiveAlert?
|
||||||
@State private var activeSheet: ActiveSheet?
|
@State private var activeSheet: ActiveSheet?
|
||||||
|
|
||||||
private let externalLink = NotificationCenter.default.publisher(for: .externalLink)
|
|
||||||
|
|
||||||
enum ActiveAlert {
|
enum ActiveAlert {
|
||||||
case ask(url: URL)
|
case ask(url: URL)
|
||||||
case notLoading
|
case notLoading
|
||||||
@ -28,8 +27,9 @@ struct ExternalLinkHandler: ViewModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
content.onReceive(externalLink) { notification in
|
content.onChange(of: browserViewModel.externalLink) { url in
|
||||||
guard let url = notification.userInfo?["url"] as? URL else { return }
|
defer { browserViewModel.externalLink = nil }
|
||||||
|
guard let url = url else { return }
|
||||||
switch Defaults[.externalLinkLoadingPolicy] {
|
switch Defaults[.externalLinkLoadingPolicy] {
|
||||||
case .alwaysAsk:
|
case .alwaysAsk:
|
||||||
isAlertPresented = true
|
isAlertPresented = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user