From 91ea6f28eeb66d8f7904f2f51a1ad93d3c848ed2 Mon Sep 17 00:00:00 2001 From: Joe Heck Date: Fri, 22 Mar 2024 10:11:40 -0700 Subject: [PATCH 1/2] a suite of small concurrency warning fixes --- Core/Sources/Core/RSScreen.swift | 4 ++-- Mac/AppAssets.swift | 5 +++++ Mac/ErrorHandler.swift | 5 +++++ Shared/ArticleStyles/ArticleTheme.swift | 2 +- Shared/ArticleStyles/ArticleThemePlist.swift | 2 +- Shared/Extensions/RSImage-AppIcons.swift | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Core/Sources/Core/RSScreen.swift b/Core/Sources/Core/RSScreen.swift index 4fee278db..78fd8faed 100644 --- a/Core/Sources/Core/RSScreen.swift +++ b/Core/Sources/Core/RSScreen.swift @@ -10,7 +10,7 @@ import AppKit public class RSScreen { - public static var maxScreenScale = CGFloat(2) + public static let maxScreenScale = CGFloat(2) } #endif @@ -19,7 +19,7 @@ public class RSScreen { import UIKit public class RSScreen { - public static var maxScreenScale = CGFloat(3) + public static let maxScreenScale = CGFloat(3) } #endif diff --git a/Mac/AppAssets.swift b/Mac/AppAssets.swift index a71a44364..f445b5692 100644 --- a/Mac/AppAssets.swift +++ b/Mac/AppAssets.swift @@ -71,6 +71,7 @@ struct AppAssets { static let legacyArticleExtractorProgress4 = NSImage(named: "legacyArticleExtractorProgress4") + @MainActor static let folderImage: IconImage = { let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)! let preferredColor = NSColor(named: "AccentColor")! @@ -96,6 +97,7 @@ struct AppAssets { static let refreshImage = NSImage(systemSymbolName: "arrow.clockwise", accessibilityDescription: nil)! + @MainActor static let searchFeedImage: IconImage = { return IconImage(NSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true, isBackgroundSupressed: true) }() @@ -108,6 +110,7 @@ struct AppAssets { static let starOpenImage = NSImage(systemSymbolName: "star", accessibilityDescription: nil)! + @MainActor static let starredFeedImage: IconImage = { let image = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)! let preferredColor = NSColor(named: "StarColor")! @@ -121,6 +124,7 @@ struct AppAssets { static let timelineStarUnselected = NSImage(named: "timelineStar")?.tinted(with: starColor) + @MainActor static let todayFeedImage: IconImage = { let image = NSImage(systemSymbolName: "sun.max.fill", accessibilityDescription: nil)! let preferredColor = NSColor.orange @@ -128,6 +132,7 @@ struct AppAssets { return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor) }() + @MainActor static let unreadFeedImage: IconImage = { let image = NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: nil)! let preferredColor = NSColor(named: "AccentColor")! diff --git a/Mac/ErrorHandler.swift b/Mac/ErrorHandler.swift index 258712b5e..33ff42275 100644 --- a/Mac/ErrorHandler.swift +++ b/Mac/ErrorHandler.swift @@ -10,6 +10,11 @@ import AppKit import Account import os.log +// asserts that OSLog is a sendable type +// @preconcurrency import os.log _should_ resolve the warning in this scenario, but does +// not due to a bug (in Swift 5.10) +extension OSLog: @unchecked Sendable { } + struct ErrorHandler { private static let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Account") diff --git a/Shared/ArticleStyles/ArticleTheme.swift b/Shared/ArticleStyles/ArticleTheme.swift index 302c45a53..832e4ef8b 100644 --- a/Shared/ArticleStyles/ArticleTheme.swift +++ b/Shared/ArticleStyles/ArticleTheme.swift @@ -8,7 +8,7 @@ import Foundation -struct ArticleTheme: Equatable { +struct ArticleTheme: Equatable, Sendable { static let defaultTheme = ArticleTheme() static let nnwThemeSuffix = ".nnwtheme" diff --git a/Shared/ArticleStyles/ArticleThemePlist.swift b/Shared/ArticleStyles/ArticleThemePlist.swift index f324cdbde..b18a38146 100644 --- a/Shared/ArticleStyles/ArticleThemePlist.swift +++ b/Shared/ArticleStyles/ArticleThemePlist.swift @@ -8,7 +8,7 @@ import Foundation -public struct ArticleThemePlist: Codable, Equatable { +public struct ArticleThemePlist: Codable, Equatable, Sendable { public var name: String public var themeIdentifier: String public var creatorHomePage: String diff --git a/Shared/Extensions/RSImage-AppIcons.swift b/Shared/Extensions/RSImage-AppIcons.swift index 04964d85d..2015d1284 100644 --- a/Shared/Extensions/RSImage-AppIcons.swift +++ b/Shared/Extensions/RSImage-AppIcons.swift @@ -27,7 +27,7 @@ extension RSImage { } extension IconImage { - static var appIcon: IconImage? = { + static let appIcon: IconImage? = { if let image = RSImage.appIconImage { return IconImage(image) } From d28b36d15ae34ee806b5f00e368a35e7a68fdab1 Mon Sep 17 00:00:00 2001 From: Joe Heck Date: Fri, 22 Mar 2024 11:35:04 -0700 Subject: [PATCH 2/2] updating based on PR feedback --- Core/Sources/Core/RSImage.swift | 8 +++++++ Core/Sources/Core/RSScreen.swift | 25 ---------------------- Mac/ErrorHandler.swift | 3 +++ Shared/Extensions/RSImage-Extensions.swift | 2 +- 4 files changed, 12 insertions(+), 26 deletions(-) delete mode 100644 Core/Sources/Core/RSScreen.swift diff --git a/Core/Sources/Core/RSImage.swift b/Core/Sources/Core/RSImage.swift index 6549f02a1..4e190e53f 100644 --- a/Core/Sources/Core/RSImage.swift +++ b/Core/Sources/Core/RSImage.swift @@ -20,6 +20,14 @@ public typealias RSImage = UIImage public extension RSImage { +#if os(macOS) + static let maxScreenScale = CGFloat(2) +#endif + +#if os(iOS) + static let maxScreenScale = CGFloat(3) +#endif + /// Create a colored image from the source image using a specified color. /// /// - Parameter color: The color with which to fill the mask image. diff --git a/Core/Sources/Core/RSScreen.swift b/Core/Sources/Core/RSScreen.swift deleted file mode 100644 index 78fd8faed..000000000 --- a/Core/Sources/Core/RSScreen.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// RSScreen.swift -// RSCore -// -// Created by Maurice Parker on 4/11/19. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -#if os(macOS) -import AppKit - -public class RSScreen { - public static let maxScreenScale = CGFloat(2) -} - -#endif - -#if os(iOS) -import UIKit - -public class RSScreen { - public static let maxScreenScale = CGFloat(3) -} - -#endif diff --git a/Mac/ErrorHandler.swift b/Mac/ErrorHandler.swift index 33ff42275..a4dee6929 100644 --- a/Mac/ErrorHandler.swift +++ b/Mac/ErrorHandler.swift @@ -13,6 +13,9 @@ import os.log // asserts that OSLog is a sendable type // @preconcurrency import os.log _should_ resolve the warning in this scenario, but does // not due to a bug (in Swift 5.10) +#if swift(>=6.0) + #warning("Reevaluate whether this Sendable decoration is still needed for OSLog.") +#endif extension OSLog: @unchecked Sendable { } struct ErrorHandler { diff --git a/Shared/Extensions/RSImage-Extensions.swift b/Shared/Extensions/RSImage-Extensions.swift index c45067c89..fae8d6291 100644 --- a/Shared/Extensions/RSImage-Extensions.swift +++ b/Shared/Extensions/RSImage-Extensions.swift @@ -22,7 +22,7 @@ extension RSImage { } static func scaledForIcon(_ data: Data) -> RSImage? { - let scaledMaxPixelSize = Int(ceil(CGFloat(RSImage.maxIconSize) * RSScreen.maxScreenScale)) + let scaledMaxPixelSize = Int(ceil(CGFloat(RSImage.maxIconSize) * maxScreenScale)) guard var cgImage = RSImage.scaleImage(data, maxPixelSize: scaledMaxPixelSize) else { return nil }