Reimplement open in browser toolbar button functionality

This commit is contained in:
Maurice Parker 2020-07-25 16:56:38 -05:00
parent 628f349448
commit d83ca618fb
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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)) {