Skip to content

Commit 42db2eb

Browse files
authored
Merge pull request #285 from kean/task/url-session-protocol
Add URLSessionProxy
2 parents 97a4491 + 2d3043a commit 42db2eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1029
-587
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
- uses: actions/checkout@v2
9393
- name: Build Demo
9494
run: |
95+
cd Demo
9596
set -o pipefail
9697
xcodebuild build -scheme "Pulse Demo iOS" -destination "OS=17.4,name=iPhone 15 Pro" | xcpretty
9798
build-demo-tvos:
@@ -103,6 +104,7 @@ jobs:
103104
- uses: actions/checkout@v2
104105
- name: Build Demo
105106
run: |
107+
cd Demo
106108
set -o pipefail
107109
xcodebuild build -scheme "Pulse Demo tvOS" -destination "OS=17.4,name=Apple TV" | xcpretty
108110
build-integration-examples-ios:
@@ -114,5 +116,6 @@ jobs:
114116
- uses: actions/checkout@v2
115117
- name: Build Integration Tests
116118
run: |
119+
cd Demo
117120
set -o pipefail
118121
xcodebuild build -scheme "Pulse Integration Examples iOS" -destination "OS=17.4,name=iPhone 15 Pro" | xcpretty

Demo/Pulse.xcodeproj/project.pbxproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
0C9F04F92884F34A0035239F /* Pulse_Demo_macOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C9F04F82884F34A0035239F /* Pulse_Demo_macOSApp.swift */; };
4141
0C9F04FD2884F34A0035239F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0C9F04FC2884F34A0035239F /* Assets.xcassets */; };
4242
0C9F05002884F34A0035239F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0C9F04FF2884F34A0035239F /* Preview Assets.xcassets */; };
43+
0CA245732C85E87A00B432DA /* PulseProxy in Frameworks */ = {isa = PBXBuildFile; productRef = 0CA245722C85E87A00B432DA /* PulseProxy */; };
4344
0CDACDE529EC6607007C15CD /* repos.json in Resources */ = {isa = PBXBuildFile; fileRef = 0CDACDE129EC6607007C15CD /* repos.json */; };
4445
0CDACDE629EC6607007C15CD /* repos.json in Resources */ = {isa = PBXBuildFile; fileRef = 0CDACDE129EC6607007C15CD /* repos.json */; };
4546
/* End PBXBuildFile section */
@@ -152,6 +153,7 @@
152153
isa = PBXFrameworksBuildPhase;
153154
buildActionMask = 2147483647;
154155
files = (
156+
0CA245732C85E87A00B432DA /* PulseProxy in Frameworks */,
155157
0C8FCB522C45F05400C4FD84 /* PulseUI in Frameworks */,
156158
0C8FCB502C45F05400C4FD84 /* Pulse in Frameworks */,
157159
);
@@ -382,6 +384,7 @@
382384
packageProductDependencies = (
383385
0C8FCB4F2C45F05400C4FD84 /* Pulse */,
384386
0C8FCB512C45F05400C4FD84 /* PulseUI */,
387+
0CA245722C85E87A00B432DA /* PulseProxy */,
385388
);
386389
productName = "Pulse Demo iOS";
387390
productReference = 0C70EA732A3F611B000B1071 /* Pulse Demo iOS.app */;
@@ -791,7 +794,7 @@
791794
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
792795
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
793796
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
794-
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
797+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
795798
LD_RUNPATH_SEARCH_PATHS = (
796799
"$(inherited)",
797800
"@executable_path/Frameworks",
@@ -835,7 +838,7 @@
835838
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
836839
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
837840
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
838-
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
841+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
839842
LD_RUNPATH_SEARCH_PATHS = (
840843
"$(inherited)",
841844
"@executable_path/Frameworks",
@@ -1033,6 +1036,10 @@
10331036
isa = XCSwiftPackageProductDependency;
10341037
productName = PulseUI;
10351038
};
1039+
0CA245722C85E87A00B432DA /* PulseProxy */ = {
1040+
isa = XCSwiftPackageProductDependency;
1041+
productName = PulseProxy;
1042+
};
10361043
/* End XCSwiftPackageProductDependency section */
10371044
};
10381045
rootObject = 0C57AD45245F0EFB005B3400 /* Project object */;

Demo/Sources/iOS/Pulse_Demo_iOSApp.swift

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import SwiftUI
66
import Pulse
77
import PulseUI
8-
import OSLog
8+
import PulseProxy
99

