Add isJavascriptEnabled setting, defaulting to false, and respect it in the web view.

This commit is contained in:
Brent Simmons 2023-11-25 11:53:19 -08:00
parent c05ef2344f
commit dfd778d038
2 changed files with 23 additions and 11 deletions

View File

@ -41,6 +41,7 @@ final class AppDefaults {
static let exportOPMLAccountID = "exportOPMLAccountID"
static let defaultBrowserID = "defaultBrowserID"
static let currentThemeName = "currentThemeName"
static let javascriptEnabled = "javascriptEnabled"
// Hidden prefs
static let showDebugMenu = "ShowDebugMenu"
@ -299,6 +300,15 @@ final class AppDefaults {
}
}
var isJavascriptEnabled: Bool {
get {
UserDefaults.standard.bool(forKey: Key.javascriptEnabled)
}
set {
UserDefaults.standard.set(newValue, forKey: Key.javascriptEnabled)
}
}
func registerDefaults() {
#if DEBUG
let showDebugMenu = true
@ -306,15 +316,18 @@ final class AppDefaults {
let showDebugMenu = false
#endif
let defaults: [String : Any] = [Key.sidebarFontSize: FontSize.medium.rawValue,
Key.timelineFontSize: FontSize.medium.rawValue,
Key.detailFontSize: FontSize.medium.rawValue,
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
Key.timelineGroupByFeed: false,
"NSScrollViewShouldScrollUnderTitlebar": false,
Key.refreshInterval: RefreshInterval.everyHour.rawValue,
Key.showDebugMenu: showDebugMenu,
Key.currentThemeName: Self.defaultThemeName]
let defaults: [String : Any] = [
Key.sidebarFontSize: FontSize.medium.rawValue,
Key.timelineFontSize: FontSize.medium.rawValue,
Key.detailFontSize: FontSize.medium.rawValue,
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
Key.timelineGroupByFeed: false,
"NSScrollViewShouldScrollUnderTitlebar": false,
Key.refreshInterval: RefreshInterval.everyHour.rawValue,
Key.showDebugMenu: showDebugMenu,
Key.currentThemeName: Self.defaultThemeName,
Key.javascriptEnabled: false
]
UserDefaults.standard.register(defaults: defaults)

View File

@ -95,10 +95,9 @@ final class DetailWebViewController: NSViewController {
preferences.minimumFontSize = 12.0
preferences.javaScriptCanOpenWindowsAutomatically = false
let configuration = WKWebViewConfiguration()
configuration.preferences = preferences
configuration.defaultWebpagePreferences.allowsContentJavaScript = false
configuration.defaultWebpagePreferences.allowsContentJavaScript = AppDefaults.shared.isJavascriptEnabled
configuration.setURLSchemeHandler(detailIconSchemeHandler, forURLScheme: ArticleRenderer.imageIconScheme)
let userContentController = WKUserContentController()