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 exportOPMLAccountID = "exportOPMLAccountID"
static let defaultBrowserID = "defaultBrowserID" static let defaultBrowserID = "defaultBrowserID"
static let currentThemeName = "currentThemeName" static let currentThemeName = "currentThemeName"
static let javascriptEnabled = "javascriptEnabled"
// Hidden prefs // Hidden prefs
static let showDebugMenu = "ShowDebugMenu" 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() { func registerDefaults() {
#if DEBUG #if DEBUG
let showDebugMenu = true let showDebugMenu = true
@ -306,15 +316,18 @@ final class AppDefaults {
let showDebugMenu = false let showDebugMenu = false
#endif #endif
let defaults: [String : Any] = [Key.sidebarFontSize: FontSize.medium.rawValue, let defaults: [String : Any] = [
Key.timelineFontSize: FontSize.medium.rawValue, Key.sidebarFontSize: FontSize.medium.rawValue,
Key.detailFontSize: FontSize.medium.rawValue, Key.timelineFontSize: FontSize.medium.rawValue,
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, Key.detailFontSize: FontSize.medium.rawValue,
Key.timelineGroupByFeed: false, Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
"NSScrollViewShouldScrollUnderTitlebar": false, Key.timelineGroupByFeed: false,
Key.refreshInterval: RefreshInterval.everyHour.rawValue, "NSScrollViewShouldScrollUnderTitlebar": false,
Key.showDebugMenu: showDebugMenu, Key.refreshInterval: RefreshInterval.everyHour.rawValue,
Key.currentThemeName: Self.defaultThemeName] Key.showDebugMenu: showDebugMenu,
Key.currentThemeName: Self.defaultThemeName,
Key.javascriptEnabled: false
]
UserDefaults.standard.register(defaults: defaults) UserDefaults.standard.register(defaults: defaults)

View File

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