1010
@main
1111
struct PulseDemo_iOS: App {
@@ -21,27 +21,52 @@ struct PulseDemo_iOS: App {
2121
}
2222

2323
private final class AppViewModel: ObservableObject {
24-
let log = OSLog(subsystem: "app", category: "AppViewModel")
25-
2624
init() {
27-
// URLSessionProxyDelegate.enableAutomaticRegistration()
28-
// URLSessionProxy.enable()
25+
// NetworkLogger.enableProxy()
26+
2927
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
3028
sendRequest()
3129
}
32-
// DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(6)) {
33-
// sendRequest()
34-
// }
35-
// DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(9)) {
36-
// sendRequest()
37-
// }
3830
}
3931
}
4032

33+
4134
private func sendRequest() {
42-
let session = URLSession(configuration: .default, delegate: DemoSessionDelegate(), delegateQueue: nil)
43-
let task = session.dataTask(with: URLRequest(url: URL(string: "https://github.com/kean/Nuke/archive/refs/tags/11.0.0.zip")!))
35+
testSwiftConcurrency()
36+
37+
// let task = session.dataTask(with: URLRequest(url: URL(string: "https://github.com/kean/Nuke/archive/refs/tags/11.0.0.zip")!))
38+
// task.resume()
39+
}
40+
41+
private func testClosures() {
42+
let session = URLSessionProxy(configuration: .default)
43+
let task = session.dataTask(with: URLRequest(url: URL(string: "https://api.github.com/repos/octocat/Spoon-Knife/issues?per_page=2")!)) { data, _, _ in
44+
NSLog("didFinish: \(data?.count ?? 0)")
45+
}
4446
task.resume()
4547
}
4648

47-
private final class DemoSessionDelegate: NSObject, URLSessionDelegate {}
49+
private func testSwiftConcurrency() {
50+
Task {
51+
let demoDelegate = DemoSessionDelegate()
52+
let session = URLSessionProxy(configuration: .default, delegate: demoDelegate, delegateQueue: nil)
53+
// let session = URLSession(configuration: .default)
54+
55+
let (data, _) = try await session.data(from: URL(string: "https://api.github.com/repos/octocat/Spoon-Knife/issues?per_page=2")!) //, delegate: demoDelegate)
56+
NSLog("didFinish: \(data.count)")
57+
}
58+
}
59+
60+
private final class DemoSessionDelegate: NSObject, URLSessionDelegate, URLSessionDataDelegate {
61+
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
62+
NSLog("[\(dataTask.taskIdentifier)] didReceive: \(data.count)")
63+
}
64+
65+
func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
66+
NSLog("[\(task.taskIdentifier)] didFinishCollectingMetrics: \(metrics)")
67+
}
68+
69+
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: (any Error)?) {
70+
NSLog("[\(task.taskIdentifier)] didCompleteWithError: \(String(describing: error))")
71+
}
72+
}

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
import PackageDescription
33

