Merge pull request #3180 from danielpunkass/default-feed-handler

Invert the semantics of the defaults key for whether to open Subscrib…
This commit is contained in:
Maurice Parker 2021-06-22 21:20:12 -05:00 committed by GitHub
commit ba2d26dce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 20 deletions

View File

@ -30,7 +30,7 @@ final class AppDefaults {
static let timelineGroupByFeed = "timelineGroupByFeed" static let timelineGroupByFeed = "timelineGroupByFeed"
static let detailFontSize = "detailFontSize" static let detailFontSize = "detailFontSize"
static let openInBrowserInBackground = "openInBrowserInBackground" static let openInBrowserInBackground = "openInBrowserInBackground"
static let subscribeToFeedsInNetNewsWire = "subscribeToFeedsInNetNewsWire" static let subscribeToFeedsInDefaultBrowser = "subscribeToFeedsInDefaultBrowser"
static let articleTextSize = "articleTextSize" static let articleTextSize = "articleTextSize"
static let refreshInterval = "refreshInterval" static let refreshInterval = "refreshInterval"
static let addWebFeedAccountID = "addWebFeedAccountID" static let addWebFeedAccountID = "addWebFeedAccountID"
@ -107,12 +107,12 @@ final class AppDefaults {
} }
} }
var subscribeToFeedsInNetNewsWire: Bool { var subscribeToFeedsInDefaultBrowser: Bool {
get { get {
return AppDefaults.bool(for: Key.subscribeToFeedsInNetNewsWire) return AppDefaults.bool(for: Key.subscribeToFeedsInDefaultBrowser)
} }
set { set {
AppDefaults.setBool(for: Key.subscribeToFeedsInNetNewsWire, newValue) AppDefaults.setBool(for: Key.subscribeToFeedsInDefaultBrowser, newValue)
} }
} }
@ -297,7 +297,7 @@ final class AppDefaults {
Key.detailFontSize: FontSize.medium.rawValue, Key.detailFontSize: FontSize.medium.rawValue,
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
Key.timelineGroupByFeed: false, Key.timelineGroupByFeed: false,
Key.subscribeToFeedsInNetNewsWire: true, Key.subscribeToFeedsInDefaultBrowser: false,
"NSScrollViewShouldScrollUnderTitlebar": false, "NSScrollViewShouldScrollUnderTitlebar": false,
Key.refreshInterval: RefreshInterval.everyHour.rawValue, Key.refreshInterval: RefreshInterval.everyHour.rawValue,
Key.showDebugMenu: showDebugMenu] Key.showDebugMenu: showDebugMenu]

View File

@ -190,7 +190,11 @@
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>
<connections> <connections>
<binding destination="mAF-gO-1PI" name="value" keyPath="values.subscribeToFeedsInNetNewsWire" id="Q15-dB-PCt"/> <binding destination="mAF-gO-1PI" name="value" keyPath="values.subscribeToFeedsInDefaultBrowser" id="rgT-1E-AoD">
<dictionary key="options">
<string key="NSValueTransformerName">NSNegateBoolean</string>
</dictionary>
</binding>
</connections> </connections>
</button> </button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Yrc-6Q-kx8"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Yrc-6Q-kx8">
@ -200,11 +204,7 @@
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>
<connections> <connections>
<binding destination="mAF-gO-1PI" name="value" keyPath="values.subscribeToFeedsInNetNewsWire" id="Ikq-MR-S1U"> <binding destination="mAF-gO-1PI" name="value" keyPath="values.subscribeToFeedsInDefaultBrowser" id="Dnc-co-ppt"/>
<dictionary key="options">
<string key="NSValueTransformerName">NSNegateBoolean</string>
</dictionary>
</binding>
</connections> </connections>
</button> </button>
</subviews> </subviews>

View File

