mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-27 01:52:30 +01:00
Reimplement open in browser toolbar button functionality
This commit is contained in:
parent
628f349448
commit
d83ca618fb
@ -77,7 +77,7 @@ final class SceneModel: ObservableObject {
|
||||
|
||||
/// Opens the selected article in an external browser
|
||||
func openSelectedArticleInBrowser() {
|
||||
// timelineModel.openSelectedArticleInBrowser()
|
||||
timelineModel.openSelectedArticlesInBrowserSubject.send()
|
||||
}
|
||||
|
||||
/// Retrieves the article before the given article in the Timeline
|
||||
|
@ -41,6 +41,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
||||
var markAllAsReadSubject = PassthroughSubject<Void, Never>()
|
||||
var toggleReadStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>()
|
||||
var toggleStarredStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>()
|
||||
var openSelectedArticlesInBrowserSubject = PassthroughSubject<Void, Never>()
|
||||
|
||||
var readFilterEnabledTable = [FeedIdentifier: Bool]()
|
||||
|
||||
@ -63,6 +64,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
||||
subscribeToArticleStatusChanges()
|
||||
// subscribeToAccountDidDownloadArticles()
|
||||
subscribeToArticleMarkingEvents()
|
||||
subscribeToOpenInBrowserEvents()
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
@ -310,6 +312,25 @@ private extension TimelineModel {
|
||||
|
||||
}
|
||||
|
||||
func subscribeToOpenInBrowserEvents() {
|
||||
guard let selectedArticlesPublisher = selectedArticlesPublisher else { return }
|
||||
|
||||
let selectedArticleOpenInBrowserPublisher = openSelectedArticlesInBrowserSubject
|
||||
.withLatestFrom(selectedArticlesPublisher)
|
||||
.compactMap { $0.first?.preferredLink }
|
||||
|
||||
selectedArticleOpenInBrowserPublisher
|
||||
.sink { link in
|
||||
#if os(macOS)
|
||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||
#else
|
||||
guard let url = URL(string: link) else { return }
|
||||
UIApplication.shared.open(url, options: [:])
|
||||
#endif
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// MARK: Timeline Management
|
||||
|
||||
func performBlockAndRestoreSelection(_ block: (() -> Void)) {
|
||||
|
Loading…
Reference in New Issue
Block a user