44
let package = Package(
55
name: "Pulse",
66
platforms: [
7-
.iOS(.v14),
7+
.iOS(.v15),
88
.tvOS(.v15),
99
.macOS(.v12),
1010
.watchOS(.v8)
1111
],
1212
products: [
1313
.library(name: "Pulse", targets: ["Pulse"]),
14+
.library(name: "PulseProxy", targets: ["PulseProxy"]),
1415
.library(name: "PulseUI", targets: ["PulseUI"])
1516
],
1617
targets: [
1718
.target(name: "Pulse"),
19+
.target(name: "PulseProxy", dependencies: ["Pulse"]),
1820
.target(name: "PulseUI", dependencies: ["Pulse"]),
1921
],
2022
swiftLanguageVersions: [

Sources/Pulse/Helpers/PulseDocument.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ final class PulseDocument {
2727
}
2828
}
2929

30+
/// - warning: Model has to be loaded only once.
3031
static let model: NSManagedObjectModel = {
3132
let model = NSManagedObjectModel()
3233
let blob = NSEntityDescription(class: PulseBlobEntity.self)

Sources/Pulse/Helpers/Regex.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import Foundation
66

7-
final class Regex {
7+
final class Regex: @unchecked Sendable {
88
private let regex: NSRegularExpression
99

1010
struct Options: OptionSet {

Sources/Pulse/Helpers/Version.swift

Lines changed: 0 additions & 68 deletions
This file was deleted.

Sources/Pulse/LoggerStore/LoggerStore+Configuration.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension LoggerStore {
5050

5151
/// The store configuration.
5252
public struct Configuration: @unchecked Sendable {
53-
/// Size limit in bytes. `128 MB` by default.
53+
/// Size limit in bytes. `256 MB` by default.
5454
public var sizeLimit: Int64
5555

5656
var blobSizeLimit: Int64 {
@@ -75,8 +75,8 @@ extension LoggerStore {
7575
public var isStoringOnlyImageThumbnails = true
7676

7777
/// Limit the maximum response size stored by the logger. The default
78-
/// value is `5 Mb`. The same limit applies to requests.
79-
public var responseBodySizeLimit: Int = 5 * 1048576
78+
/// value is `8 MB`. The same limit applies to requests.
79+
public var responseBodySizeLimit: Int = 8 * 1048576
8080

8181
var inlineLimit = 16384 // 16 KB
8282

@@ -87,9 +87,6 @@ extension LoggerStore {
8787
/// ``LoggerStore/Options-swift.struct/sweep`` option. The default store supports sweeps.
8888
public var maxAge: TimeInterval = 14 * 86400
8989

90-
/// For testing purposes.
91-
var makeCurrentDate: () -> Date = { Date() }
92-
9390
/// Gets called when the store receives an event. You can use it to
9491
/// modify the event before it is stored in order, for example, filter
9592
/// out some sensitive information. If you return `nil`, the event
@@ -102,8 +99,8 @@ extension LoggerStore {
10299
///
103100
/// - parameters:
104101
/// - sizeLimit: The approximate limit of the logger store, including
105-
/// both the database and the blobs. `128 Mb` by default.
106-
public init(sizeLimit: Int64 = 128 * 1_000_000) {
102+
/// both the database and the blobs. `256 Mb` by default.
103+
public init(sizeLimit: Int64 = 256 * 1_000_000) {
107104
self.sizeLimit = sizeLimit
108105
}
109106
}

Sources/Pulse/LoggerStore/LoggerStore+Info.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ private func getAppIcon() -> Data? {
104104
#if os(iOS) || os(tvOS) || os(visionOS)
105105
import UIKit
106106

107+
@MainActor
107108
func getDeviceId() -> UUID? {
108109
UIDevice.current.identifierForVendor
109110
}
110111

111112
extension LoggerStore.Info.DeviceInfo {
112-
static func make() -> LoggerStore.Info.DeviceInfo {
113+
@MainActor
114+
static func make() -> LoggerStore.Info.DeviceInfo {
113115
let device = UIDevice.current
114116
return LoggerStore.Info.DeviceInfo(
115117
name: device.name,
@@ -123,12 +125,14 @@ extension LoggerStore.Info.DeviceInfo {
123125
#elseif os(watchOS)
124126
import WatchKit
125127

128+
@MainActor
126129
func getDeviceId() -> UUID? {
127130
WKInterfaceDevice.current().identifierForVendor
128131
}
129132

130133
extension LoggerStore.Info.DeviceInfo {
131-
static func make() -> LoggerStore.Info.DeviceInfo {
134+
@MainActor
135+
static func make() -> LoggerStore.Info.DeviceInfo {
132136
let device = WKInterfaceDevice.current()
133137
return LoggerStore.Info.DeviceInfo(
134138
name: device.name,
@@ -143,7 +147,8 @@ extension LoggerStore.Info.DeviceInfo {
143147
import AppKit
144148

145149
extension LoggerStore.Info.DeviceInfo {
146-
static func make() -> LoggerStore.Info.DeviceInfo {
150+
@MainActor
151+
static func make() -> LoggerStore.Info.DeviceInfo {
147152
return LoggerStore.Info.DeviceInfo(
148153
name: Host.current().name ?? "unknown",
149154
model: "unknown",
@@ -154,6 +159,7 @@ extension LoggerStore.Info.DeviceInfo {
154159
}
155160
}
156161

162+
@MainActor
157163
func getDeviceId() -> UUID? {
158164
return nil
159165
}

Sources/Pulse/LoggerStore/LoggerStore+Model.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import CoreData
66

77
extension LoggerStore {
88
/// Returns Core Data model used by the store.
9+
///
10+
/// - warning: Model has to be loaded only once.
911
static let model: NSManagedObjectModel = {
1012
typealias Entity = NSEntityDescription
1113
typealias Attribute = NSAttributeDescription

0 commit comments

Comments
 (0)