Move things to RSCore that belong there.

This commit is contained in:
Brent Simmons committed 2025-11-19 16:22:26 -08:00
1 parent f5822c4766
commit b296bbd053
8 files changed
+36 -77

No files matched your search

@@ -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.
@@ -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.
@@ -8,7 +8,7 @@
import UniformTypeIdentifiers
extension UTType {
public extension UTType {
static let opml = UTType("org.opml.opml")!
}
-1
View File
@@ -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,
-20
View File
@@ -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]
}
}
-38
View File
@@ -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)
}
@@ -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