From 030d10163456462fc255cf6eee144a8d577d5a12 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 9 Jul 2024 21:08:34 -0700 Subject: [PATCH] Continue moving from AppAssets to AppAsset. --- Mac/AppAssets.swift | 32 ++++++------------- Mac/AppDelegate.swift | 2 +- Mac/MainWindow/MainWindowController.swift | 18 +++++------ .../TimelineContainerViewController.swift | 4 +-- Shared/AppAsset.swift | 7 ++++ .../SendToMarsEditCommand.swift | 2 +- .../SendToMicroBlogCommand.swift | 2 +- iOS/AppAssets.swift | 8 ----- iOS/Feeds/SidebarViewController.swift | 8 ++--- iOS/Timeline/TimelineViewController.swift | 8 ++--- 10 files changed, 39 insertions(+), 52 deletions(-) diff --git a/Mac/AppAssets.swift b/Mac/AppAssets.swift index 45e342b02..286809c13 100644 --- a/Mac/AppAssets.swift +++ b/Mac/AppAssets.swift @@ -15,9 +15,18 @@ extension AppAsset { struct Mac { + static let iconLightBackgroundColor = NSColor(named: NSColor.Name("iconLightBackgroundColor"))! + static let iconDarkBackgroundColor = NSColor(named: NSColor.Name("iconDarkBackgroundColor"))! + + static let marsEditIcon = RSImage.appImage("MarsEditIcon") + static let microblogIcon = RSImage.appImage("MicroblogIcon") + struct Toolbar { static let addNewSidebarItem = RSImage.systemImage("plus") - + static let sidebarToggle = RSImage.systemImage("sidebar.left") + static let refresh = RSImage.systemImage("arrow.clockwise") + static let articleTheme = RSImage.systemImage("doc.richtext") + static let cleanUpImage = RSImage.systemImage("wind") } } } @@ -25,23 +34,7 @@ extension AppAsset { struct AppAssets { - static let articleTheme = NSImage(systemSymbolName: "doc.richtext", accessibilityDescription: nil)! - static let cleanUpImage = NSImage(systemSymbolName: "wind", accessibilityDescription: nil)! - - static let marsEditIcon = NSImage(named: "MarsEditIcon")! - - static let microblogIcon = NSImage(named: "MicroblogIcon")! - - static let faviconTemplateImage = NSImage(named: "faviconTemplateImage")! - - static let filterActive = NSImage(systemSymbolName: "line.horizontal.3.decrease.circle.fill", accessibilityDescription: nil)! - - static let filterInactive = NSImage(systemSymbolName: "line.horizontal.3.decrease.circle", accessibilityDescription: nil)! - - static let iconLightBackgroundColor = NSColor(named: NSColor.Name("iconLightBackgroundColor"))! - - static let iconDarkBackgroundColor = NSColor(named: NSColor.Name("iconDarkBackgroundColor"))! static let legacyArticleExtractor = NSImage(named: "legacyArticleExtractor")! @@ -67,8 +60,6 @@ struct AppAssets { return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) }() - static let markAllAsReadImage = NSImage(named: "markAllAsRead")! - static let nextUnreadImage = NSImage(systemSymbolName: "chevron.down.circle", accessibilityDescription: nil)! static let openInBrowserImage = NSImage(systemSymbolName: "safari", accessibilityDescription: nil)! @@ -83,7 +74,6 @@ struct AppAssets { static let readOpenImage = NSImage(systemSymbolName: "circle", accessibilityDescription: nil)! - static let refreshImage = NSImage(systemSymbolName: "arrow.clockwise", accessibilityDescription: nil)! @MainActor static let searchFeedImage: IconImage = { @@ -92,8 +82,6 @@ struct AppAssets { static let shareImage = NSImage(systemSymbolName: "square.and.arrow.up", accessibilityDescription: nil)! - static let sidebarToggleImage = NSImage(systemSymbolName: "sidebar.left", accessibilityDescription: nil)! - static let starClosedImage = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)! static let starOpenImage = NSImage(systemSymbolName: "star", accessibilityDescription: nil)! diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 00cae5fed..d10af9671 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -164,7 +164,7 @@ import Sparkle os_log(.debug, "Is first run.") } - FaviconGenerator.faviconTemplateImage = AppAssets.faviconTemplateImage + FaviconGenerator.faviconTemplateImage = AppAsset.faviconTemplate importFeedsIfNeeded() updateSortMenuItems() diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 00585255e..132ecdd0f 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -796,11 +796,11 @@ extension MainWindowController: NSToolbarDelegate { case .sidebarToggle: let title = NSLocalizedString("Toggle Sidebar", comment: "Toggle Sidebar") - return buildToolbarButton(.toggleSidebar, title, AppAssets.sidebarToggleImage, "toggleTheSidebar:") + return buildToolbarButton(.toggleSidebar, title, AppAsset.Mac.Toolbar.sidebarToggle, "toggleTheSidebar:") case .refresh: let title = NSLocalizedString("Refresh", comment: "Refresh") - return buildToolbarButton(.refresh, title, AppAssets.refreshImage, "refreshAll:") + return buildToolbarButton(.refresh, title, AppAsset.Mac.Toolbar.refresh, "refreshAll:") case .newSidebarItemMenu: let toolbarItem = NSMenuToolbarItem(itemIdentifier: .newSidebarItemMenu) @@ -813,11 +813,11 @@ extension MainWindowController: NSToolbarDelegate { case .markAllAsRead: let title = NSLocalizedString("Mark All as Read", comment: "Mark All as Read") - return buildToolbarButton(.markAllAsRead, title, AppAssets.markAllAsReadImage, "markAllAsRead:") + return buildToolbarButton(.markAllAsRead, title, AppAsset.markAllAsRead, "markAllAsRead:") case .toggleReadArticlesFilter: let title = NSLocalizedString("Read Articles Filter", comment: "Read Articles Filter") - return buildToolbarButton(.toggleReadArticlesFilter, title, AppAssets.filterInactive, "toggleReadArticlesFilter:") + return buildToolbarButton(.toggleReadArticlesFilter, title, AppAsset.filterInactive, "toggleReadArticlesFilter:") case .timelineTrackingSeparator: return NSTrackingSeparatorToolbarItem(identifier: .timelineTrackingSeparator, splitView: splitViewController!.splitView, dividerIndex: 1) @@ -854,7 +854,7 @@ extension MainWindowController: NSToolbarDelegate { return buildToolbarButton(.openInBrowser, title, AppAssets.openInBrowserImage, "openArticleInBrowser:") case .articleThemeMenu: - articleThemeMenuToolbarItem.image = AppAssets.articleTheme + articleThemeMenuToolbarItem.image = AppAsset.Mac.Toolbar.articleTheme let description = NSLocalizedString("Article Theme", comment: "Article Theme") articleThemeMenuToolbarItem.toolTip = description articleThemeMenuToolbarItem.label = description @@ -869,7 +869,7 @@ extension MainWindowController: NSToolbarDelegate { case .cleanUp: let title = NSLocalizedString("Clean Up", comment: "Clean Up") - return buildToolbarButton(.cleanUp, title, AppAssets.cleanUpImage, "cleanUp:") + return buildToolbarButton(.cleanUp, title, AppAsset.Mac.Toolbar.cleanUpImage, "cleanUp:") default: break @@ -1190,7 +1190,7 @@ private extension MainWindowController { (item as? NSMenuItem)?.title = hideCommand if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { toolbarItem.toolTip = hideCommand - button.image = AppAssets.filterInactive + button.image = AppAsset.filterInactive } return false } @@ -1199,13 +1199,13 @@ private extension MainWindowController { (item as? NSMenuItem)?.title = showCommand if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { toolbarItem.toolTip = showCommand - button.image = AppAssets.filterActive + button.image = AppAsset.filterActive } } else { (item as? NSMenuItem)?.title = hideCommand if let toolbarItem = item as? NSToolbarItem, let button = toolbarItem.view as? NSButton { toolbarItem.toolTip = hideCommand - button.image = AppAssets.filterInactive + button.image = AppAsset.filterInactive } } diff --git a/Mac/MainWindow/Timeline/TimelineContainerViewController.swift b/Mac/MainWindow/Timeline/TimelineContainerViewController.swift index 5d0e83340..2819da8c1 100644 --- a/Mac/MainWindow/Timeline/TimelineContainerViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineContainerViewController.swift @@ -210,9 +210,9 @@ private extension TimelineContainerViewController { readFilteredButton.isHidden = false if isReadFiltered { - readFilteredButton.image = AppAssets.filterActive + readFilteredButton.image = AppAsset.filterActive } else { - readFilteredButton.image = AppAssets.filterInactive + readFilteredButton.image = AppAsset.filterInactive } } diff --git a/Shared/AppAsset.swift b/Shared/AppAsset.swift index 4327a594f..f2441219c 100644 --- a/Shared/AppAsset.swift +++ b/Shared/AppAsset.swift @@ -17,6 +17,10 @@ import Account final class AppAsset { + + static let markAllAsRead = RSImage.appImage("markAllAsRead") + static let faviconTemplate = RSImage.appImage("faviconTemplateImage") + struct Account { static let bazQux = RSImage.appImage("accountBazQux") @@ -76,4 +80,7 @@ final class AppAsset { static let on = RSImage.appImage("articleExtractorOn") static let onSF = RSImage.appImage("articleExtractorOnSF") } + + static let filterActive = RSImage.systemImage("line.horizontal.3.decrease.circle.fill") + static let filterInactive = RSImage.systemImage("line.horizontal.3.decrease.circle") } diff --git a/Shared/ExtensionPoints/SendToMarsEditCommand.swift b/Shared/ExtensionPoints/SendToMarsEditCommand.swift index 1ff9e5bdc..18c364808 100644 --- a/Shared/ExtensionPoints/SendToMarsEditCommand.swift +++ b/Shared/ExtensionPoints/SendToMarsEditCommand.swift @@ -14,7 +14,7 @@ import Core @MainActor final class SendToMarsEditCommand: SendToCommand { let title = "MarsEdit" - let image: RSImage? = AppAssets.marsEditIcon + let image: RSImage? = AppAsset.Mac.marsEditIcon private let marsEditApps = [UserApp(bundleID: "com.red-sweater.marsedit4"), UserApp(bundleID: "com.red-sweater.marsedit")] diff --git a/Shared/ExtensionPoints/SendToMicroBlogCommand.swift b/Shared/ExtensionPoints/SendToMicroBlogCommand.swift index 7ef43c7cc..92a4d96db 100644 --- a/Shared/ExtensionPoints/SendToMicroBlogCommand.swift +++ b/Shared/ExtensionPoints/SendToMicroBlogCommand.swift @@ -16,7 +16,7 @@ import Core @MainActor final class SendToMicroBlogCommand: SendToCommand { let title = "Micro.blog" - let image: RSImage? = AppAssets.microblogIcon + let image: RSImage? = AppAsset.Mac.microblogIcon private let microBlogApp = UserApp(bundleID: "blog.micro.mac") diff --git a/iOS/AppAssets.swift b/iOS/AppAssets.swift index 267caae71..e06df2362 100644 --- a/iOS/AppAssets.swift +++ b/iOS/AppAssets.swift @@ -37,20 +37,12 @@ struct AppAssets { static let editImage = UIImage(systemName: "square.and.pencil")! - static let faviconTemplateImage = RSImage(named: "faviconTemplateImage")! - - static let filterInactiveImage = UIImage(systemName: "line.horizontal.3.decrease.circle")! - - static let filterActiveImage = UIImage(systemName: "line.horizontal.3.decrease.circle.fill")! - static let folderOutlinePlus = UIImage(systemName: "folder.badge.plus")! static let fullScreenBackgroundColor = UIColor(named: "fullScreenBackgroundColor")! static let infoImage = UIImage(systemName: "info.circle")! - static let markAllAsReadImage = UIImage(named: "markAllAsRead")! - static let markBelowAsReadImage = UIImage(systemName: "arrowtriangle.down.circle")! static let markAboveAsReadImage = UIImage(systemName: "arrowtriangle.up.circle")! diff --git a/iOS/Feeds/SidebarViewController.swift b/iOS/Feeds/SidebarViewController.swift index 5b4a299cc..7d4122bad 100644 --- a/iOS/Feeds/SidebarViewController.swift +++ b/iOS/Feeds/SidebarViewController.swift @@ -705,12 +705,12 @@ private extension SidebarViewController { } func setFilterButtonToActive() { - filterButton?.image = AppAssets.filterActiveImage + filterButton?.image = AppAsset.filterActive filterButton?.accLabelText = NSLocalizedString("Selected - Filter Read Feeds", comment: "Selected - Filter Read Feeds") } func setFilterButtonToInactive() { - filterButton?.image = AppAssets.filterInactiveImage + filterButton?.image = AppAsset.filterInactive filterButton?.accLabelText = NSLocalizedString("Filter Read Feeds", comment: "Filter Read Feeds") } @@ -1101,7 +1101,7 @@ private extension SidebarViewController { let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command") let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String - let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in + let action = UIAction(title: title, image: AppAsset.markAllAsRead) { [weak self] action in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in Task { @MainActor in @@ -1122,7 +1122,7 @@ private extension SidebarViewController { let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command") let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, account.nameForDisplay) as String - let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in + let action = UIAction(title: title, image: AppAsset.markAllAsRead) { [weak self] action in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in // If you don't have this delay the screen flashes when it executes this code DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { diff --git a/iOS/Timeline/TimelineViewController.swift b/iOS/Timeline/TimelineViewController.swift index b2f23a2b8..6e5b71a8a 100644 --- a/iOS/Timeline/TimelineViewController.swift +++ b/iOS/Timeline/TimelineViewController.swift @@ -63,7 +63,7 @@ class TimelineViewController: UITableViewController, UndoableCommandRunner { NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) // Initialize Programmatic Buttons - filterButton = UIBarButtonItem(image: AppAssets.filterInactiveImage, style: .plain, target: self, action: #selector(toggleFilter(_:))) + filterButton = UIBarButtonItem(image: AppAsset.filterInactive, style: .plain, target: self, action: #selector(toggleFilter(_:))) firstUnreadButton = UIBarButtonItem(image: AppAssets.nextUnreadArticleImage, style: .plain, target: self, action: #selector(firstUnread(_:))) // Setup the Search Controller @@ -656,10 +656,10 @@ private extension TimelineViewController { } if coordinator.isReadArticlesFiltered { - filterButton?.image = AppAssets.filterActiveImage + filterButton?.image = AppAsset.filterActive filterButton?.accLabelText = NSLocalizedString("Selected - Filter Read Articles", comment: "Selected - Filter Read Articles") } else { - filterButton?.image = AppAssets.filterInactiveImage + filterButton?.image = AppAsset.filterInactive filterButton?.accLabelText = NSLocalizedString("Filter Read Articles", comment: "Filter Read Articles") } @@ -886,7 +886,7 @@ private extension TimelineViewController { let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command") let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String - let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in + let action = UIAction(title: title, image: AppAsset.markAllAsRead) { [weak self] action in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in Task { @MainActor in