diff --git a/Modules/RSCore/Sources/RSCore/AppKit/NSView+RSCore.swift b/Modules/RSCore/Sources/RSCore/AppKit/NSView+RSCore.swift index 831a0f784..d104741cc 100644 --- a/Modules/RSCore/Sources/RSCore/AppKit/NSView+RSCore.swift +++ b/Modules/RSCore/Sources/RSCore/AppKit/NSView+RSCore.swift @@ -35,6 +35,14 @@ public extension NSView { ]) } + func constraintsToMakeSubViewFullSize(_ subview: NSView) -> [NSLayoutConstraint] { + let leadingConstraint = NSLayoutConstraint(item: subview, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1.0, constant: 0.0) + let trailingConstraint = NSLayoutConstraint(item: subview, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing, multiplier: 1.0, constant: 0.0) + let topConstraint = NSLayoutConstraint(item: subview, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 0.0) + let bottomConstraint = NSLayoutConstraint(item: subview, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0) + return [leadingConstraint, trailingConstraint, topConstraint, bottomConstraint] + } + /// Sets the view's frame if it's different from the current frame. /// /// - Parameter rect: The new frame. diff --git a/Shared/Extensions/URL-Extensions.swift b/Modules/RSCore/Sources/RSCore/URL+RSCore.swift similarity index 64% rename from Shared/Extensions/URL-Extensions.swift rename to Modules/RSCore/Sources/RSCore/URL+RSCore.swift index 54ad6f742..b54537e7b 100644 --- a/Shared/Extensions/URL-Extensions.swift +++ b/Modules/RSCore/Sources/RSCore/URL+RSCore.swift @@ -8,13 +8,7 @@ import Foundation -extension URL { - - /// Extracts email address from a `URL` with a `mailto` scheme, otherwise `nil`. - var emailAddress: String? { - scheme == "mailto" ? URLComponents(url: self, resolvingAgainstBaseURL: false)?.path : nil - } - +public extension URL { /// Percent encoded `mailto` URL for use with `canOpenUrl`. If the URL doesn't contain the `mailto` scheme, this is `nil`. var percentEncodedEmailAddress: URL? { guard scheme == "mailto" else { @@ -26,16 +20,6 @@ extension URL { return URL(string: urlString) } - func valueFor(_ parameter: String) -> String? { - guard let components = URLComponents(url: self, resolvingAgainstBaseURL: false), - let queryItems = components.queryItems, - let value = queryItems.first(where: { $0.name == parameter })?.value else { - return nil - } - return value - - } - /// Percent-encode spaces in links that may contain spaces but are otherwise already percent-encoded. /// /// For performance reasons, try this only if initial URL init fails. diff --git a/Modules/RSCore/Sources/RSCore/UniformTypeIdentifiers+RSCore.swift b/Modules/RSCore/Sources/RSCore/UniformTypeIdentifiers+RSCore.swift index e33211a7e..5076ab2c9 100644 --- a/Modules/RSCore/Sources/RSCore/UniformTypeIdentifiers+RSCore.swift +++ b/Modules/RSCore/Sources/RSCore/UniformTypeIdentifiers+RSCore.swift @@ -8,7 +8,7 @@ import UniformTypeIdentifiers -extension UTType { +public extension UTType { static let opml = UTType("org.opml.opml")! } diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 436e0ea0f..c103eb572 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -415,7 +415,6 @@ Commands/MarkCommandValidationStatus.swift, ExtensionPoints/SendToMarsEditCommand.swift, ExtensionPoints/SendToMicroBlogCommand.swift, - "Extensions/NSView-Extensions.swift", Resources/NewsFax.nnwtheme, ShareExtension/SafariExt.js, ShareExtension/ShareDefaultContainer.swift, diff --git a/Shared/Extensions/NSAttributedString+NetNewsWire.swift b/Shared/Extensions/NSAttributedString+Extensions.swift similarity index 100% rename from Shared/Extensions/NSAttributedString+NetNewsWire.swift rename to Shared/Extensions/NSAttributedString+Extensions.swift diff --git a/Shared/Extensions/NSView-Extensions.swift b/Shared/Extensions/NSView-Extensions.swift deleted file mode 100644 index 2c5aff1d0..000000000 --- a/Shared/Extensions/NSView-Extensions.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// NSView-Extensions.swift -// NetNewsWire -// -// Created by Brent Simmons on 2/13/19. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -import AppKit - -extension NSView { - - func constraintsToMakeSubViewFullSize(_ subview: NSView) -> [NSLayoutConstraint] { - let leadingConstraint = NSLayoutConstraint(item: subview, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1.0, constant: 0.0) - let trailingConstraint = NSLayoutConstraint(item: subview, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing, multiplier: 1.0, constant: 0.0) - let topConstraint = NSLayoutConstraint(item: subview, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 0.0) - let bottomConstraint = NSLayoutConstraint(item: subview, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0) - return [leadingConstraint, trailingConstraint, topConstraint, bottomConstraint] - } -} diff --git a/Shared/Extensions/RSImage-AppIcons.swift b/Shared/Extensions/RSImage-AppIcons.swift deleted file mode 100644 index 273f17e27..000000000 --- a/Shared/Extensions/RSImage-AppIcons.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// RSImage-AppIcons.swift -// NetNewsWire -// -// Created by Nate Weaver on 2019-12-07. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -import Foundation -import RSCore - -extension RSImage { - static var appIconImage: RSImage? { - #if os(macOS) - return RSImage(named: NSImage.applicationIconName) - #elseif os(iOS) - // https://stackoverflow.com/a/51241158/14256 - if let icons = Bundle.main.infoDictionary?["CFBundleIcons"] as? [String: Any], - let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any], - let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String], - let lastIcon = iconFiles.last { - return RSImage(named: lastIcon) - } - return nil - #endif - } -} - -extension IconImage { - static let appIcon: IconImage? = { - if let image = RSImage.appIconImage { - return IconImage(image) - } - return nil - }() - - static let nnwFeedIcon = IconImage(Assets.Images.nnwFeedIcon) -} diff --git a/Shared/Extensions/RSImage-Extensions.swift b/Shared/Extensions/RSImage-Extensions.swift index 12f59350b..01e3e1370 100644 --- a/Shared/Extensions/RSImage-Extensions.swift +++ b/Shared/Extensions/RSImage-Extensions.swift @@ -36,6 +36,32 @@ extension RSImage { return RSImage(cgImage: cgImage, size: size) #endif } + + static var appIconImage: RSImage? { + #if os(macOS) + return RSImage(named: NSImage.applicationIconName) + #elseif os(iOS) + // https://stackoverflow.com/a/51241158/14256 + if let icons = Bundle.main.infoDictionary?["CFBundleIcons"] as? [String: Any], + let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any], + let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String], + let lastIcon = iconFiles.last { + return RSImage(named: lastIcon) + } + return nil + #endif + } +} + +extension IconImage { + static let appIcon: IconImage? = { + if let image = RSImage.appIconImage { + return IconImage(image) + } + return nil + }() + + static let nnwFeedIcon = IconImage(Assets.Images.nnwFeedIcon) } // MARK: - IconScalerQueue