From 58be2ec216a96790c0be240143b9cf410b28bcea Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Fri, 26 Apr 2024 01:47:54 +0200 Subject: [PATCH 1/4] Make webView inspectable for debug --- ViewModel/BrowserViewModel.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ViewModel/BrowserViewModel.swift b/ViewModel/BrowserViewModel.swift index ce9a0607..fb04c986 100644 --- a/ViewModel/BrowserViewModel.swift +++ b/ViewModel/BrowserViewModel.swift @@ -96,6 +96,11 @@ final class BrowserViewModel: NSObject, ObservableObject, init(tabID: NSManagedObjectID? = nil) { self.tabID = tabID webView = WKWebView(frame: .zero, configuration: WebViewConfiguration()) +#if DEBUG + if #available(macOS 13.3, *) { + webView.isInspectable = true + } +#endif // Bookmark fetching: bookmarkFetchedResultsController = NSFetchedResultsController( fetchRequest: Bookmark.fetchRequest(), // initially empty @@ -402,6 +407,11 @@ final class BrowserViewModel: NSObject, ObservableObject, let configuration = UIContextMenuConfiguration( previewProvider: { let webView = WKWebView(frame: .zero, configuration: WebViewConfiguration()) + #if DEBUG + if #available(iOS 16.4, *) { + webView.isInspectable = true + } + #endif webView.load(URLRequest(url: url)) return WebViewController(webView: webView) }, From b0b8a815062e9a8ffca5ab5b248c8cf6a73f4ebe Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Fri, 26 Apr 2024 08:50:12 +0200 Subject: [PATCH 2/4] Fix available --- ViewModel/BrowserViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ViewModel/BrowserViewModel.swift b/ViewModel/BrowserViewModel.swift index fb04c986..26789d94 100644 --- a/ViewModel/BrowserViewModel.swift +++ b/ViewModel/BrowserViewModel.swift @@ -97,7 +97,7 @@ final class BrowserViewModel: NSObject, ObservableObject, self.tabID = tabID webView = WKWebView(frame: .zero, configuration: WebViewConfiguration()) #if DEBUG - if #available(macOS 13.3, *) { + if #available(iOS 16.4, macOS 13.3, *) { webView.isInspectable = true } #endif From 730fb43b4156797ccd4a53d5a0d0243f0363c89f Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Fri, 26 Apr 2024 09:08:39 +0200 Subject: [PATCH 3/4] Make webview inspectable on TestFlight builds --- Model/Utilities/Bundle+Extension.swift | 26 ++++++++++++++++++++++++++ ViewModel/BrowserViewModel.swift | 12 ++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 Model/Utilities/Bundle+Extension.swift diff --git a/Model/Utilities/Bundle+Extension.swift b/Model/Utilities/Bundle+Extension.swift new file mode 100644 index 00000000..9e0e0251 --- /dev/null +++ b/Model/Utilities/Bundle+Extension.swift @@ -0,0 +1,26 @@ +// This file is part of Kiwix for iOS & macOS. +// +// Kiwix is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// any later version. +// +// Kiwix is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kiwix; If not, see https://www.gnu.org/licenses/. + +import Foundation + +extension Bundle { + var isProduction: Bool { + #if DEBUG + return false + #else + appStoreReceiptURL?.path.contains("sandboxReceipt") + #endif + } +} diff --git a/ViewModel/BrowserViewModel.swift b/ViewModel/BrowserViewModel.swift index 26789d94..a1cfc508 100644 --- a/ViewModel/BrowserViewModel.swift +++ b/ViewModel/BrowserViewModel.swift @@ -96,11 +96,9 @@ final class BrowserViewModel: NSObject, ObservableObject, init(tabID: NSManagedObjectID? = nil) { self.tabID = tabID webView = WKWebView(frame: .zero, configuration: WebViewConfiguration()) -#if DEBUG - if #available(iOS 16.4, macOS 13.3, *) { - webView.isInspectable = true + if !Bundle.main.isProduction, #available(iOS 16.4, macOS 13.3, *) { + webView.isInspectable = true } -#endif // Bookmark fetching: bookmarkFetchedResultsController = NSFetchedResultsController( fetchRequest: Bookmark.fetchRequest(), // initially empty @@ -407,11 +405,9 @@ final class BrowserViewModel: NSObject, ObservableObject, let configuration = UIContextMenuConfiguration( previewProvider: { let webView = WKWebView(frame: .zero, configuration: WebViewConfiguration()) - #if DEBUG - if #available(iOS 16.4, *) { - webView.isInspectable = true + if !Bundle.main.isProduction, #available(iOS 16.4, *) { + webView.isInspectable = true } - #endif webView.load(URLRequest(url: url)) return WebViewController(webView: webView) }, From 2ac45b1c08bf88e68f73689535184ccd32aa8c85 Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Fri, 26 Apr 2024 10:59:55 +0200 Subject: [PATCH 4/4] Fix build issue --- Model/Utilities/Bundle+Extension.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/Utilities/Bundle+Extension.swift b/Model/Utilities/Bundle+Extension.swift index 9e0e0251..7f3df08a 100644 --- a/Model/Utilities/Bundle+Extension.swift +++ b/Model/Utilities/Bundle+Extension.swift @@ -18,9 +18,9 @@ import Foundation extension Bundle { var isProduction: Bool { #if DEBUG - return false + false #else - appStoreReceiptURL?.path.contains("sandboxReceipt") + appStoreReceiptURL?.path.contains("sandboxReceipt") == true #endif } }