From 75fd9e1e1342074e7ee71007db83ce23146b95e1 Mon Sep 17 00:00:00 2001 From: Daniel Jalkut Date: Mon, 21 Jun 2021 17:51:04 -0400 Subject: [PATCH 1/2] Add new subscribeToFeedsInNetNewsWire boolean preference, to direct the behavior of the Subscribe to Feed app extension. --- Mac/AppDefaults.swift | 11 ++ Mac/Base.lproj/Preferences.storyboard | 105 ++++++++++++------ Multiplatform/Shared/AppDefaults.swift | 9 +- .../General/GeneralPreferencesView.swift | 15 ++- 4 files changed, 102 insertions(+), 38 deletions(-) diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index 2aa453d8d..d38d065ec 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -30,6 +30,7 @@ final class AppDefaults { static let timelineGroupByFeed = "timelineGroupByFeed" static let detailFontSize = "detailFontSize" static let openInBrowserInBackground = "openInBrowserInBackground" + static let subscribeToFeedsInNetNewsWire = "subscribeToFeedsInNetNewsWire" static let articleTextSize = "articleTextSize" static let refreshInterval = "refreshInterval" static let addWebFeedAccountID = "addWebFeedAccountID" @@ -106,6 +107,15 @@ final class AppDefaults { } } + var subscribeToFeedsInNetNewsWire: Bool { + get { + return AppDefaults.bool(for: Key.subscribeToFeedsInNetNewsWire) + } + set { + AppDefaults.setBool(for: Key.subscribeToFeedsInNetNewsWire, newValue) + } + } + var sidebarFontSize: FontSize { get { return fontSize(for: Key.sidebarFontSize) @@ -287,6 +297,7 @@ final class AppDefaults { Key.detailFontSize: FontSize.medium.rawValue, Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, Key.timelineGroupByFeed: false, + Key.subscribeToFeedsInNetNewsWire: true, "NSScrollViewShouldScrollUnderTitlebar": false, Key.refreshInterval: RefreshInterval.everyHour.rawValue, Key.showDebugMenu: showDebugMenu] diff --git a/Mac/Base.lproj/Preferences.storyboard b/Mac/Base.lproj/Preferences.storyboard index ddd693d02..c6fa7a8ae 100644 --- a/Mac/Base.lproj/Preferences.storyboard +++ b/Mac/Base.lproj/Preferences.storyboard @@ -1,8 +1,8 @@ - + - + @@ -31,15 +31,15 @@ - - + + - + - + @@ -47,7 +47,7 @@ - + @@ -76,10 +76,10 @@ - + - + @@ -87,7 +87,7 @@ - + @@ -102,7 +102,7 @@ - + @@ -133,8 +133,8 @@ - - + + @@ -175,15 +175,50 @@ + + + + + + + + + + + + + @@ -193,13 +228,19 @@ - + + + + + + + @@ -400,20 +441,20 @@ - + - + - + - + - + @@ -493,7 +534,7 @@ - + - + diff --git a/Multiplatform/Shared/AppDefaults.swift b/Multiplatform/Shared/AppDefaults.swift index 7ad949455..193cd1a8a 100644 --- a/Multiplatform/Shared/AppDefaults.swift +++ b/Multiplatform/Shared/AppDefaults.swift @@ -75,6 +75,7 @@ final class AppDefaults: ObservableObject { static let articleTextSize = "articleTextSize" static let openInBrowserInBackground = "openInBrowserInBackground" static let defaultBrowserID = "defaultBrowserID" + static let subscribeToFeedsInNetNewsWire = "subscribeToFeedsInNetNewsWire" static let checkForUpdatesAutomatically = "checkForUpdatesAutomatically" static let downloadTestBuilds = "downloadTestBuild" static let sendCrashLogs = "sendCrashLogs" @@ -265,7 +266,13 @@ final class AppDefaults: ObservableObject { objectWillChange.send() } } - + + @AppStorage(wrappedValue: false, Key.subscribeToFeedsInNetNewsWire, store: store) var subscribeToFeedsInNetNewsWire: Bool { + didSet { + objectWillChange.send() + } + } + @AppStorage(Key.showTitleOnMainWindow, store: store) var showTitleOnMainWindow: Bool? { didSet { objectWillChange.send() diff --git a/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesView.swift b/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesView.swift index 71634bae9..5342d1686 100644 --- a/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesView.swift +++ b/Multiplatform/macOS/Preferences/Preference Panes/General/GeneralPreferencesView.swift @@ -14,7 +14,7 @@ struct GeneralPreferencesView: View { var body: some View { Form { - Picker("Refresh feeds", + Picker("Refresh feeds:", selection: $defaults.interval, content: { ForEach(RefreshInterval.allCases, content: { interval in @@ -22,8 +22,8 @@ struct GeneralPreferencesView: View { .tag(interval.rawValue) }) }) - - Picker("Default RSS reader", selection: $preferences.readerSelection, content: { + + Picker("Default RSS reader:", selection: $preferences.readerSelection, content: { ForEach(0.. 0 && preferences.rssReaders[index].nameMinusAppSuffix.contains("NetNewsWire") { Text(preferences.rssReaders[index].nameMinusAppSuffix.appending(" (old version)")) @@ -38,9 +38,14 @@ struct GeneralPreferencesView: View { Toggle("Confirm when deleting feeds and folders", isOn: $defaults.sidebarConfirmDelete) Toggle("Open webpages in background in browser", isOn: $defaults.openInBrowserInBackground) - Toggle("Hide Unread Count in Dock", isOn: $defaults.hideDockUnreadCount) - + + Picker("Safari Extension:", + selection: $defaults.subscribeToFeedsInNetNewsWire, + content: { + Text("Open feeds in NetNewsWire").tag(true) + Text("Open feeds in default news reader").tag(false) + }).pickerStyle(RadioGroupPickerStyle()) } .frame(width: 400, alignment: .center) .lineLimit(2) From 8191f2476aee10d3b97210fd2eccec13a2028433 Mon Sep 17 00:00:00 2001 From: Daniel Jalkut Date: Tue, 22 Jun 2021 12:35:09 -0400 Subject: [PATCH 2/2] Add x-netnewswire-feed to the list of scheme prefixes for adding a feed to NetNewsWire, and modify the behavior of the Safari App Extension plugin so that it consults the host app preference for opening in NetNewsWire or with the default feed handler, before choosing which scheme to prepend to the feed URL. --- Mac/Resources/Info.plist | 1 + .../SafariExtensionHandler.swift | 21 ++++++++++++++----- .../Subscribe_to_Feed.entitlements | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) 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 +