Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Drop iOS 13 + CocoaLumberjack #147

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
"version" : "5.10.2"
}
},
{
"identity" : "cocoalumberjack",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CocoaLumberjack/CocoaLumberjack",
"state" : {
"revision" : "4b8714a7fb84d42393314ce897127b3939885ec3",
"version" : "3.8.5"
}
},
{
"identity" : "ios-dependency-injection",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -72,15 +63,6 @@
"version" : "8.42.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91",
"version" : "1.6.2"
}
},
{
"identity" : "zipfoundation",
"kind" : "remoteSourceControl",
Expand Down
7 changes: 2 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ if resolveDependenciesForTesting {
let package = Package(
name: "InfomaniakCore",
platforms: [
.iOS(.v13),
.macOS(.v10_15)
.iOS(.v15),
.macOS(.v11)
],
products: [
.library(
Expand All @@ -40,7 +40,6 @@ let package = Package(
.package(url: "https://github.com/Alamofire/Alamofire", .upToNextMajor(from: "5.8.0")),
.package(url: "https://github.com/getsentry/sentry-cocoa", .upToNextMajor(from: "8.18.0")),
.package(url: "https://github.com/realm/realm-swift", .upToNextMajor(from: "10.45.0")),
.package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack", .upToNextMajor(from: "3.8.0")),
.package(url: "https://github.com/weichsel/ZIPFoundation.git", .upToNextMajor(from: "0.9.0")),
.package(url: "https://github.com/MarcoEidinger/OSInfo.git", .upToNextMajor(from: "1.0.0"))
],
Expand All @@ -52,8 +51,6 @@ let package = Package(
.product(name: "InfomaniakDI", package: "ios-dependency-injection"),
.product(name: "InfomaniakLogin", package: "ios-login"),
.product(name: "Sentry-Dynamic", package: "sentry-cocoa"),
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
.product(name: "OSInfo", package: "OSInfo")
]
),
Expand Down
20 changes: 11 additions & 9 deletions Sources/InfomaniakCore/Account/KeychainHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CocoaLumberjackSwift
import Foundation
import InfomaniakLogin
import OSLog
import Sentry

public class KeychainHelper {
private let logger = Logger(category: "KeychainHelper")

let accessGroup: String
let tag = "ch.infomaniak.token".data(using: .utf8)!
let keychainQueue = DispatchQueue(label: "com.infomaniak.keychain")
Expand Down Expand Up @@ -63,7 +65,7 @@ public class KeychainHelper {
}
return false
} else {
DDLogInfo("[Keychain] Accessible error ? \(resultCode == noErr), \(resultCode)")
logger.error("[Keychain] Accessible error ? \(resultCode == noErr), \(resultCode)")
return false
}
}
Expand All @@ -78,7 +80,7 @@ public class KeychainHelper {
kSecValueData as String: lockedValue
]
let resultCode = SecItemAdd(queryAdd as CFDictionary, nil)
DDLogInfo(
logger.info(
"[Keychain] Successfully init KeychainHelper ? \(resultCode == noErr || resultCode == errSecDuplicateItem), \(resultCode)"
)
}
Expand All @@ -91,7 +93,7 @@ public class KeychainHelper {
kSecAttrAccount as String: "\(userId)"
]
let resultCode = SecItemDelete(queryDelete as CFDictionary)
DDLogInfo("Successfully deleted token ? \(resultCode == noErr)")
logger.info("Successfully deleted token ? \(resultCode == noErr)")
}
}

Expand All @@ -102,7 +104,7 @@ public class KeychainHelper {
kSecAttrService as String: tag
]
let resultCode = SecItemDelete(queryDelete as CFDictionary)
DDLogInfo("Successfully deleted all tokens ? \(resultCode == noErr)")
logger.info("Successfully deleted all tokens ? \(resultCode == noErr)")
}
}

