diff --git a/Multiplatform/Shared/SceneModel.swift b/Multiplatform/Shared/SceneModel.swift index 8a3f9b1d7..0200e436b 100644 --- a/Multiplatform/Shared/SceneModel.swift +++ b/Multiplatform/Shared/SceneModel.swift @@ -6,7 +6,11 @@ // Copyright © 2020 Ranchero Software. All rights reserved. // -import Foundation +#if os(macOS) +import AppKit +#else +import UIKit +#endif import Combine import Account import Articles @@ -54,6 +58,19 @@ final class SceneModel: ObservableObject { } } + // MARK Navigation API + + func openInBrowser() { + guard let link = selectedArticles.first?.preferredLink else { return } + + #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 + } + // MARK: Article Management API func toggleReadStatusForSelectedArticles() { diff --git a/Multiplatform/Shared/SceneNavigationView.swift b/Multiplatform/Shared/SceneNavigationView.swift index 6cb0d901d..35cd3b5a7 100644 --- a/Multiplatform/Shared/SceneNavigationView.swift +++ b/Multiplatform/Shared/SceneNavigationView.swift @@ -158,6 +158,7 @@ struct SceneNavigationView: View { } ToolbarItem { Button { + sceneModel.openInBrowser() } label: { AppAssets.openInBrowserImage }