Continue moving to structured and shared AppAsset over separate AppAssets.

This commit is contained in:
Brent Simmons 2024-07-25 20:14:58 -07:00
parent 1660d77668
commit 440a7fbefa
36 changed files with 100 additions and 263 deletions

View File

@ -7,16 +7,16 @@
//
import AppKit
import Core
import Account
import Images
import Core
extension AppAsset {
struct Mac {
static let iconLightBackgroundColor = NSColor(named: NSColor.Name("iconLightBackgroundColor"))!
static let iconDarkBackgroundColor = NSColor(named: NSColor.Name("iconDarkBackgroundColor"))!
static let iconLightBackgroundColor = NSColor(named: "iconLightBackgroundColor")!
static let iconDarkBackgroundColor = NSColor(named: "iconDarkBackgroundColor")!
static let marsEditIcon = RSImage.appImage("MarsEditIcon")
static let microblogIcon = RSImage.appImage("MicroblogIcon")
@ -27,6 +27,31 @@ extension AppAsset {
static let refresh = RSImage.systemImage("arrow.clockwise")
static let articleTheme = RSImage.systemImage("doc.richtext")
static let cleanUpImage = RSImage.systemImage("wind")
static let nextUnread = RSImage.systemImage("chevron.down.circle")
static let openInBrowser = RSImage.systemImage("safari")
static let readClosed = RSImage.systemImage("largecircle.fill.circle")
static let readOpen = RSImage.systemImage("circle")
static let share = AppAsset.share
}
struct PreferencesToolbar {
static let accounts = RSImage.systemImage("at")
static let general = RSImage.systemImage("gearshape")
static let advanced = RSImage.systemImage("gearshape.2")
}
struct Timeline {
static let swipeMarkRead = NSImage(systemSymbolName: "circle", accessibilityDescription: "Mark Read")!
.withSymbolConfiguration(.init(scale: .large))
static let swipeMarkUnread = NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: "Mark Unread")!
.withSymbolConfiguration(.init(scale: .large))
static let swipeMarkStarred = NSImage(systemSymbolName: "star.fill", accessibilityDescription: "Star")!
.withSymbolConfiguration(.init(scale: .large))
static let swipeMarkUnstarred = NSImage(systemSymbolName: "star", accessibilityDescription: "Unstar")!
.withSymbolConfiguration(.init(scale: .large))!
static let starSelected = RSImage.appImage("timelineStar").tinted(with: .white)
static let starUnselected = RSImage.appImage("timelineStar").tinted(with: AppAsset.starColor)
static let separatorColor = NSColor(named: "timelineSeparatorColor")!
}
}
}
@ -34,54 +59,11 @@ extension AppAsset {
struct AppAssets {
static let legacyArticleExtractor = NSImage(named: "legacyArticleExtractor")!
static let legacyArticleExtractorError = NSImage(named: "legacyArticleExtractorError")!
static let legacyArticleExtractorInactiveDark = NSImage(named: "legacyArticleExtractorInactiveDark")!
static let legacyArticleExtractorInactiveLight = NSImage(named: "legacyArticleExtractorInactiveLight")!
static let legacyArticleExtractorProgress1 = NSImage(named: "legacyArticleExtractorProgress1")
static let legacyArticleExtractorProgress2 = NSImage(named: "legacyArticleExtractorProgress2")
static let legacyArticleExtractorProgress3 = NSImage(named: "legacyArticleExtractorProgress3")
static let legacyArticleExtractorProgress4 = NSImage(named: "legacyArticleExtractorProgress4")
@MainActor
static let folderImage: IconImage = {
let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "AccentColor")!
let coloredImage = image.tinted(with: preferredColor)
return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
}()
static let nextUnreadImage = NSImage(systemSymbolName: "chevron.down.circle", accessibilityDescription: nil)!
static let openInBrowserImage = NSImage(systemSymbolName: "safari", accessibilityDescription: nil)!
static let preferencesToolbarAccountsImage = NSImage(systemSymbolName: "at", accessibilityDescription: nil)!
static let preferencesToolbarGeneralImage = NSImage(systemSymbolName: "gearshape", accessibilityDescription: nil)!
static let preferencesToolbarAdvancedImage = NSImage(systemSymbolName: "gearshape.2", accessibilityDescription: nil)!
static let readClosedImage = NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: nil)!
static let readOpenImage = NSImage(systemSymbolName: "circle", accessibilityDescription: nil)!
@MainActor
static let searchFeedImage: IconImage = {
return IconImage(NSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true, isBackgroundSupressed: true)
}()
static let shareImage = NSImage(systemSymbolName: "square.and.arrow.up", accessibilityDescription: nil)!
static let starClosedImage = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)!
static let starOpenImage = NSImage(systemSymbolName: "star", accessibilityDescription: nil)!
@ -89,17 +71,11 @@ struct AppAssets {
@MainActor
static let starredFeedImage: IconImage = {
let image = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "StarColor")!
let preferredColor = AppAsset.starColor
let coloredImage = image.tinted(with: preferredColor)
return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
}()
static let timelineSeparatorColor = NSColor(named: "timelineSeparatorColor")!
static let timelineStarSelected = NSImage(named: "timelineStar")?.tinted(with: .white)
static let timelineStarUnselected = NSImage(named: "timelineStar")?.tinted(with: starColor)
@MainActor
static let todayFeedImage: IconImage = {
let image = NSImage(systemSymbolName: "sun.max.fill", accessibilityDescription: nil)!
@ -115,18 +91,4 @@ struct AppAssets {
let coloredImage = image.tinted(with: preferredColor)
return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
}()
static let swipeMarkReadImage = NSImage(systemSymbolName: "circle", accessibilityDescription: "Mark Read")!
.withSymbolConfiguration(.init(scale: .large))
static let swipeMarkUnreadImage = NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: "Mark Unread")!
.withSymbolConfiguration(.init(scale: .large))
static let swipeMarkStarredImage = NSImage(systemSymbolName: "star.fill", accessibilityDescription: "Star")!
.withSymbolConfiguration(.init(scale: .large))
static let swipeMarkUnstarredImage = NSImage(systemSymbolName: "star", accessibilityDescription: "Unstar")!
.withSymbolConfiguration(.init(scale: .large))!
static let starColor = NSColor(named: NSColor.Name("StarColor"))!
}

