Adapt store of the openFeedsInDefaultBrowser preference to be stored/retrieved from app group shared defaults, so that the Safari App Extension can access it.
This commit is contained in:
parent
d2157a7c08
commit
8b447f6446
@ -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 {
|
var subscribeToFeedsInDefaultBrowser: Bool {
|
||||||
get {
|
get {
|
||||||
return AppDefaults.bool(for: Key.subscribeToFeedsInDefaultBrowser)
|
return subscribeToFeedDefaults.bool(forKey: Key.subscribeToFeedsInDefaultBrowser)
|
||||||
}
|
}
|
||||||
set {
|
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.detailFontSize: FontSize.medium.rawValue,
|
||||||
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue,
|
||||||
Key.timelineGroupByFeed: false,
|
Key.timelineGroupByFeed: false,
|
||||||
Key.subscribeToFeedsInDefaultBrowser: false,
|
|
||||||
"NSScrollViewShouldScrollUnderTitlebar": false,
|
"NSScrollViewShouldScrollUnderTitlebar": false,
|
||||||
Key.refreshInterval: RefreshInterval.everyHour.rawValue,
|
Key.refreshInterval: RefreshInterval.everyHour.rawValue,
|
||||||
Key.showDebugMenu: showDebugMenu]
|
Key.showDebugMenu: showDebugMenu]
|
||||||
|
@ -190,7 +190,7 @@
|
|||||||
<font key="font" metaFont="system"/>
|
<font key="font" metaFont="system"/>
|
||||||
</buttonCell>
|
</buttonCell>
|
||||||
<connections>
|
<connections>
|
||||||
<binding destination="mAF-gO-1PI" name="value" keyPath="values.subscribeToFeedsInDefaultBrowser" id="rgT-1E-AoD">
|
<binding destination="iuH-lz-18x" name="value" keyPath="openFeedsInDefaultNewsReader" id="l1B-rk-qfE">
|
||||||
<dictionary key="options">
|
<dictionary key="options">
|
||||||
<string key="NSValueTransformerName">NSNegateBoolean</string>
|
<string key="NSValueTransformerName">NSNegateBoolean</string>
|
||||||
</dictionary>
|
</dictionary>
|
||||||
@ -204,7 +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.subscribeToFeedsInDefaultBrowser" id="Dnc-co-ppt"/>
|
<binding destination="iuH-lz-18x" name="value" keyPath="openFeedsInDefaultNewsReader" id="QZ4-W8-rPi"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
</subviews>
|
</subviews>
|
||||||
|
@ -126,4 +126,12 @@ private extension GeneralPreferencesViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc var openFeedsInDefaultNewsReader: Bool {
|
||||||
|
get {
|
||||||
|
return AppDefaults.shared.subscribeToFeedsInDefaultBrowser
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
AppDefaults.shared.subscribeToFeedsInDefaultBrowser = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
<string>Subscribe to Feed</string>
|
<string>Subscribe to Feed</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
|
<key>AppGroup</key>
|
||||||
|
<string>group.$(ORGANIZATION_IDENTIFIER).NetNewsWire-Evergreen</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
@ -45,15 +45,11 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
|
|||||||
if var feedURLString = userInfo?["url"] as? String {
|
if var feedURLString = userInfo?["url"] as? String {
|
||||||
var openInDefaultBrowser = false
|
var openInDefaultBrowser = false
|
||||||
|
|
||||||
// Ask for the user default from NetNewsWire's defaults to determine whether to open the feed URL
|
// Ask for the user's choice for whether to open the feed URL using whatever the system
|
||||||
// using whatever the system configured default is, or to always hard-code it to NetNewsWire itself.
|
// configured default is, or to always hard-code it to have NetNewsWire handle it itself.
|
||||||
if let pluginBundleID = Bundle.main.bundleIdentifier {
|
if let appGroupID = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as? String {
|
||||||
// By convention we assume that our bundle ID will always be the same as the host app's, with
|
if let groupDefaults = UserDefaults(suiteName: appGroupID) {
|
||||||
// the addition of ".Subscribe-to-Feed".
|
openInDefaultBrowser = groupDefaults.bool(forKey: "subscribeToFeedsInDefaultBrowser")
|
||||||
let hostAppBundleID = pluginBundleID.replacingOccurrences(of: ".Subscribe-to-Feed", with: "")
|
|
||||||
|
|
||||||
if let sharedDefaults = UserDefaults(suiteName: hostAppBundleID) {
|
|
||||||
openInDefaultBrowser = sharedDefaults.bool(forKey: "subscribeToFeedsInDefaultBrowser")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user