mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-06 12:18:26 +00:00
Convert Secrets and SyncDatabase to approachable concurrency.
This commit is contained in:
1 parent
3a3dea47b6
commit
94aacab419
9 files changed
+27
-22
No files matched your search
@@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
import RSDatabaseObjC
|
||||
|
||||
public extension FMResultSet {
|
||||
nonisolated public extension FMResultSet {
|
||||
|
||||
func intWithCountResult() -> Int? {
|
||||
guard next() else {
|
||||
|
||||
@@ -16,7 +16,13 @@ let package = Package(
|
||||
.target(
|
||||
name: "Secrets",
|
||||
dependencies: [],
|
||||
exclude: ["SecretKey.swift.gyb"]
|
||||
exclude: ["SecretKey.swift.gyb"],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
.defaultIsolation(MainActor.self),
|
||||
.unsafeFlags(["-warnings-as-errors"])
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum CredentialsError: Error {
|
||||
public enum CredentialsError: Error, Sendable {
|
||||
case incompleteCredentials
|
||||
case unhandledError(status: OSStatus)
|
||||
}
|
||||
|
||||
public enum CredentialsType: String {
|
||||
public enum CredentialsType: String, Sendable {
|
||||
case basic = "password"
|
||||
case newsBlurBasic = "newsBlurBasic"
|
||||
case newsBlurSessionID = "newsBlurSessionId"
|
||||
@@ -24,7 +24,7 @@ public enum CredentialsType: String {
|
||||
case oauthRefreshToken = "oauthRefreshToken"
|
||||
}
|
||||
|
||||
public struct Credentials: Equatable {
|
||||
nonisolated public struct Credentials: Equatable, Sendable {
|
||||
public let type: CredentialsType
|
||||
public let username: String
|
||||
public let secret: String
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct CredentialsManager {
|
||||
nonisolated public struct CredentialsManager {
|
||||
|
||||
private static let keychainGroup: String? = {
|
||||
guard let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as? String else {
|
||||
@@ -20,7 +20,6 @@ public struct CredentialsManager {
|
||||
}()
|
||||
|
||||
public static func storeCredentials(_ credentials: Credentials, server: String) throws {
|
||||
|
||||
var query: [String: Any] = [kSecClass as String: kSecClassInternetPassword,
|
||||
kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlock,
|
||||
kSecAttrAccount as String: credentials.username,
|
||||
@@ -56,11 +55,9 @@ public struct CredentialsManager {
|
||||
if addStatus != errSecSuccess {
|
||||
throw CredentialsError.unhandledError(status: status)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static func retrieveCredentials(type: CredentialsType, server: String, username: String) throws -> Credentials? {
|
||||
|
||||
var query: [String: Any] = [kSecClass as String: kSecClassInternetPassword,
|
||||
kSecAttrAccount as String: username,
|
||||
kSecAttrServer as String: server,
|
||||
@@ -94,7 +91,6 @@ public struct CredentialsManager {
|
||||
}
|
||||
|
||||
return Credentials(type: type, username: username, secret: secret)
|
||||
|
||||
}
|
||||
|
||||
public static func removeCredentials(type: CredentialsType, server: String, username: String) throws {
|
||||
@@ -118,7 +114,5 @@ public struct CredentialsManager {
|
||||
guard status == errSecSuccess || status == errSecItemNotFound else {
|
||||
throw CredentialsError.unhandledError(status: status)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ salt = [byte for byte in os.urandom(64)]
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct SecretKey {
|
||||
nonisolated public struct SecretKey {
|
||||
% for secret in secrets:
|
||||
|
||||
public static var ${snake_to_camel(secret)}: String {
|
||||
@@ -56,11 +56,9 @@ public struct SecretKey {
|
||||
}
|
||||
|
||||
private static let isRunningUnitTests: Bool = {
|
||||
let environment = ProcessInfo.processInfo.environment
|
||||
if environment["XCTestConfigurationFilePath"] != nil {
|
||||
if ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if NSClassFromString("XCTestCase") != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.10
|
||||
// swift-tools-version:6.2
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
@@ -22,6 +22,13 @@ let package = Package(
|
||||
"RSCore",
|
||||
"RSDatabase",
|
||||
"Articles",
|
||||
]),
|
||||
],
|
||||
swiftSettings: [
|
||||
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
|
||||
.enableUpcomingFeature("InferIsolatedConformances"),
|
||||
.defaultIsolation(MainActor.self),
|
||||
.unsafeFlags(["-warnings-as-errors"])
|
||||
]
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -6,7 +6,7 @@
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
struct DatabaseKey {
|
||||
nonisolated struct DatabaseKey {
|
||||
// Sync Status
|
||||
static let articleID = "articleID"
|
||||
static let key = "key"
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
import Articles
|
||||
import RSDatabase
|
||||
|
||||
public struct SyncStatus: Hashable, Equatable {
|
||||
nonisolated public struct SyncStatus: Hashable, Equatable {
|
||||
public enum Key: String {
|
||||
case read
|
||||
case starred
|
||||
|
||||
@@ -11,7 +11,7 @@ import Articles
|
||||
import RSDatabase
|
||||
import RSDatabaseObjC
|
||||
|
||||
struct SyncStatusTable {
|
||||
nonisolated struct SyncStatusTable {
|
||||
static let name = "syncStatus"
|
||||
|
||||
static func selectForProcessing(limit: Int?, database: FMDatabase) -> Set<SyncStatus>? {
|
||||
@@ -98,7 +98,7 @@ struct SyncStatusTable {
|
||||
}
|
||||
}
|
||||
|
||||
private extension SyncStatusTable {
|
||||
nonisolated private extension SyncStatusTable {
|
||||
|
||||
static func statusWithRow(_ row: FMResultSet) -> SyncStatus? {
|
||||
guard let articleID = row.string(forColumn: DatabaseKey.articleID),
|
||||
|
||||
Reference in new issue
Block a user