View File

@ -824,7 +824,7 @@ extension MainWindowController: NSToolbarDelegate {
case .markRead:
let title = NSLocalizedString("Mark Read", comment: "Mark Read")
return buildToolbarButton(.markRead, title, AppAssets.readClosedImage, "toggleRead:")
return buildToolbarButton(.markRead, title, AppAsset.Mac.Toolbar.readClosed, "toggleRead:")
case .markStar:
let title = NSLocalizedString("Star", comment: "Star")
@ -832,7 +832,7 @@ extension MainWindowController: NSToolbarDelegate {
case .nextUnread:
let title = NSLocalizedString("Next Unread", comment: "Next Unread")
return buildToolbarButton(.nextUnread, title, AppAssets.nextUnreadImage, "nextUnread:")
return buildToolbarButton(.nextUnread, title, AppAsset.Mac.Toolbar.nextUnread, "nextUnread:")
case .readerView:
let toolbarItem = RSToolbarItem(itemIdentifier: .readerView)
@ -847,11 +847,11 @@ extension MainWindowController: NSToolbarDelegate {
case .share:
let title = NSLocalizedString("Share", comment: "Share")
return buildToolbarButton(.share, title, AppAssets.shareImage, "toolbarShowShareMenu:")
return buildToolbarButton(.share, title, AppAsset.Mac.Toolbar.share, "toolbarShowShareMenu:")
case .openInBrowser:
let title = NSLocalizedString("Open in Browser", comment: "Open in Browser")
return buildToolbarButton(.openInBrowser, title, AppAssets.openInBrowserImage, "openArticleInBrowser:")
return buildToolbarButton(.openInBrowser, title, AppAsset.Mac.Toolbar.openInBrowser, "openArticleInBrowser:")
case .articleThemeMenu:
articleThemeMenuToolbarItem.image = AppAsset.Mac.Toolbar.articleTheme
@ -1079,7 +1079,7 @@ private extension MainWindowController {
}
if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton {
button.image = markingRead ? AppAssets.readClosedImage : AppAssets.readOpenImage
button.image = markingRead ? AppAsset.Mac.Toolbar.readClosed : AppAsset.Mac.Toolbar.readOpen
}
return result

View File

@ -8,7 +8,7 @@
import AppKit
class TimelineTableCellView: NSTableCellView {
final class TimelineTableCellView: NSTableCellView {
private let titleView = TimelineTableCellView.multiLineTextField()
private let summaryView = TimelineTableCellView.multiLineTextField()
@ -19,7 +19,7 @@ class TimelineTableCellView: NSTableCellView {
private lazy var iconView = IconView()
private var starView = TimelineTableCellView.imageView(with: AppAssets.timelineStarUnselected, scaling: .scaleNone)
private var starView = TimelineTableCellView.imageView(with: AppAsset.Mac.Timeline.starUnselected, scaling: .scaleNone)
private lazy var textFields = {
return [self.dateView, self.feedNameView, self.titleView, self.summaryView, self.textView]
@ -258,9 +258,9 @@ private extension TimelineTableCellView {
func updateStarView() {
if isSelected && isEmphasized {
starView.image = AppAssets.timelineStarSelected
starView.image = AppAsset.Mac.Timeline.starSelected
} else {
starView.image = AppAssets.timelineStarUnselected
starView.image = AppAsset.Mac.Timeline.starUnselected
}
showOrHideView(starView, !cellData.starred)
}

View File

@ -59,7 +59,7 @@ class TimelineTableRowView : NSTableRowView {
separator = NSView()
separator!.translatesAutoresizingMaskIntoConstraints = false
separator!.wantsLayer = true
separator!.layer?.backgroundColor = AppAssets.timelineSeparatorColor.cgColor
separator!.layer?.backgroundColor = AppAsset.Mac.Timeline.separatorColor.cgColor
addSubview(separator!)

View File

@ -938,7 +938,7 @@ extension TimelineViewController: NSTableViewDelegate {
self.toggleArticleRead(article);
tableView.rowActionsVisible = false
}
action.image = article.status.read ? AppAssets.swipeMarkUnreadImage : AppAssets.swipeMarkReadImage
action.image = article.status.read ? AppAsset.Mac.Timeline.swipeMarkUnread : AppAsset.Mac.Timeline.swipeMarkRead
return [action]
case .trailing:
@ -946,8 +946,8 @@ extension TimelineViewController: NSTableViewDelegate {
self.toggleArticleStarred(article);
tableView.rowActionsVisible = false
}
action.backgroundColor = AppAssets.starColor
action.image = article.status.starred ? AppAssets.swipeMarkUnstarredImage : AppAssets.swipeMarkStarredImage
action.backgroundColor = AppAsset.starColor
action.image = article.status.starred ? AppAsset.Mac.Timeline.swipeMarkUnstarred : AppAsset.Mac.Timeline.swipeMarkStarred
return [action]
@unknown default:

View File

@ -35,10 +35,10 @@ class PreferencesWindowController : NSWindowController, NSToolbarDelegate {
var specs = [PreferencesToolbarItemSpec]()
specs += [PreferencesToolbarItemSpec(identifierRawValue: ToolbarItemIdentifier.General,
name: NSLocalizedString("General", comment: "Preferences"),
image: AppAssets.preferencesToolbarGeneralImage)]
image: AppAsset.Mac.PreferencesToolbar.general)]
specs += [PreferencesToolbarItemSpec(identifierRawValue: ToolbarItemIdentifier.Accounts,
name: NSLocalizedString("Accounts", comment: "Preferences"),
image: AppAssets.preferencesToolbarAccountsImage)]
image: AppAsset.Mac.PreferencesToolbar.accounts)]
// Omit the Advanced Preferences for now because the Software Update related functionality is
// forbidden/non-applicable, and we can rely upon Apple to some extent for crash reports. We
@ -47,7 +47,7 @@ class PreferencesWindowController : NSWindowController, NSToolbarDelegate {
#if !MAC_APP_STORE
specs += [PreferencesToolbarItemSpec(identifierRawValue: ToolbarItemIdentifier.Advanced,
name: NSLocalizedString("Advanced", comment: "Preferences"),
image: AppAssets.preferencesToolbarAdvancedImage)]
image: AppAsset.Mac.PreferencesToolbar.advanced)]
#endif
return specs
}()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

View File

@ -1,22 +0,0 @@
{
"images" : [
{
"filename" : "ArticleExtractor.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ArticleExtractor@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -1,12 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "ArticleExtractorError.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

View File

@ -1,22 +0,0 @@
{
"images" : [
{
"filename" : "ArticleExtractorInactiveDark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ArticleExtractorInactiveDark@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

View File

@ -1,22 +0,0 @@
{
"images" : [
{
"filename" : "ArticleExtractorInactiveLight.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ArticleExtractorInactiveLight@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 B

View File

@ -1,22 +0,0 @@
{
"images" : [
{
"filename" : "ArticleExtractorProgress1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ArticleExtractorProgress1@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

View File

@ -1,22 +0,0 @@
{
"images" : [
{
"filename" : "ArticleExtractorProgress2.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ArticleExtractorProgress2@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

View File

@ -1,22 +0,0 @@
{
"images" : [
{
"filename" : "ArticleExtractorProgress3.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ArticleExtractorProgress3@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 B

View File

@ -1,22 +0,0 @@
{
"images" : [
{
"filename" : "ArticleExtractorProgress4.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ArticleExtractorProgress4@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,16 @@
//
// RSColor.swift
//
//
// Created by Brent Simmons on 7/9/24.
//
#if os(macOS)
import AppKit
public typealias RSColor = NSColor
#endif
#if os(iOS)
import UIKit
public typealias RSColor = UIColor
#endif

View File

@ -14,12 +14,43 @@ import UIKit
import Core
import Account
import Images
final class AppAsset {
static let markAllAsRead = RSImage.appImage("markAllAsRead")
static let faviconTemplate = RSImage.appImage("faviconTemplateImage")
static let share = RSImage.systemImage("square.and.arrow.up")
static let starColor = RSColor(named: "StarColor")!
@MainActor static let folder: IconImage = {
#if os(macOS)
let image = RSImage.systemImage("folder")
let preferredColor = NSColor(named: "AccentColor")!
let coloredImage = image.tinted(with: preferredColor)
return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
#else
let image = RSImage.systemImage("folder.fill")
let preferredColor = AppAssets.secondaryAccentColor
return IconImage(image, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
#endif
}()
@MainActor static let searchFeedImage: IconImage = {
#if os(macOS)
IconImage(NSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true, isBackgroundSupressed: true)
#else
IconImage(UIImage(systemName: "magnifyingglass")!, isSymbol: true)
#endif
}()
struct Account {

View File

@ -35,6 +35,6 @@ extension Feed: SmallIconProvider {
extension Folder: SmallIconProvider {
var smallIcon: IconImage? {
AppAssets.folderImage
AppAsset.folder
}
}

View File

@ -47,8 +47,6 @@ struct AppAssets {
static let markAboveAsReadImage = UIImage(systemName: "arrowtriangle.up.circle")!
@MainActor static let folderImage = IconImage(UIImage(systemName: "folder.fill")!, isSymbol: true, isBackgroundSupressed: true, preferredColor: AppAssets.secondaryAccentColor.cgColor)
static let folderImageNonIcon = UIImage(systemName: "folder.fill")!.withRenderingMode(.alwaysOriginal).withTintColor(.secondaryLabel)
static let moreImage = UIImage(systemName: "ellipsis.circle")!
@ -73,26 +71,22 @@ struct AppAssets {
static let sectionHeaderColor = UIColor(named: "sectionHeaderColor")!
static let shareImage = UIImage(systemName: "square.and.arrow.up")!
static let smartFeedImage = UIImage(systemName: "gear")!
static let starColor = UIColor(named: "starColor")!
static let starClosedImage = UIImage(systemName: "star.fill")!
static let starOpenImage = UIImage(systemName: "star")!
@MainActor static let starredFeedImage: IconImage = {
let image = UIImage(systemName: "star.fill")!
return IconImage(image, isSymbol: true, isBackgroundSupressed: true, preferredColor: AppAssets.starColor.cgColor)
return IconImage(image, isSymbol: true, isBackgroundSupressed: true, preferredColor: AppAsset.starColor.cgColor)
}()
static let tickMarkColor = UIColor(named: "tickMarkColor")!
static let timelineStarImage: UIImage = {
let image = UIImage(systemName: "star.fill")!
return image.withTintColor(AppAssets.starColor, renderingMode: .alwaysOriginal)
return image.withTintColor(AppAsset.starColor, renderingMode: .alwaysOriginal)
}()
@MainActor static let todayFeedImage: IconImage = {

View File

@ -868,7 +868,7 @@ private extension WebViewController {
func shareAction() -> UIAction {
let title = NSLocalizedString("Share", comment: "Share")
return UIAction(title: title, image: AppAssets.shareImage) { [weak self] action in
return UIAction(title: title, image: AppAsset.share) { [weak self] action in
self?.showActivityDialog()
}
}

View File

@ -49,7 +49,7 @@ class ShareFolderPickerController: UITableViewController {
if let account = container as? ExtensionAccount {
cell.icon.image = AppAsset.Account.image(for: account.type)
} else {
cell.icon.image = AppAssets.folderImage.image
cell.icon.image = AppAsset.folder.image
}
cell.label?.text = container?.name ?? ""

View File

@ -285,7 +285,7 @@ class TimelineViewController: UITableViewController, UndoableCommandRunner {
}
starAction.image = article.status.starred ? AppAssets.starOpenImage : AppAssets.starClosedImage
starAction.backgroundColor = AppAssets.starColor
starAction.backgroundColor = AppAsset.starColor
// Set up the read action
let moreTitle = NSLocalizedString("More", comment: "More")
@ -984,7 +984,7 @@ private extension TimelineViewController {
func shareAction(_ article: Article, indexPath: IndexPath) -> UIAction? {
guard let url = article.preferredURL else { return nil }
let title = NSLocalizedString("Share", comment: "Share")
let action = UIAction(title: title, image: AppAssets.shareImage) { [weak self] action in
let action = UIAction(title: title, image: AppAsset.share) { [weak self] action in
self?.shareDialogForTableCell(indexPath: indexPath, url: url, title: article.title)
}
return action