diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index fbc529dfd..3c0eaf09d 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -107,12 +107,24 @@ final class AppDefaults { } } + // Special case for this default: store/retrieve it from the shared app group + // defaults, so that it can be resolved by the Safari App Extension. + var subscribeToFeedDefaults: UserDefaults { + if let appGroupID = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as? String, + let appGroupDefaults = UserDefaults(suiteName: appGroupID) { + return appGroupDefaults + } + else { + return UserDefaults.standard + } + } + var subscribeToFeedsInDefaultBrowser: Bool { get { - return AppDefaults.bool(for: Key.subscribeToFeedsInDefaultBrowser) + return subscribeToFeedDefaults.bool(forKey: Key.subscribeToFeedsInDefaultBrowser) } set { - AppDefaults.setBool(for: Key.subscribeToFeedsInDefaultBrowser, newValue) + subscribeToFeedDefaults.set(newValue, forKey: Key.subscribeToFeedsInDefaultBrowser) } } @@ -297,7 +309,6 @@ final class AppDefaults { Key.detailFontSize: FontSize.medium.rawValue, Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, Key.timelineGroupByFeed: false, - Key.subscribeToFeedsInDefaultBrowser: false, "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 9f9b2e431..415f70e1e 100644 --- a/Mac/Base.lproj/Preferences.storyboard +++ b/Mac/Base.lproj/Preferences.storyboard @@ -190,7 +190,7 @@ - + NSNegateBoolean @@ -204,7 +204,7 @@ - + diff --git a/Mac/Preferences/General/GeneralPrefencesViewController.swift b/Mac/Preferences/General/GeneralPrefencesViewController.swift index 32e789ed4..08de5b27d 100644 --- a/Mac/Preferences/General/GeneralPrefencesViewController.swift +++ b/Mac/Preferences/General/GeneralPrefencesViewController.swift @@ -126,4 +126,12 @@ private extension GeneralPreferencesViewController { } } + @objc var openFeedsInDefaultNewsReader: Bool { + get { + return AppDefaults.shared.subscribeToFeedsInDefaultBrowser + } + set { + AppDefaults.shared.subscribeToFeedsInDefaultBrowser = newValue + } + } } diff --git a/Mac/SafariExtension/Info.plist b/Mac/SafariExtension/Info.plist index b31bd790b..a335419fe 100644 --- a/Mac/SafariExtension/Info.plist +++ b/Mac/SafariExtension/Info.plist @@ -8,6 +8,8 @@ Subscribe to Feed CFBundleExecutable $(EXECUTABLE_NAME) + AppGroup + group.$(ORGANIZATION_IDENTIFIER).NetNewsWire-Evergreen CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion diff --git a/Mac/SafariExtension/SafariExtensionHandler.swift b/Mac/SafariExtension/SafariExtensionHandler.swift index 556154f38..2589d4034 100644 --- a/Mac/SafariExtension/SafariExtensionHandler.swift +++ b/Mac/SafariExtension/SafariExtensionHandler.swift @@ -45,15 +45,11 @@ class SafariExtensionHandler: SFSafariExtensionHandler { 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 - // 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) { - openInDefaultBrowser = sharedDefaults.bool(forKey: "subscribeToFeedsInDefaultBrowser") + // Ask for the user's choice for whether to open the feed URL using whatever the system + // configured default is, or to always hard-code it to have NetNewsWire handle it itself. + if let appGroupID = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as? String { + if let groupDefaults = UserDefaults(suiteName: appGroupID) { + openInDefaultBrowser = groupDefaults.bool(forKey: "subscribeToFeedsInDefaultBrowser") } }