From 29a68a3d8948ee3a660a3f4b448501c3c2ac96a4 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 10 Nov 2024 21:22:05 +0300 Subject: [PATCH 01/11] Update CI and delete CloudKit services --- .github/workflows/ci.yml | 41 ++++- Package.swift | 9 - .../AssetsCloudKitService.swift | 70 ------- .../DressWeatherCloudKitService.swift | 172 ------------------ .../Models/AssetIcon.swift | 16 -- .../Models/WeatherCity.swift | 64 ------- .../Models/WeatherDress.swift | 88 --------- .../Models/WeatherPlace.swift | 60 ------ .../ServiceRegistering.swift | 13 -- .../Support/CloudKitIdentifier.swift | 10 - .../BodyMassService.swift | 2 +- 11 files changed, 32 insertions(+), 513 deletions(-) delete mode 100644 Sources/OversizeCloudKitService/AssetsCloudKitService.swift delete mode 100644 Sources/OversizeCloudKitService/DressWeatherCloudKitService.swift delete mode 100644 Sources/OversizeCloudKitService/Models/AssetIcon.swift delete mode 100644 Sources/OversizeCloudKitService/Models/WeatherCity.swift delete mode 100644 Sources/OversizeCloudKitService/Models/WeatherDress.swift delete mode 100644 Sources/OversizeCloudKitService/Models/WeatherPlace.swift delete mode 100644 Sources/OversizeCloudKitService/ServiceRegistering.swift delete mode 100644 Sources/OversizeCloudKitService/Support/CloudKitIdentifier.swift diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f12b5ba..efc3e03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,31 +1,52 @@ -name: CI - Push +name: CI on: push: - branches: ["main"] + branches: + - '**' workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: build-swiftpm: - name: Build packages + name: Build SwiftPM uses: oversizedev/GithubWorkflows/.github/workflows/build-swiftpm.yml@main strategy: matrix: - packages: [OversizeServices, OversizeHealthService, OversizeCloudKitService, OversizeStoreService, OversizeLocationService, OversizeCalendarService, OversizeContactsService, OversizeNotificationService, OversizeFileManagerService] + packages: + - OversizeServices + - OversizeHealthService + - OversizeStoreService + - OversizeLocationService + - OversizeCalendarService + - OversizeContactsService + - OversizeNotificationService + - OversizeFileManagerService + destination: + - platform=iOS Simulator,name=iPhone 16,OS=18.1 + - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.1 + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.1 + - platform=macOS,arch=arm64 + with: package: ${{ matrix.packages }} + destination: ${{ matrix.destination }} secrets: inherit - # tests: - # name: Test - # needs: build-swiftpm - # uses: oversizedev/GithubWorkflows/.github/workflows/test.yml@main - # secrets: inherit + tests: + name: Test + needs: build-swiftpm + uses: oversizedev/GithubWorkflows/.github/workflows/test.yml@main + secrets: inherit bump: name: Bump version - needs: build-swiftpm + needs: tests + if: github.ref == 'refs/heads/main' uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main secrets: inherit diff --git a/Package.swift b/Package.swift index 2ed2161..65c279c 100644 --- a/Package.swift +++ b/Package.swift @@ -35,7 +35,6 @@ let package = Package( ], products: [ .library(name: "OversizeHealthService", targets: ["OversizeHealthService"]), - .library(name: "OversizeCloudKitService", targets: ["OversizeCloudKitService"]), .library(name: "OversizeServices", targets: ["OversizeServices"]), .library(name: "OversizeStoreService", targets: ["OversizeStoreService"]), .library(name: "OversizeLocationService", targets: ["OversizeLocationService"]), @@ -94,14 +93,6 @@ let package = Package( .product(name: "Factory", package: "Factory"), ] ), - .target( - name: "OversizeCloudKitService", - dependencies: [ - .product(name: "OversizeCore", package: "OversizeCore"), - .product(name: "OversizeModels", package: "OversizeModels"), - .product(name: "Factory", package: "Factory"), - ] - ), .target( name: "OversizeStoreService", dependencies: [ diff --git a/Sources/OversizeCloudKitService/AssetsCloudKitService.swift b/Sources/OversizeCloudKitService/AssetsCloudKitService.swift deleted file mode 100644 index 1d9d10e..0000000 --- a/Sources/OversizeCloudKitService/AssetsCloudKitService.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright © 2022 Alexander Romanov -// AssetsCloudKitService.swift -// - -import CloudKit -import Foundation -import OversizeModels -import SwiftUI -#if canImport(UIKit) - import UIKit -#endif - -public final class AssetsCloudKitService { - private var database: CKDatabase - private var container: CKContainer - - public init() { - container = CKContainer(identifier: CloudKitIdentifier.dressWeather.rawValue) - database = container.publicCloudDatabase - } -} - -public extension AssetsCloudKitService { - func saveIcon(name: String, image _: URL? = nil) async -> Result { - guard let path = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first?.appendingPathComponent("\(name).svg") else { return .failure(.cloudKit(type: .unknown)) } - do { - let record = CKRecord(recordType: "AssetIcon") - record.setValue(name, forKey: "name") - - let svg = URL(string: "https://openclipart.org/download/181651/manhammock.svg")! - let data = try? Data(contentsOf: svg) - - try data!.write(to: path) - let asset = CKAsset(fileURL: path) - record.setValue(asset, forKey: "icon") - - _ = try await database.save(record) - return .success(true) - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - func fetchIcons() async -> Result<[AssetIcon], AppError> { - do { - let query = CKQuery(recordType: "AssetIcon", predicate: NSPredicate(value: true)) - if #available(iOS 15.0, *) { - let data = try await database.records(matching: query) - let records = data.matchResults.compactMap { try? $0.1.get() } - - var icons = [AssetIcon]() - - for record in records { - let name = record["name"] as! String - let asset = record["icon"] as? CKAsset - let url = asset?.fileURL - let assetIcon = AssetIcon(name: name, imageUrl: url) - icons.append(assetIcon) - } - return .success(icons) - } else { - print("🔴 Method FetchCities dont work in iOS 14") - return .failure(.cloudKit(type: .unknown)) - } - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } -} diff --git a/Sources/OversizeCloudKitService/DressWeatherCloudKitService.swift b/Sources/OversizeCloudKitService/DressWeatherCloudKitService.swift deleted file mode 100644 index 6cb6bf9..0000000 --- a/Sources/OversizeCloudKitService/DressWeatherCloudKitService.swift +++ /dev/null @@ -1,172 +0,0 @@ -// -// Copyright © 2022 Alexander Romanov -// DressWeatherCloudKitService.swift -// - -import CloudKit -import Foundation -import OversizeModels - -public protocol DressWeatherCloudKitServiceProtocol { - func fetchAccountStatus() async -> Result - func fetchCities() async -> Result<[WeatherCity], AppError> - func fetchPlaces() async -> Result<[WeatherPlace], AppError> - func fetchDresses() async -> Result<[WeatherDress], AppError> - - func deleteCity(_ recordId: CKRecord.ID) async -> Result - func deletePlace(_ recordId: CKRecord.ID) async -> Result - func deleteDress(_ recordId: CKRecord.ID) async -> Result - - func saveCity(_ city: WeatherCity) async -> Result - // func savePlace(_ cityRecordId: CKRecord.ID, place: WeatherPlace) async -> Result - func savePlace(_ place: WeatherPlace) async -> Result - func saveDress(_ dress: WeatherDress) async -> Result -} - -final class DressWeatherCloudKitService { - private var database: CKDatabase - private var container: CKContainer - - public init() { - container = CKContainer(identifier: CloudKitIdentifier.dressWeather.rawValue) - database = container.privateCloudDatabase - } -} - -extension DressWeatherCloudKitService: DressWeatherCloudKitServiceProtocol { - public func fetchAccountStatus() async -> Result { - do { - let result = try await CKContainer.default().accountStatus() - return .success(result) - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - public func deleteCity(_ recordId: CKRecord.ID) async -> Result { - do { - let result = try await database.deleteRecord(withID: recordId) - return .success(result) - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - public func deleteDress(_ recordId: CKRecord.ID) async -> Result { - do { - let result = try await database.deleteRecord(withID: recordId) - return .success(result) - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - public func deletePlace(_ recordId: CKRecord.ID) async -> Result { - do { - let result = try await database.deleteRecord(withID: recordId) - return .success(result) - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - public func fetchCities() async -> Result<[WeatherCity], AppError> { - do { - let query = CKQuery(recordType: WeatherCity.WeatherCityRecordKeys.type.rawValue, predicate: NSPredicate(value: true)) - if #available(iOS 15.0, *) { - let data = try await database.records(matching: query) - let records = data.matchResults.compactMap { try? $0.1.get() } - return .success(records.compactMap(WeatherCity.init)) - } else { - print("🔴 Method FetchCities dont work in iOS 14") - return .failure(.cloudKit(type: .unknown)) - } - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - public func fetchDresses() async -> Result<[WeatherDress], AppError> { - do { - let query = CKQuery(recordType: WeatherDress.WeatherDressRecordKeys.type.rawValue, predicate: NSPredicate(value: true)) - if #available(iOS 15.0, *) { - let data = try await database.records(matching: query) - let records = data.matchResults.compactMap { try? $0.1.get() } - return .success(records.compactMap(WeatherDress.init)) - } else { - print("🔴 Method FetchCities dont work in iOS 14") - return .failure(.cloudKit(type: .unknown)) - } - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - // swiftformat:disable all - public func fetchPlaces(for cityId: CKRecord.ID) async -> Result<[WeatherPlace], AppError> { - do { - let reference = CKRecord.Reference(recordID: cityId, action: .deleteSelf) - let query = CKQuery(recordType: WeatherPlace.WeatherPlaceRecordKeys.type.rawValue, - predicate: NSPredicate(format: "\(WeatherPlace.WeatherPlaceRecordKeys.type.rawValue) == %@", reference)) - if #available(iOS 15.0, *) { - let data = try await database.records(matching: query) - let records = data.matchResults.compactMap { try? $0.1.get() } - return .success(records.compactMap(WeatherPlace.init)) - } else { - print("🔴 Method FetchCities dont work in iOS 14") - return .failure(.cloudKit(type: .unknown)) - } - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - // swiftformat:disable all - public func fetchPlaces() async -> Result<[WeatherPlace], AppError> { - do { - let query = CKQuery(recordType: WeatherPlace.WeatherPlaceRecordKeys.type.rawValue, predicate: NSPredicate(value: true)) - if #available(iOS 15.0, *) { - let data = try await database.records(matching: query) - let records = data.matchResults.compactMap { try? $0.1.get() } - return .success(records.compactMap(WeatherPlace.init)) - } else { - print("🔴 Method FetchCities dont work in iOS 14") - return .failure(.cloudKit(type: .unknown)) - } - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - public func saveCity(_ city: WeatherCity) async -> Result { - do { - let result = try await database.save(city.record) - guard let city = WeatherCity(from: result) else { return .failure(.cloudKit(type: .unknown)) } - return .success(city) - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - public func saveDress(_ dress: WeatherDress) async -> Result { - do { - let result = try await database.save(dress.record) - guard let dress = WeatherDress(from: result) else { return .failure(.cloudKit(type: .unknown)) } - return .success(dress) - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } - - - - public func savePlace(_ place: WeatherPlace) async -> Result { - do { - let result = try await database.save(place.record) - guard let city = WeatherPlace(from: result) else { return .failure(.cloudKit(type: .unknown)) } - return .success(city) - } catch { - return .failure(.cloudKit(type: .unknown)) - } - } -} diff --git a/Sources/OversizeCloudKitService/Models/AssetIcon.swift b/Sources/OversizeCloudKitService/Models/AssetIcon.swift deleted file mode 100644 index 2638a0d..0000000 --- a/Sources/OversizeCloudKitService/Models/AssetIcon.swift +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright © 2022 Alexander Romanov -// AssetIcon.swift -// - -import CloudKit -import Foundation - -public struct AssetIcon: Identifiable { - public let id: UUID = .init() - - public let name: String - // public let style: String - // public let category: String - public let imageUrl: URL? -} diff --git a/Sources/OversizeCloudKitService/Models/WeatherCity.swift b/Sources/OversizeCloudKitService/Models/WeatherCity.swift deleted file mode 100644 index d62e54b..0000000 --- a/Sources/OversizeCloudKitService/Models/WeatherCity.swift +++ /dev/null @@ -1,64 +0,0 @@ -// -// Copyright © 2022 Alexander Romanov -// WeatherCity.swift -// - -import CloudKit -import Foundation - -public struct WeatherCity: Identifiable { - public let name: String - public let country: String - public let location: CLLocation - public let cityId: Int - public let position: Int - - // MARK: - Sourcery generated - - public var recordId: CKRecord.ID? - public var id: String { recordId?.recordName ?? UUID().uuidString } - - public enum WeatherCityRecordKeys: String { - case type = "WeatherCity" - case name - case country - case location - case cityId - case position - } - - public init(recordId: CKRecord.ID? = nil, name: String, country: String, location: CLLocation, cityId: Int, position: Int) { - self.recordId = recordId - self.name = name - self.country = country - self.location = location - self.cityId = cityId - self.position = position - } - - var record: CKRecord { - let record = CKRecord(recordType: WeatherCityRecordKeys.type.rawValue) - record[WeatherCityRecordKeys.name.rawValue] = name - record[WeatherCityRecordKeys.country.rawValue] = country - record[WeatherCityRecordKeys.location.rawValue] = location - record[WeatherCityRecordKeys.cityId.rawValue] = cityId - record[WeatherCityRecordKeys.position.rawValue] = position - return record - } - - init?(from record: CKRecord) { - guard - let name = record[WeatherCityRecordKeys.name.rawValue] as? String, - let country = record[WeatherCityRecordKeys.country.rawValue] as? String, - let location = record[WeatherCityRecordKeys.location.rawValue] as? CLLocation, - let cityId = record[WeatherCityRecordKeys.cityId.rawValue] as? Int, - let position = record[WeatherCityRecordKeys.position.rawValue] as? Int - else { return nil } - self = .init(recordId: record.recordID, - name: name, - country: country, - location: location, - cityId: cityId, - position: position) - } -} diff --git a/Sources/OversizeCloudKitService/Models/WeatherDress.swift b/Sources/OversizeCloudKitService/Models/WeatherDress.swift deleted file mode 100644 index b2b76f5..0000000 --- a/Sources/OversizeCloudKitService/Models/WeatherDress.swift +++ /dev/null @@ -1,88 +0,0 @@ -// -// Copyright © 2022 Alexander Romanov -// WeatherDress.swift -// - -import CloudKit -import Foundation - -public struct WeatherDress: Identifiable { - public let name: String - public let icon: String - public let minTemperature: Double - public let maxTemperature: Double - public let forSunnyWeather: Bool - public let forRainyWeather: Bool - public let forSnowyWeather: Bool - public let isFavorite: Bool - public let position: Int - - // MARK: - Sourcery generated - - public var recordId: CKRecord.ID? - public var id: String { recordId?.recordName ?? UUID().uuidString } - - public enum WeatherDressRecordKeys: String { - case type = "WeatherDress" - case name - case icon - case minTemperature - case maxTemperature - case forSunnyWeather - case forRainyWeather - case forSnowyWeather - case isFavorite - case position - } - - public init(recordId: CKRecord.ID? = nil, name: String, icon: String, minTemperature: Double, maxTemperature: Double, forSunnyWeather: Bool, forRainyWeather: Bool, forSnowyWeather: Bool, isFavorite: Bool, position: Int) { - self.recordId = recordId - self.name = name - self.icon = icon - self.minTemperature = minTemperature - self.maxTemperature = maxTemperature - self.forSunnyWeather = forSunnyWeather - self.forRainyWeather = forRainyWeather - self.forSnowyWeather = forSnowyWeather - self.isFavorite = isFavorite - self.position = position - } - - var record: CKRecord { - let record = CKRecord(recordType: WeatherDressRecordKeys.type.rawValue) - record[WeatherDressRecordKeys.name.rawValue] = name - record[WeatherDressRecordKeys.icon.rawValue] = icon - record[WeatherDressRecordKeys.minTemperature.rawValue] = minTemperature - record[WeatherDressRecordKeys.maxTemperature.rawValue] = maxTemperature - record[WeatherDressRecordKeys.forSunnyWeather.rawValue] = forSunnyWeather - record[WeatherDressRecordKeys.forRainyWeather.rawValue] = forRainyWeather - record[WeatherDressRecordKeys.forSnowyWeather.rawValue] = forSnowyWeather - record[WeatherDressRecordKeys.isFavorite.rawValue] = isFavorite - record[WeatherDressRecordKeys.position.rawValue] = position - return record - } - - init?(from record: CKRecord) { - guard - let name = record[WeatherDressRecordKeys.name.rawValue] as? String, - let icon = record[WeatherDressRecordKeys.icon.rawValue] as? String, - let minTemperature = record[WeatherDressRecordKeys.minTemperature.rawValue] as? Double, - let maxTemperature = record[WeatherDressRecordKeys.maxTemperature.rawValue] as? Double, - let forSunnyWeather = record[WeatherDressRecordKeys.forSunnyWeather.rawValue] as? Bool, - let forRainyWeather = record[WeatherDressRecordKeys.forRainyWeather.rawValue] as? Bool, - let forSnowyWeather = record[WeatherDressRecordKeys.forSnowyWeather.rawValue] as? Bool, - let isFavorite = record[WeatherDressRecordKeys.isFavorite.rawValue] as? Bool, - let position = record[WeatherDressRecordKeys.position.rawValue] as? Int - else { return nil } - self = .init(recordId: record.recordID, - name: name, - icon: icon, - minTemperature: minTemperature, - maxTemperature: maxTemperature, - forSunnyWeather: forSunnyWeather, - forRainyWeather: forRainyWeather, - forSnowyWeather: forSnowyWeather, - isFavorite: isFavorite, - position: position) - } -} diff --git a/Sources/OversizeCloudKitService/Models/WeatherPlace.swift b/Sources/OversizeCloudKitService/Models/WeatherPlace.swift deleted file mode 100644 index 8efa902..0000000 --- a/Sources/OversizeCloudKitService/Models/WeatherPlace.swift +++ /dev/null @@ -1,60 +0,0 @@ -// -// Copyright © 2022 Alexander Romanov -// WeatherPlace.swift -// - -import CloudKit -import CoreLocation -import Foundation -import MapKit - -public struct WeatherPlace: Identifiable, Equatable { - public let name: String - public let icon: String - public let location: CLLocation - public let position: Int - - // MARK: - Sourcery generated - - public var recordId: CKRecord.ID? - public var id: String { recordId?.recordName ?? UUID().uuidString } - - public enum WeatherPlaceRecordKeys: String { - case type = "WeatherPlace" - case name - case icon - case location - case position - } - - public init(recordId: CKRecord.ID? = nil, name: String, icon: String, location: CLLocation, position: Int) { - self.recordId = recordId - self.name = name - self.icon = icon - self.location = location - self.position = position - } - - var record: CKRecord { - let record = CKRecord(recordType: WeatherPlaceRecordKeys.type.rawValue) - record[WeatherPlaceRecordKeys.name.rawValue] = name - record[WeatherPlaceRecordKeys.icon.rawValue] = icon - record[WeatherPlaceRecordKeys.location.rawValue] = location - record[WeatherPlaceRecordKeys.position.rawValue] = position - return record - } - - init?(from record: CKRecord) { - guard - let name = record[WeatherPlaceRecordKeys.name.rawValue] as? String, - let icon = record[WeatherPlaceRecordKeys.icon.rawValue] as? String, - let location = record[WeatherPlaceRecordKeys.location.rawValue] as? CLLocation, - let position = record[WeatherPlaceRecordKeys.position.rawValue] as? Int - else { return nil } - self = .init(recordId: record.recordID, - name: name, - icon: icon, - location: location, - position: position) - } -} diff --git a/Sources/OversizeCloudKitService/ServiceRegistering.swift b/Sources/OversizeCloudKitService/ServiceRegistering.swift deleted file mode 100644 index c73f275..0000000 --- a/Sources/OversizeCloudKitService/ServiceRegistering.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright © 2022 Alexander Romanov -// ServiceRegistering.swift -// - -import Factory -import Foundation - -public extension Container { - var dressWeatherCloudKitService: Factory { - self { DressWeatherCloudKitService() } - } -} diff --git a/Sources/OversizeCloudKitService/Support/CloudKitIdentifier.swift b/Sources/OversizeCloudKitService/Support/CloudKitIdentifier.swift deleted file mode 100644 index 8aadde2..0000000 --- a/Sources/OversizeCloudKitService/Support/CloudKitIdentifier.swift +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright © 2022 Alexander Romanov -// CloudKitIdentifier.swift -// - -import Foundation - -public enum CloudKitIdentifier: String { - case dressWeather = "iCloud.com.romanov.DressWeather" -} diff --git a/Sources/OversizeHealthService/BodyMassService.swift b/Sources/OversizeHealthService/BodyMassService.swift index a7f606b..ca624eb 100644 --- a/Sources/OversizeHealthService/BodyMassService.swift +++ b/Sources/OversizeHealthService/BodyMassService.swift @@ -10,7 +10,7 @@ import Foundation import OversizeCore import OversizeModels -#if !os(tvOS) +#if canImport(HealthKit) @available(iOS 15, macOS 13.0, *) public protocol BodyMassServiceProtocol { func requestAuthorization() async -> Result From 2f3c6a913142f32e2385539070006c8040ca502a Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 10 Nov 2024 21:24:36 +0300 Subject: [PATCH 02/11] Update ci.yml --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efc3e03..d34774b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,11 +37,11 @@ jobs: destination: ${{ matrix.destination }} secrets: inherit - tests: - name: Test - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/test.yml@main - secrets: inherit + tests: + name: Test + needs: build-swiftpm + uses: oversizedev/GithubWorkflows/.github/workflows/test.yml@main + secrets: inherit bump: name: Bump version From 277d22dcdcf48ea4f0f204764d52a2046347d0c9 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 10 Nov 2024 22:03:17 +0300 Subject: [PATCH 03/11] Fix HealthKit service --- Sources/OversizeHealthService/HealthKitService.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/OversizeHealthService/HealthKitService.swift b/Sources/OversizeHealthService/HealthKitService.swift index f40fdfd..3e40ba7 100644 --- a/Sources/OversizeHealthService/HealthKitService.swift +++ b/Sources/OversizeHealthService/HealthKitService.swift @@ -12,7 +12,7 @@ import OversizeModels #if !os(tvOS) @available(iOS 15, macOS 13.0, *) - open class HealthKitService { + open class HealthKitService: @unchecked Sendable { var healthStore: HKHealthStore? init() { From 75c514a5e98f3938201206e49a7d3e232d661301 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 10 Nov 2024 22:03:35 +0300 Subject: [PATCH 04/11] Upd --- .../BloodPressureService.swift | 0 .../{OversizeHealthService => HealthKit}/BodyMassService.swift | 0 .../{OversizeHealthService => HealthKit}/HealthKitService.swift | 0 .../{OversizeHealthService => HealthKit}/ServiceRegistering.swift | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Sources/{OversizeHealthService => HealthKit}/BloodPressureService.swift (100%) rename Sources/{OversizeHealthService => HealthKit}/BodyMassService.swift (100%) rename Sources/{OversizeHealthService => HealthKit}/HealthKitService.swift (100%) rename Sources/{OversizeHealthService => HealthKit}/ServiceRegistering.swift (100%) diff --git a/Sources/OversizeHealthService/BloodPressureService.swift b/Sources/HealthKit/BloodPressureService.swift similarity index 100% rename from Sources/OversizeHealthService/BloodPressureService.swift rename to Sources/HealthKit/BloodPressureService.swift diff --git a/Sources/OversizeHealthService/BodyMassService.swift b/Sources/HealthKit/BodyMassService.swift similarity index 100% rename from Sources/OversizeHealthService/BodyMassService.swift rename to Sources/HealthKit/BodyMassService.swift diff --git a/Sources/OversizeHealthService/HealthKitService.swift b/Sources/HealthKit/HealthKitService.swift similarity index 100% rename from Sources/OversizeHealthService/HealthKitService.swift rename to Sources/HealthKit/HealthKitService.swift diff --git a/Sources/OversizeHealthService/ServiceRegistering.swift b/Sources/HealthKit/ServiceRegistering.swift similarity index 100% rename from Sources/OversizeHealthService/ServiceRegistering.swift rename to Sources/HealthKit/ServiceRegistering.swift From 5fcea82336b79b396a5445883fcab15053b6c6fa Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 10 Nov 2024 22:41:47 +0300 Subject: [PATCH 05/11] Fix healthKit --- .../BloodPressureService.swift | 4 +- .../BodyMassService.swift | 0 .../HealthKitService.swift | 61 +++++++++---------- .../ServiceRegistering.swift | 0 4 files changed, 30 insertions(+), 35 deletions(-) rename Sources/{HealthKit => OversizeHealthService}/BloodPressureService.swift (99%) rename Sources/{HealthKit => OversizeHealthService}/BodyMassService.swift (100%) rename Sources/{HealthKit => OversizeHealthService}/HealthKitService.swift (78%) rename Sources/{HealthKit => OversizeHealthService}/ServiceRegistering.swift (100%) diff --git a/Sources/HealthKit/BloodPressureService.swift b/Sources/OversizeHealthService/BloodPressureService.swift similarity index 99% rename from Sources/HealthKit/BloodPressureService.swift rename to Sources/OversizeHealthService/BloodPressureService.swift index 228bb02..7e94ecc 100644 --- a/Sources/HealthKit/BloodPressureService.swift +++ b/Sources/OversizeHealthService/BloodPressureService.swift @@ -10,9 +10,9 @@ import Foundation import OversizeCore import OversizeModels -#if !os(tvOS) +#if canImport(HealthKit) @available(iOS 15, macOS 13.0, *) - public class BloodPressureService: HealthKitService { + public class BloodPressureService: HealthKitService, @unchecked Sendable { private let bloodPressureType = HKQuantityType.correlationType(forIdentifier: HKCorrelationTypeIdentifier.bloodPressure) private let bloodPressureSystolicType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureSystolic) private let bloodPressureDiastolicType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureDiastolic) diff --git a/Sources/HealthKit/BodyMassService.swift b/Sources/OversizeHealthService/BodyMassService.swift similarity index 100% rename from Sources/HealthKit/BodyMassService.swift rename to Sources/OversizeHealthService/BodyMassService.swift diff --git a/Sources/HealthKit/HealthKitService.swift b/Sources/OversizeHealthService/HealthKitService.swift similarity index 78% rename from Sources/HealthKit/HealthKitService.swift rename to Sources/OversizeHealthService/HealthKitService.swift index 3e40ba7..62009b0 100644 --- a/Sources/HealthKit/HealthKitService.swift +++ b/Sources/OversizeHealthService/HealthKitService.swift @@ -10,7 +10,7 @@ import Foundation import OversizeCore import OversizeModels -#if !os(tvOS) +#if canImport(HealthKit) @available(iOS 15, macOS 13.0, *) open class HealthKitService: @unchecked Sendable { var healthStore: HKHealthStore? @@ -28,14 +28,11 @@ import OversizeModels guard let healthStore else { return .failure(AppError.healthKit(type: .savingItem)) } - return await withCheckedContinuation { continuation in - healthStore.save(quantitySample) { _, error in - if error != nil { - continuation.resume(returning: .failure(AppError.healthKit(type: .savingItem))) - } else { - continuation.resume(returning: .success(quantitySample)) - } - } + do { + try await healthStore.save(quantitySample) + return .success(quantitySample) + } catch { + return .failure(AppError.healthKit(type: .savingItem)) } } @@ -43,14 +40,11 @@ import OversizeModels guard let healthStore else { return .failure(AppError.healthKit(type: .savingItem)) } - return await withCheckedContinuation { continuation in - healthStore.save(correlation) { _, error in - if error != nil { - continuation.resume(returning: .failure(AppError.healthKit(type: .savingItem))) - } else { - continuation.resume(returning: .success(correlation)) - } - } + do { + try await healthStore.save(correlation) + return .success(correlation) + } catch { + return .failure(AppError.healthKit(type: .savingItem)) } } @@ -161,26 +155,27 @@ import OversizeModels } func deleteObject(_ object: HKObject) async -> Result { - await withCheckedContinuation { continuation in - self.healthStore?.delete(object, withCompletion: { _, error in - if error != nil { - continuation.resume(returning: .failure(AppError.healthKit(type: .deleteItem))) - } else { - continuation.resume(returning: .success(object)) - } - }) + guard let healthStore else { + return .failure(AppError.healthKit(type: .deleteItem)) + } + do { + try await healthStore.delete(object) + return .success(object) + } catch { + return .failure(AppError.healthKit(type: .deleteItem)) } } + func deleteObjects(_ objects: [HKObject]) async -> Result<[HKObject], AppError> { - await withCheckedContinuation { continuation in - self.healthStore?.delete(objects, withCompletion: { _, error in - if error != nil { - continuation.resume(returning: .failure(AppError.healthKit(type: .deleteItem))) - } else { - continuation.resume(returning: .success(objects)) - } - }) + guard let healthStore else { + return .failure(AppError.healthKit(type: .deleteItem)) + } + do { + try await healthStore.delete(objects) + return .success(objects) + } catch { + return .failure(AppError.healthKit(type: .deleteItem)) } } } diff --git a/Sources/HealthKit/ServiceRegistering.swift b/Sources/OversizeHealthService/ServiceRegistering.swift similarity index 100% rename from Sources/HealthKit/ServiceRegistering.swift rename to Sources/OversizeHealthService/ServiceRegistering.swift From 6dc64c223f550f6b64eb5a195195bad6e58d41c4 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 10 Nov 2024 22:46:15 +0300 Subject: [PATCH 06/11] Fix watchOS --- Sources/OversizeHealthService/BloodPressureService.swift | 2 +- Sources/OversizeHealthService/BodyMassService.swift | 2 +- Sources/OversizeHealthService/HealthKitService.swift | 2 +- Sources/OversizeHealthService/ServiceRegistering.swift | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/OversizeHealthService/BloodPressureService.swift b/Sources/OversizeHealthService/BloodPressureService.swift index 7e94ecc..9fdddac 100644 --- a/Sources/OversizeHealthService/BloodPressureService.swift +++ b/Sources/OversizeHealthService/BloodPressureService.swift @@ -10,7 +10,7 @@ import Foundation import OversizeCore import OversizeModels -#if canImport(HealthKit) +#if os(iOS) || os(macOS) @available(iOS 15, macOS 13.0, *) public class BloodPressureService: HealthKitService, @unchecked Sendable { private let bloodPressureType = HKQuantityType.correlationType(forIdentifier: HKCorrelationTypeIdentifier.bloodPressure) diff --git a/Sources/OversizeHealthService/BodyMassService.swift b/Sources/OversizeHealthService/BodyMassService.swift index ca624eb..17ea216 100644 --- a/Sources/OversizeHealthService/BodyMassService.swift +++ b/Sources/OversizeHealthService/BodyMassService.swift @@ -10,7 +10,7 @@ import Foundation import OversizeCore import OversizeModels -#if canImport(HealthKit) +#if os(iOS) || os(macOS) @available(iOS 15, macOS 13.0, *) public protocol BodyMassServiceProtocol { func requestAuthorization() async -> Result diff --git a/Sources/OversizeHealthService/HealthKitService.swift b/Sources/OversizeHealthService/HealthKitService.swift index 62009b0..57147d5 100644 --- a/Sources/OversizeHealthService/HealthKitService.swift +++ b/Sources/OversizeHealthService/HealthKitService.swift @@ -10,7 +10,7 @@ import Foundation import OversizeCore import OversizeModels -#if canImport(HealthKit) +#if os(iOS) || os(macOS) @available(iOS 15, macOS 13.0, *) open class HealthKitService: @unchecked Sendable { var healthStore: HKHealthStore? diff --git a/Sources/OversizeHealthService/ServiceRegistering.swift b/Sources/OversizeHealthService/ServiceRegistering.swift index 3efe95d..9839c39 100644 --- a/Sources/OversizeHealthService/ServiceRegistering.swift +++ b/Sources/OversizeHealthService/ServiceRegistering.swift @@ -6,7 +6,7 @@ import Factory import Foundation -#if !os(tvOS) +#if os(iOS) || os(macOS) public extension Container { @available(iOS 15, macOS 13.0, *) var bodyMassService: Factory { From d9e3d95b21615afa3e6edfca556fbfa64cf95bfd Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 10 Nov 2024 23:53:22 +0300 Subject: [PATCH 07/11] Fix remoteDependencies --- Package.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 65c279c..a0fe896 100644 --- a/Package.swift +++ b/Package.swift @@ -18,10 +18,10 @@ let developmentDependencies: [PackageDescription.Package.Dependency] = [ .package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")), ] -var dependencies: [PackageDescription.Package.Dependency] = developmentDependencies +var dependencies: [PackageDescription.Package.Dependency] = remoteDependencies -if ProcessInfo.processInfo.environment["BUILD_MODE"] == "PRODUCTION" { - dependencies = remoteDependencies +if ProcessInfo.processInfo.environment["BUILD_MODE"] == "DEV" { + dependencies = developmentDependencies } let package = Package( @@ -43,7 +43,7 @@ let package = Package( .library(name: "OversizeNotificationService", targets: ["OversizeNotificationService"]), .library(name: "OversizeFileManagerService", targets: ["OversizeFileManagerService"]), ], - dependencies: dependencies, + dependencies: remoteDependencies, targets: [ .target( name: "OversizeServices", From 1d92587607ba6e018dafb39e6f688a9e877f6ed1 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 10 Nov 2024 23:59:04 +0300 Subject: [PATCH 08/11] Delete HealthServices build from CI --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d34774b..3e61d93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,6 @@ jobs: matrix: packages: - OversizeServices - - OversizeHealthService - OversizeStoreService - OversizeLocationService - OversizeCalendarService From 1a1fcd6ced54c8770d32369333f83fe4b8586a16 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Mon, 11 Nov 2024 00:08:39 +0300 Subject: [PATCH 09/11] Fix auth service --- Package.swift | 2 +- .../Services/SecurityService/BiometricService.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index a0fe896..f41a3a0 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let developmentDependencies: [PackageDescription.Package.Dependency] = [ .package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")), ] -var dependencies: [PackageDescription.Package.Dependency] = remoteDependencies +var dependencies: [PackageDescription.Package.Dependency] = developmentDependencies if ProcessInfo.processInfo.environment["BUILD_MODE"] == "DEV" { dependencies = developmentDependencies diff --git a/Sources/OversizeServices/Services/SecurityService/BiometricService.swift b/Sources/OversizeServices/Services/SecurityService/BiometricService.swift index 7094011..a2d731a 100644 --- a/Sources/OversizeServices/Services/SecurityService/BiometricService.swift +++ b/Sources/OversizeServices/Services/SecurityService/BiometricService.swift @@ -26,7 +26,7 @@ public class BiometricService: @unchecked Sendable { public init() {} public var biometricType: BiometricType { - #if canImport(LocalAuthentication) + #if os(iOS) || os(macOS) let authContext: LAContext = .init() _ = authContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) switch authContext.biometryType { @@ -49,7 +49,7 @@ public class BiometricService: @unchecked Sendable { extension BiometricService: BiometricServiceProtocol { public func checkIfBioMetricAvailable() -> Bool { - #if canImport(LocalAuthentication) + #if os(iOS) || os(macOS) var error: NSError? let laContext: LAContext = .init() @@ -65,7 +65,7 @@ extension BiometricService: BiometricServiceProtocol { } public func authenticating(reason: String) async -> Bool { - #if canImport(LocalAuthentication) + #if os(iOS) || os(macOS) do { let laContext: LAContext = .init() if checkIfBioMetricAvailable() { From 336dcff95ca14017cc598a49d69af0e3459facfb Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Mon, 11 Nov 2024 00:09:30 +0300 Subject: [PATCH 10/11] Fix package --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index f41a3a0..a0fe896 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let developmentDependencies: [PackageDescription.Package.Dependency] = [ .package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")), ] -var dependencies: [PackageDescription.Package.Dependency] = developmentDependencies +var dependencies: [PackageDescription.Package.Dependency] = remoteDependencies if ProcessInfo.processInfo.environment["BUILD_MODE"] == "DEV" { dependencies = developmentDependencies From 30e115ac45f52045b5e21b68acd5696cc6646d26 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Mon, 11 Nov 2024 00:19:45 +0300 Subject: [PATCH 11/11] Disable tests --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e61d93..fdd76bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,15 +36,15 @@ jobs: destination: ${{ matrix.destination }} secrets: inherit - tests: - name: Test - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/test.yml@main - secrets: inherit +# tests: +# name: Test +# needs: build-swiftpm +# uses: oversizedev/GithubWorkflows/.github/workflows/test.yml@main +# secrets: inherit bump: name: Bump version - needs: tests + needs: build-swiftpm if: github.ref == 'refs/heads/main' uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main secrets: inherit