@ -43,6 +43,8 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : Any]?) { override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : Any]?) {
if (messageName == "subscribeToFeed") { if (messageName == "subscribeToFeed") {
if var feedURLString = userInfo?["url"] as? String { if var feedURLString = userInfo?["url"] as? String {
var openInDefaultBrowser = false
// Ask for the user default from NetNewsWire's defaults to determine whether to open the feed URL // Ask for the user default from NetNewsWire's defaults to determine whether to open the feed URL
// using whatever the system configured default is, or to always hard-code it to NetNewsWire itself. // using whatever the system configured default is, or to always hard-code it to NetNewsWire itself.
if let pluginBundleID = Bundle.main.bundleIdentifier { if let pluginBundleID = Bundle.main.bundleIdentifier {
@ -51,12 +53,14 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
let hostAppBundleID = pluginBundleID.replacingOccurrences(of: ".Subscribe-to-Feed", with: "") let hostAppBundleID = pluginBundleID.replacingOccurrences(of: ".Subscribe-to-Feed", with: "")
if let sharedDefaults = UserDefaults(suiteName: hostAppBundleID) { if let sharedDefaults = UserDefaults(suiteName: hostAppBundleID) {
let openInNNW = sharedDefaults.bool(forKey: "subscribeToFeedsInNetNewsWire") openInDefaultBrowser = sharedDefaults.bool(forKey: "subscribeToFeedsInDefaultBrowser")
if openInNNW {
feedURLString = feedURLString.replacingOccurrences(of: "feed:", with: "x-netnewswire-feed")
} }
} }
if openInDefaultBrowser == false {
feedURLString = feedURLString.replacingOccurrences(of: "feed:", with: "x-netnewswire-feed:")
} }
if let feedURL = URL(string: feedURLString) { if let feedURL = URL(string: feedURLString) {
NSWorkspace.shared.open(feedURL) NSWorkspace.shared.open(feedURL)
} }

View File

@ -75,7 +75,7 @@ final class AppDefaults: ObservableObject {
static let articleTextSize = "articleTextSize" static let articleTextSize = "articleTextSize"
static let openInBrowserInBackground = "openInBrowserInBackground" static let openInBrowserInBackground = "openInBrowserInBackground"
static let defaultBrowserID = "defaultBrowserID" static let defaultBrowserID = "defaultBrowserID"
static let subscribeToFeedsInNetNewsWire = "subscribeToFeedsInNetNewsWire" static let subscribeToFeedsInDefaultBrowser = "subscribeToFeedsInDefaultBrowser"
static let checkForUpdatesAutomatically = "checkForUpdatesAutomatically" static let checkForUpdatesAutomatically = "checkForUpdatesAutomatically"
static let downloadTestBuilds = "downloadTestBuild" static let downloadTestBuilds = "downloadTestBuild"
static let sendCrashLogs = "sendCrashLogs" static let sendCrashLogs = "sendCrashLogs"
@ -267,7 +267,7 @@ final class AppDefaults: ObservableObject {
} }
} }
@AppStorage(wrappedValue: false, Key.subscribeToFeedsInNetNewsWire, store: store) var subscribeToFeedsInNetNewsWire: Bool { @AppStorage(wrappedValue: false, Key.subscribeToFeedsInDefaultBrowser, store: store) var subscribeToFeedsInDefaultBrowser: Bool {
didSet { didSet {
objectWillChange.send() objectWillChange.send()
} }

View File

@ -41,10 +41,10 @@ struct GeneralPreferencesView: View {
Toggle("Hide Unread Count in Dock", isOn: $defaults.hideDockUnreadCount) Toggle("Hide Unread Count in Dock", isOn: $defaults.hideDockUnreadCount)
Picker("Safari Extension:", Picker("Safari Extension:",
selection: $defaults.subscribeToFeedsInNetNewsWire, selection: $defaults.subscribeToFeedsInDefaultBrowser,
content: { content: {
Text("Open feeds in NetNewsWire").tag(true) Text("Open feeds in NetNewsWire").tag(false)
Text("Open feeds in default news reader").tag(false) Text("Open feeds in default news reader").tag(true)
}).pickerStyle(RadioGroupPickerStyle()) }).pickerStyle(RadioGroupPickerStyle())
} }
.frame(width: 400, alignment: .center) .frame(width: 400, alignment: .center)