diff --git a/Mac/Resources/Info.plist b/Mac/Resources/Info.plist
index af856875b..e6a304af3 100644
--- a/Mac/Resources/Info.plist
+++ b/Mac/Resources/Info.plist
@@ -33,6 +33,7 @@
feed
feeds
+ x-netnewswire-feed
diff --git a/Mac/SafariExtension/SafariExtensionHandler.swift b/Mac/SafariExtension/SafariExtensionHandler.swift
index 44c560bf7..b3c8cf828 100644
--- a/Mac/SafariExtension/SafariExtensionHandler.swift
+++ b/Mac/SafariExtension/SafariExtensionHandler.swift
@@ -40,13 +40,24 @@ 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 let feedURLString = userInfo?["url"] as? String {
+ if var feedURLString = userInfo?["url"] as? String {
+ // 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.
+ if let pluginBundleID = Bundle.main.bundleIdentifier {
+ // By convention we assume that our bundle ID will always be the same as the host app's, with
+ // the addition of ".Subscribe-to-Feed".
+ let hostAppBundleID = pluginBundleID.replacingOccurrences(of: ".Subscribe-to-Feed", with: "")
+
+ if let sharedDefaults = UserDefaults(suiteName: hostAppBundleID) {
+ let openInNNW = sharedDefaults.bool(forKey: "subscribeToFeedsInNetNewsWire")
+ if openInNNW {
+ feedURLString = feedURLString.replacingOccurrences(of: "feed:", with: "x-netnewswire-feed")
+ }
+ }
+ }
if let feedURL = URL(string: feedURLString) {
- // We could do something more NetNewsWire-specific like invoke an app-specific scheme
- // to subscribe in the app. For starters we just let NSWorkspace open the URL in the
- // default "feed:" URL scheme handler.
NSWorkspace.shared.open(feedURL)
}
}
diff --git a/Mac/SafariExtension/Subscribe_to_Feed.entitlements b/Mac/SafariExtension/Subscribe_to_Feed.entitlements
index 852fa1a47..08aae1850 100644
--- a/Mac/SafariExtension/Subscribe_to_Feed.entitlements
+++ b/Mac/SafariExtension/Subscribe_to_Feed.entitlements
@@ -4,5 +4,9 @@
com.apple.security.app-sandbox
+ com.apple.security.application-groups
+
+ group.$(ORGANIZATION_IDENTIFIER).NetNewsWire-Evergreen
+