Expand Down Expand Up @@ -132,12 +134,12 @@ public class KeychainHelper {
let newTokenExpirationDate = token.expirationDate,
savedTokenExpirationDate <= newTokenExpirationDate {
resultCode = SecItemUpdate(queryUpdate as CFDictionary, attributes as CFDictionary)
DDLogInfo("Successfully updated token ? \(resultCode == noErr)")
logger.info("Successfully updated token ? \(resultCode == noErr)")
SentrySDK.addBreadcrumb(token.generateBreadcrumb(level: .info, message: "Successfully updated token"))
} else if savedToken.expirationDate == nil || token.expirationDate == nil {
// Or if one of them is now an infinite refresh token
resultCode = SecItemUpdate(queryUpdate as CFDictionary, attributes as CFDictionary)
DDLogInfo("Successfully updated unlimited token ? \(resultCode == noErr)")
logger.info("Successfully updated unlimited token ? \(resultCode == noErr)")
SentrySDK.addBreadcrumb(token.generateBreadcrumb(
level: .info,
message: "Successfully updated unlimited token"
Expand All @@ -156,7 +158,7 @@ public class KeychainHelper {
kSecValueData as String: tokenData
]
resultCode = SecItemAdd(queryAdd as CFDictionary, nil)
DDLogInfo("Successfully saved token ? \(resultCode == noErr)")
logger.info("Successfully saved token ? \(resultCode == noErr)")
SentrySDK.addBreadcrumb(token.generateBreadcrumb(level: .info, message: "Successfully saved token"))
}
}
Expand Down Expand Up @@ -215,7 +217,7 @@ public class KeychainHelper {
let resultCode = withUnsafeMutablePointer(to: &result) {
SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
}
DDLogInfo("Successfully loaded tokens ? \(resultCode == noErr)")
logger.info("Successfully loaded tokens ? \(resultCode == noErr)")

guard resultCode == noErr else {
let crumb = Breadcrumb(level: .error, category: "Token")
Expand Down
8 changes: 5 additions & 3 deletions Sources/InfomaniakCore/Account/UserProfileStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CocoaLumberjackSwift
import Foundation
import InfomaniakDI
import OSLog

public actor UserProfileStore {
private let logger = Logger(category: "UserProfileStore")

public typealias UserId = Int

let preferencesURL: URL
Expand Down Expand Up @@ -65,7 +67,7 @@ public actor UserProfileStore {
try FileManager.default.createDirectory(atPath: preferencesURL.path, withIntermediateDirectories: true)
try usersData.write(to: storeFileURL)
} catch {
DDLogError("[UserProfileStore] Error saving accounts :\(error)")
logger.error("[UserProfileStore] Error saving accounts :\(error)")
}
}

Expand All @@ -84,7 +86,7 @@ public actor UserProfileStore {

profiles = savedUsers
} catch {
DDLogError("[UserProfileStore] Error loading accounts :\(error)")
logger.error("[UserProfileStore] Error loading accounts :\(error)")
}
}
}
14 changes: 8 additions & 6 deletions Sources/InfomaniakCore/Asynchronous/BackgroundExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CocoaLumberjackSwift
import Foundation
import OSLog

public enum BackgroundExecutor {
private static let logger = Logger(category: "BackgroundExecutor")

public typealias TaskCompletion = () -> Void
public static func executeWithBackgroundTask(_ block: @escaping (@escaping TaskCompletion) -> Void,
onExpired: @escaping () -> Void) {
Expand All @@ -28,24 +30,24 @@ public enum BackgroundExecutor {
let group = TolerantDispatchGroup()
group.enter()
#if os(macOS)
DDLogDebug("Starting task \(taskName) (No expiration handler as we are running on macOS)")
logger.debug("Starting task \(taskName) (No expiration handler as we are running on macOS)")
processInfos.performActivity(options: .suddenTerminationDisabled, reason: taskName) {
block {
DDLogDebug("Ending task \(taskName)")
logger.debug("Ending task \(taskName)")
group.leave()
}
group.wait()
}
#else
DDLogDebug("Starting task \(taskName)")
logger.debug("Starting task \(taskName)")
processInfos.performExpiringActivity(withReason: taskName) { expired in
if expired {
onExpired()
DDLogDebug("Expired task \(taskName)")
logger.debug("Expired task \(taskName)")
group.leave()
} else {
block {
DDLogDebug("Ending task \(taskName)")
logger.debug("Ending task \(taskName)")
group.leave()
}
group.wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CocoaLumberjackSwift
import Foundation
import OSLog

public final class TolerantDispatchGroup {
private let logger = Logger(category: "TolerantDispatchGroup")

let syncQueue: DispatchQueue
private let dispatchGroup = DispatchGroup()
private var callBalancer = 0
Expand All @@ -40,7 +42,7 @@ public final class TolerantDispatchGroup {
public func leave() {
syncQueue.sync {
guard callBalancer > 0 else {
DDLogWarn("TolerantDispatchGroup: Unbalanced call to leave()")
logger.warning("TolerantDispatchGroup: Unbalanced call to leave()")
return
}

Expand Down
26 changes: 26 additions & 0 deletions Sources/InfomaniakCore/CoreLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Infomaniak Core - iOS
Copyright (C) 2025 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import Foundation
import OSLog

extension Logger {
init(category: String) {
self.init(subsystem: "com.infomaniak.core", category: category)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CocoaLumberjackSwift
import Foundation
import OSLog

/// Something that can provide a set of common URLs within the app group
///
Expand Down Expand Up @@ -47,6 +47,8 @@ public protocol AppGroupPathProvidable: AnyObject {
}

public final class AppGroupPathProvider: AppGroupPathProvidable {
private let logger = Logger(category: "AppGroupPathProvider")

private let fileManager = FileManager.default

private let realmRootPath: String
Expand Down Expand Up @@ -116,7 +118,7 @@ public final class AppGroupPathProvider: AppGroupPathProvidable {
ofItemAtPath: groupDirectoryURL.path
)
} catch {
DDLogError("[AppGroupPathProvider] failed to protect mandatory path :\(error)")
logger.error("[AppGroupPathProvider] failed to protect mandatory path :\(error)")
return nil
}

Expand Down